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.

Merge branch 'main' into lander-builder

Steven Tey9a4b2f185d9c
diff --cc apps/web/lib/actions/partners/update-program.ts
index f38e0b38e6,8eced649b9..340cbadd44
--- a/apps/web/lib/actions/partners/update-program.ts
+++ b/apps/web/lib/actions/partners/update-program.ts
@@@ -1,11 -1,10 +1,12 @@@
"use server";
+ import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { getFolderOrThrow } from "@/lib/folder/get-folder-or-throw";
import { isStored, storage } from "@/lib/storage";
+import { programLanderSchema } from "@/lib/zod/schemas/program-lander";
import { prisma } from "@dub/prisma";
++import { Prisma } from "@dub/prisma/client";
import { nanoid, R2_URL } from "@dub/utils";
- import { Prisma } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { z } from "zod";
import { getProgramOrThrow } from "../../api/programs/get-program-or-throw";
@@@ -44,68 -39,64 +43,65 @@@ export const updateProgramAction = auth
termsUrl,
} = parsedInput;
- try {
- const program = await getProgramOrThrow({
+ const programId = getDefaultProgramIdOrThrow(workspace);
+ const program = await getProgramOrThrow({
+ workspaceId: workspace.id,
+ programId,
+ });
+
+ if (defaultFolderId) {
+ await getFolderOrThrow({
workspaceId: workspace.id,
- programId,
+ userId: ctx.user.id,
+ folderId: defaultFolderId,
});
+ }
- if (defaultFolderId) {
- await getFolderOrThrow({
- workspaceId: workspace.id,
- userId: ctx.user.id,
- folderId: defaultFolderId,
- });
- }
-
- const [logoUrl, wordmarkUrl] = await Promise.all([
- logo && !isStored(logo)
- ? storage
- .upload(`programs/${programId}/logo_${nanoid(7)}`, logo)
- .then(({ url }) => url)
- : null,
- wordmark && !isStored(wordmark)
- ? storage
- .upload(`programs/${programId}/wordmark_${nanoid(7)}`, wordmark)
- .then(({ url }) => url)
- : null,
- ]);
+ const [logoUrl, wordmarkUrl] = await Promise.all([
+ logo && !isStored(logo)
+ ? storage
+ .upload(`programs/${programId}/logo_${nanoid(7)}`, logo)
+ .then(({ url }) => url)
+ : null,
+ wordmark && !isStored(wordmark)
+ ? storage
+ .upload(`programs/${programId}/wordmark_${nanoid(7)}`, wordmark)
+ .then(({ url }) => url)
+ : null,
+ ]);
- await prisma.program.update({
- where: {
- id: programId,
- },
- data: {
- name,
- cookieLength,
- holdingPeriodDays,
- minPayoutAmount,
- domain,
- url,
- brandColor,
- logo: logoUrl ?? undefined,
- wordmark: wordmarkUrl ?? undefined,
- landerData: landerData === null ? Prisma.JsonNull : landerData,
- defaultFolderId,
- linkStructure,
- supportEmail,
- helpUrl,
- termsUrl,
- },
- });
+ await prisma.program.update({
+ where: {
+ id: programId,
+ },
+ data: {
+ name,
+ cookieLength,
+ holdingPeriodDays,
+ minPayoutAmount,
+ domain,
+ url,
+ brandColor,
+ logo: logoUrl ?? undefined,
+ wordmark: wordmarkUrl ?? undefined,
++ landerData: landerData === null ? Prisma.JsonNull : landerData,
+ defaultFolderId,
+ linkStructure,
+ supportEmail,
+ helpUrl,
+ termsUrl,
+ },
+ });
- // Delete old logo/wordmark if they were updated
- waitUntil(
- Promise.all([
- ...(logoUrl && program.logo
- ? [storage.delete(program.logo.replace(`${R2_URL}/`, ""))]
- : []),
- ...(wordmarkUrl && program.wordmark
- ? [storage.delete(program.wordmark.replace(`${R2_URL}/`, ""))]
- : []),
- ]),
- );
- } catch (e) {
- throw new Error("Failed to update program.");
- }
+ // Delete old logo/wordmark if they were updated
+ waitUntil(
+ Promise.all([
+ ...(logoUrl && program.logo
+ ? [storage.delete(program.logo.replace(`${R2_URL}/`, ""))]
+ : []),
+ ...(wordmarkUrl && program.wordmark
+ ? [storage.delete(program.wordmark.replace(`${R2_URL}/`, ""))]
+ : []),
+ ]),
+ );
});