The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix program application sheet form submissions
Tim Wilson36e972542a03
diff --git a/apps/web/ui/partners/program-application-sheet.tsx b/apps/web/ui/partners/program-application-sheet.tsxindex 8210117d60..b084b70756 100644--- a/apps/web/ui/partners/program-application-sheet.tsx+++ b/apps/web/ui/partners/program-application-sheet.tsx@@ -29,6 +29,7 @@ import { toast } from "sonner";import useSWR, { mutate } from "swr";import { z } from "zod";import { ProgramApplicationFormField } from "./groups/design/application-form/fields";+import { formDataForApplicationFormData } from "./groups/design/application-form/form-data-for-application-form-data";interface ProgramApplicationSheetProps {setIsOpen: Dispatch<SetStateAction<boolean>>;@@ -51,10 +52,8 @@ type FormData = Omit<function ProgramApplicationSheetContent({program,programEnrollment,- backDestination = "programs",- onSuccess,+ ...rest}: ProgramApplicationSheetProps) {- const { partner } = usePartnerProfile();const groupIdOrSlug =programEnrollment?.groupId ||program?.defaultGroupId ||@@ -74,10 +73,43 @@ function ProgramApplicationSheetContent({},);+ return group ? (+ <ProgramApplicationSheetForm+ program={program}+ programEnrollment={programEnrollment}+ group={group}+ {...rest}+ />+ ) : (+ <div className="flex h-full items-center justify-center">+ {groupError ? (+ <p className="text-content-subtle text-sm">+ Failed to load application form+ </p>+ ) : (+ <LoadingSpinner />+ )}+ </div>+ );+}++function ProgramApplicationSheetForm({+ program,+ programEnrollment,+ backDestination = "programs",+ onSuccess,+ group,+}: ProgramApplicationSheetProps & {+ group: z.infer<typeof PartnerProgramGroupSchema>;+}) {+ const { partner } = usePartnerProfile();+const form = useForm<FormData>({defaultValues: {termsAgreement: false,- formData: { fields: group?.applicationFormData?.fields ?? [] },+ formData: formDataForApplicationFormData(+ group?.applicationFormData?.fields ?? [],+ ),},});@@ -165,62 +197,56 @@ function ProgramApplicationSheetContent({</div><div className="min-h-0 flex-1 overflow-y-auto">- {isGroupLoading ? (- <div className="flex items-center justify-center py-8">- <LoadingSpinner />- </div>- ) : (- <div className="flex flex-col gap-6 p-5 sm:p-8">- {fields?.length ? (- fields.map((field, index) => {- return (- <ProgramApplicationFormField- key={field.id}- field={field}- keyPath={`formData.fields.${index}`}- />- );- })- ) : (- <p className="text-content-subtle flex items-center gap-1 text-sm">- <CircleCheck className="inline-block size-4 text-green-500" />- No additional information required to apply- </p>- )}-- {program.termsUrl && (- <div className="flex items-center gap-2">- <input- type="checkbox"- id="termsAgreement"- className={cn(- "h-4 w-4 rounded border-neutral-300 text-[var(--brand)] focus:ring-[var(--brand)]",- errors.termsAgreement &&- "border-red-400 focus:ring-red-500",- )}- {...register("termsAgreement", {- required: true,- validate: (v) => v === true,- })}+ <div className="flex flex-col gap-6 p-5 sm:p-8">+ {fields?.length ? (+ fields.map((field, index) => {+ return (+ <ProgramApplicationFormField+ key={field.id}+ field={field}+ keyPath={`formData.fields.${index}`}/>- <label- htmlFor="termsAgreement"- className="text-sm text-neutral-800"+ );+ })+ ) : (+ <p className="text-content-subtle flex items-center gap-1 text-sm">+ <CircleCheck className="inline-block size-4 text-green-500" />+ No additional information required to apply+ </p>+ )}++ {program.termsUrl && (+ <div className="flex items-center gap-2">+ <input+ type="checkbox"+ id="termsAgreement"+ className={cn(+ "h-4 w-4 rounded border-neutral-300 text-[var(--brand)] focus:ring-[var(--brand)]",+ errors.termsAgreement &&+ "border-red-400 focus:ring-red-500",+ )}+ {...register("termsAgreement", {+ required: true,+ validate: (v) => v === true,+ })}+ />+ <label+ htmlFor="termsAgreement"+ className="text-sm text-neutral-800"+ >+ I agree to the{" "}+ <a+ href={program.termsUrl}+ target="_blank"+ rel="noopener noreferrer"+ className="text-[var(--brand)] underline hover:opacity-80">- I agree to the{" "}- <a- href={program.termsUrl}- target="_blank"- rel="noopener noreferrer"- className="text-[var(--brand)] underline hover:opacity-80"- >- {program.name} Affiliate Program Terms ↗- </a>- </label>- </div>- )}- </div>- )}+ {program.name} Affiliate Program Terms ↗+ </a>+ </label>+ </div>+ )}+ </div></div><div className="sticky bottom-0 z-10 border-t border-neutral-200 bg-white p-5">@@ -228,7 +254,6 @@ function ProgramApplicationSheetContent({type="submit"variant="primary"text="Submit application"- disabled={isGroupLoading || groupError}loading={isSubmitting}/></div>