Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions app/api/registration/recruitment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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!" });
Expand Down
21 changes: 12 additions & 9 deletions components/forms/recruitmentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading