From ed0cfb8875c764af2efcf4d1a29c50ac6209c311 Mon Sep 17 00:00:00 2001 From: Tim Wilson Date: Fri, 15 Nov 2024 12:43:19 -0500 Subject: [PATCH] Save applications and create enrollments when logged in --- .../apply/[programSlug]/application/form.tsx | 10 +- .../application/success/cta-button.tsx | 23 -- .../application/success/cta-buttons.tsx | 35 +++ .../application/success/page.tsx | 52 ++-- .../partners/create-program-application.ts | 227 ++++++++++-------- .../lib/actions/partners/onboard-partner.ts | 13 +- apps/web/lib/auth/options.ts | 4 + .../partners/complete-program-applications.ts | 102 ++++++++ apps/web/prisma/schema/partner.prisma | 1 - apps/web/prisma/schema/program.prisma | 25 +- 10 files changed, 322 insertions(+), 170 deletions(-) delete mode 100644 apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/success/cta-button.tsx create mode 100644 apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/success/cta-buttons.tsx create mode 100644 apps/web/lib/partners/complete-program-applications.ts diff --git a/apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/form.tsx b/apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/form.tsx index e94fc33abd..d1b661641c 100644 --- a/apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/form.tsx +++ b/apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/form.tsx @@ -50,7 +50,8 @@ export function ProgramApplicationForm({ if (!response?.data?.ok) { toast.error( - response?.data?.message ?? "Failed to submit application", + (response?.data as { message?: string }).message ?? + "Failed to submit application", ); setError("root.serverError", { message: "Failed to submit application. Please try again.", @@ -60,7 +61,12 @@ export function ProgramApplicationForm({ toast.success("Application submitted successfully"); router.push( - `/apply/${program.slug}/application/success?applicationId=${response.data.programApplicationId}`, + `/apply/${program.slug}/application/success?${new URLSearchParams({ + applicationId: response.data.programApplicationId, + ...("programEnrollmentId" in response.data && { + enrollmentId: response.data.programEnrollmentId, + }), + }).toString()}`, ); })} className="flex flex-col gap-6" diff --git a/apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/success/cta-button.tsx b/apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/success/cta-button.tsx deleted file mode 100644 index 21021f7c47..0000000000 --- a/apps/web/app/partners.dub.co/(apply)/apply/[programSlug]/application/success/cta-button.tsx +++ /dev/null @@ -1,23 +0,0 @@ -"use client"; - -import { Button } from "@dub/ui"; -import { useSession } from "next-auth/react"; -import { useRouter } from "next/navigation"; - -export function CTAButton() { - const router = useRouter(); - const { data: session } = useSession(); - - return ( -