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.

Pass SWR options as the second argument to useRewards.

Kiran K4c405665320b
diff --git a/apps/web/lib/swr/use-rewards.ts b/apps/web/lib/swr/use-rewards.ts
index ae0227b237..ac3ba04176 100644
--- a/apps/web/lib/swr/use-rewards.ts
+++ b/apps/web/lib/swr/use-rewards.ts
@@ -10,12 +10,11 @@ export type RewardListItem = RewardProps & {
partnersCount?: number;
};
-export function useRewards({
- groupId,
- swrOpts,
-}: z.infer<typeof getRewardsQuerySchema> & {
- swrOpts?: SWRConfiguration;
-} = {}) {
+export function useRewards(
+ opts: z.infer<typeof getRewardsQuerySchema> = {},
+ swrOpts: SWRConfiguration = {},
+) {
+ const { groupId } = opts;
const { id: workspaceId, defaultProgramId } = useWorkspace();
const searchParams = new URLSearchParams({
@@ -23,12 +22,16 @@ export function useRewards({
...(groupId && { groupId }),
});
+ const requiresGroup = "groupId" in opts;
+ const canFetch =
+ workspaceId && defaultProgramId && (!requiresGroup || groupId);
+
const { data: rewards, error } = useSWR<RewardListItem[]>(
- workspaceId && defaultProgramId && `/api/rewards?${searchParams}`,
+ canFetch ? `/api/rewards?${searchParams}` : null,
fetcher,
{
dedupingInterval: 60000,
- keepPreviousData: true,
+ keepPreviousData: !groupId,
...swrOpts,
},
);
diff --git a/apps/web/ui/modals/edit-partner-reward-modal.tsx b/apps/web/ui/modals/edit-partner-reward-modal.tsx
index 28730add7b..880f646161 100644
--- a/apps/web/ui/modals/edit-partner-reward-modal.tsx
+++ b/apps/web/ui/modals/edit-partner-reward-modal.tsx
@@ -96,12 +96,14 @@ function EditPartnerRewardModal({
const [isRewardSheetOpen, setIsRewardSheetOpen] = useState(false);
const { id: workspaceId } = useWorkspace();
- const { rewards, loading: rewardsLoading } = useRewards({
- groupId: partner.groupId,
- swrOpts: {
+ const { rewards, loading: rewardsLoading } = useRewards(
+ {
+ groupId: partner.groupId,
+ },
+ {
revalidateOnFocus: true,
},
- });
+ );
const { group } = useGroup({
groupIdOrSlug: partner.groupId ?? undefined,
});