From f19421355946a9892dfda9369209d691b62c6ae7 Mon Sep 17 00:00:00 2001 From: Neel Dutta Date: Mon, 2 Nov 2026 14:51:53 +0530 Subject: [PATCH 1/2] fix: set isSubmitting false only after success --- components/forms/recruitmentForm.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/components/forms/recruitmentForm.tsx b/components/forms/recruitmentForm.tsx index 8546f631..ce5279b4 100644 --- a/components/forms/recruitmentForm.tsx +++ b/components/forms/recruitmentForm.tsx @@ -149,15 +149,18 @@ const RecruitmentForm: React.FC = () => { } if (currentStep === "review") { - setIsSubmitting(false); - // Submit registration directly - const success = await submitRegistration(data); - if (success) { - posthog.capture("recruitment_submitted", { - year_of_study: data.year_of_study, - branch: data.branch, - }); - setSuccess(true); + try { + // Submit registration directly + const success = await submitRegistration(data); + if (success) { + posthog.capture("recruitment_submitted", { + year_of_study: data.year_of_study, + branch: data.branch, + }); + setSuccess(true); + } + } finally { + setIsSubmitting(false); } return; } From 0ba82799aae3813c9c3a94f6792d660334026059 Mon Sep 17 00:00:00 2001 From: Neel Dutta Date: Mon, 2 Nov 2026 14:56:14 +0530 Subject: [PATCH 2/2] fix: remove promise.race timeout and prevent posthog crash giving false 500 error even after sucessful save in db --- app/api/registration/recruitment/route.ts | 53 ++++++++++++----------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/app/api/registration/recruitment/route.ts b/app/api/registration/recruitment/route.ts index b97a369e..06acde38 100644 --- a/app/api/registration/recruitment/route.ts +++ b/app/api/registration/recruitment/route.ts @@ -264,14 +264,18 @@ async function checkDuplicates(request: Request) { if (existingCollegeId) duplicates.push("college_id"); if (duplicates.length > 0) { - const posthog = getPostHogClient(); - if (posthog) { - posthog.capture({ - distinctId: normalizedEmail ?? "anonymous", - event: "recruitment_duplicate_detected", - properties: { duplicate_fields: duplicates }, - }); - await posthog.flush(); + try { + const posthog = getPostHogClient(); + if (posthog) { + posthog.capture({ + distinctId: normalizedEmail ?? "anonymous", + event: "recruitment_duplicate_detected", + properties: { duplicate_fields: duplicates }, + }); + await posthog.flush(); + } + } catch (posthogError) { + console.error("[PostHog] Failed to track duplicate check:", posthogError); } return NextResponse.json( { error: "Already registered", duplicates }, @@ -439,24 +443,23 @@ async function addRegistration(request: Request) { const newDoc = new RecruitmentModel(data2); - await Promise.race([ - newDoc.save(), - new Promise((_, reject) => - setTimeout(() => reject(new Error("Save operation timeout")), 10000) - ), - ]); + await newDoc.save(); - const posthog = getPostHogClient(); - if (posthog) { - posthog.capture({ - distinctId: data2.email, - event: "recruitment_registered", - properties: { - year_of_study: data2.year_of_study, - branch: data2.branch, - }, - }); - await posthog.flush(); + try { + const posthog = getPostHogClient(); + if (posthog) { + posthog.capture({ + distinctId: data2.email, + event: "recruitment_registered", + properties: { + year_of_study: data2.year_of_study, + branch: data2.branch, + }, + }); + await posthog.flush(); + } + } catch (posthogError) { + console.error("[PostHog] Failed to track registration:", posthogError); } return NextResponse.json({ message: "Registration successful!" });