mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-25 08:48:13 +02:00
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:
parent
10e17ea221
commit
3ccbc14549
3 changed files with 161 additions and 0 deletions
31
ui/src/components/lead-forms/submitLead.ts
Normal file
31
ui/src/components/lead-forms/submitLead.ts
Normal 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"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue