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.

invalidate reward cache

Steven Tey20382a25d899
diff --git a/apps/web/lib/actions/partners/update-program.ts b/apps/web/lib/actions/partners/update-program.ts
index c2a50e2b6f..cf0fbdd00d 100644
--- a/apps/web/lib/actions/partners/update-program.ts
+++ b/apps/web/lib/actions/partners/update-program.ts
@@ -101,7 +101,7 @@ export const updateProgramAction = authActionClient
});
waitUntil(
- Promise.all([
+ Promise.allSettled([
// Delete old logo/wordmark if they were updated
...(logoUrl && program.logo
? [storage.delete(program.logo.replace(`${R2_URL}/`, ""))]
diff --git a/apps/web/lib/actions/partners/update-reward.ts b/apps/web/lib/actions/partners/update-reward.ts
index 3ab245c3df..daa1fac35f 100644
--- a/apps/web/lib/actions/partners/update-reward.ts
+++ b/apps/web/lib/actions/partners/update-reward.ts
@@ -8,6 +8,7 @@ import { updateRewardSchema } from "@/lib/zod/schemas/rewards";
import { prisma } from "@dub/prisma";
import { Prisma } from "@dub/prisma/client";
import { waitUntil } from "@vercel/functions";
+import { revalidatePath } from "next/cache";
import { authActionClient } from "../safe-action";
export const updateRewardAction = authActionClient
@@ -41,22 +42,57 @@ export const updateRewardAction = authActionClient
maxDuration,
modifiers: modifiers === null ? Prisma.JsonNull : modifiers,
},
+ include: {
+ program: true,
+ clickPartnerGroup: true,
+ leadPartnerGroup: true,
+ salePartnerGroup: true,
+ },
+ });
+
+ const {
+ program,
+ clickPartnerGroup,
+ leadPartnerGroup,
+ salePartnerGroup,
+ ...rewardMetadata
+ } = updatedReward;
+ const isDefaultGroup = [
+ clickPartnerGroup,
+ leadPartnerGroup,
+ salePartnerGroup,
+ ].some((group) => group?.slug === "default");
+
+ console.log({
+ isDefaultGroup,
+ clickPartnerGroup,
+ leadPartnerGroup,
+ salePartnerGroup,
});
waitUntil(
- recordAuditLog({
- workspaceId: workspace.id,
- programId,
- action: "reward.updated",
- description: `Reward ${rewardId} updated`,
- actor: user,
- targets: [
- {
- type: "reward",
- id: rewardId,
- metadata: updatedReward,
- },
- ],
- }),
+ Promise.allSettled([
+ recordAuditLog({
+ workspaceId: workspace.id,
+ programId,
+ action: "reward.updated",
+ description: `Reward ${rewardId} updated`,
+ actor: user,
+ targets: [
+ {
+ type: "reward",
+ id: rewardId,
+ metadata: rewardMetadata,
+ },
+ ],
+ }),
+ // we only cache default group pages for now so we need to invalidate them
+ ...(isDefaultGroup
+ ? [
+ revalidatePath(`/partners.dub.co/${program.slug}`),
+ revalidatePath(`/partners.dub.co/${program.slug}/apply`),
+ ]
+ : []),
+ ]),
);
});