feat(lead-gen): shared field options, work-email validation, and submit seam

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pritesh 2026-06-03 04:19:21 +05:30
parent 10e17ea221
commit 3ccbc14549
3 changed files with 161 additions and 0 deletions

View file

@ -0,0 +1,31 @@
// Single submission seam for all lead forms.
// Today: fires a PostHog capture. Later: add a POST to the backend
// (MongoDB) endpoint here — no form component will need to change.
import posthog from "posthog-js";
import { PostHogEvent } from "@/constants/posthog-events";
import type { LeadKind, LeadSource } from "./leadFieldOptions";
const SUBMIT_EVENT: Record<LeadKind, string> = {
topup: PostHogEvent.TOPUP_REQUESTED,
hire_expert: PostHogEvent.HIRE_EXPERT_SUBMITTED,
enterprise: PostHogEvent.ENTERPRISE_LEAD_SUBMITTED,
};
export interface SubmitLeadArgs {
kind: LeadKind;
source: LeadSource;
// Field values, already validated by the caller. Non-sensitive lead data.
payload: Record<string, unknown>;
}
export async function submitLead({ kind, source, payload }: SubmitLeadArgs): Promise<void> {
// PostHog capture — the durable record until the backend endpoint lands.
posthog.capture(SUBMIT_EVENT[kind], { source, ...payload });
// FUTURE: when the MongoDB endpoint exists, POST here, e.g.
// const res = await submitLeadApiV1LeadsPost({ body: { kind, source, ...payload } });
// if (res.error) throw new Error(detailFromError(res.error, "Failed to submit"));
}