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.

fix program application

Steven Tey2f52373fd56f
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index 68a2528799..0e64060837 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -41,22 +41,22 @@ export const createProgramApplicationAction = actionClient
throw new Error("Too many requests. Please try again later.");
}
- const [program, group] = await Promise.all([
- prisma.program.findUniqueOrThrow({
- where: {
- id: programId,
- },
- }),
-
- prisma.partnerGroup.findUniqueOrThrow({
- where: {
- id: groupId,
+ const program = await prisma.program.findUniqueOrThrow({
+ where: {
+ id: programId,
+ },
+ include: {
+ groups: {
+ where: {
+ ...(groupId ? { id: groupId } : { slug: "default" }),
+ },
},
- }),
- ]);
+ },
+ });
- if (group.programId !== program.id) {
- throw new Error(`Group ${group.name} is not found on this program.`);
+ // this should never happen, but just in case
+ if (!program.groups.length) {
+ throw new Error("This program has no groups.");
}
const session = await getSession();
@@ -78,14 +78,14 @@ export const createProgramApplicationAction = actionClient
program,
data: parsedInput,
partner: existingPartner,
- group,
+ group: program.groups[0],
});
}
const application = await createApplication({
program,
data: parsedInput,
- group,
+ group: program.groups[0],
});
await qstash.publishJSON({
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index 9397aceff3..c3d491820c 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -170,7 +170,7 @@ export const ProgramMetricsSchema = z.object({
export const createProgramApplicationSchema = z.object({
programId: z.string(),
- groupId: z.string(),
+ groupId: z.string().optional(),
name: z.string().trim().min(1).max(100),
email: z.string().trim().email().min(1).max(100),
website: z.string().trim().max(100).optional(),
diff --git a/apps/web/ui/partners/program-application-sheet.tsx b/apps/web/ui/partners/program-application-sheet.tsx
index 5baba4e7a4..25a8708a58 100644
--- a/apps/web/ui/partners/program-application-sheet.tsx
+++ b/apps/web/ui/partners/program-application-sheet.tsx
@@ -1,5 +1,6 @@
"use client";
+import { parseActionError } from "@/lib/actions/parse-action-errors";
import { createProgramApplicationAction } from "@/lib/actions/partners/create-program-application";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { ProgramProps } from "@/lib/types";
@@ -72,10 +73,16 @@ function ProgramApplicationSheetContent({
});
if (result?.serverError || result?.validationErrors) {
+ const errorMessage = parseActionError(
+ result,
+ "Failed to submit application",
+ );
+
setError("root.serverError", {
- message: "Failed to submit application",
+ message: errorMessage,
});
- toast.error("Failed to submit application");
+
+ toast.error(errorMessage);
}
};