Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Create use-rewards.ts

Kiran K3bcb8628bb57
diff --git a/apps/web/lib/swr/use-rewards.ts b/apps/web/lib/swr/use-rewards.ts
new file mode 100644
index 0000000000..02fbeb39db
--- /dev/null
+++ b/apps/web/lib/swr/use-rewards.ts
@@ -0,0 +1,25 @@
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+import { RewardProps } from "../types";
+import useWorkspace from "./use-workspace";
+
+export default function useRewards() {
+ const { id: workspaceId, defaultProgramId } = useWorkspace();
+
+ const { data: rewards, error } = useSWR<RewardProps[]>(
+ workspaceId &&
+ defaultProgramId &&
+ `/api/programs/${defaultProgramId}/rewards?workspaceId=${workspaceId}`,
+ fetcher,
+ {
+ dedupingInterval: 60000,
+ keepPreviousData: true,
+ },
+ );
+
+ return {
+ rewards,
+ loading: !rewards && !error,
+ error,
+ };
+}