Files
exodevices/medcenterstart/shared/lead.ts
T
yuriy.pandClaude Opus 5.5 a61d53962a Add after-hours callbacks and persistent ad attribution to all four landings
- The callback dialog switches its copy outside business hours
  (shared/business-hours.ts); such leads get a "нерабочее время" tag,
  a marker in the deal name and a line in the note in amoCRM.
- utm_*, yclid and gclid are read on page load and kept for 30 days
  (src/lib/attribution.ts), last tagged visit wins, and are sent with
  every lead.
- The callback dialog is rebuilt: focus trap, focus return, phone
  masking and a full-number check.
- fitnes drops the floating MobileCta; header and mobile bars follow
  the new dialog state in the other three.
- Add the latest design mockups under legacy/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 20:53:40 +06:00

73 lines
2.9 KiB
TypeScript

import { z } from 'zod'
/** Which form on the page produced the lead. Surfaces as an amoCRM tag. */
export const leadFormIds = ['request', 'callback'] as const
export type LeadFormId = (typeof leadFormIds)[number]
/** UTM tags plus the Yandex Direct and Google Ads click IDs. */
export const utmKeys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'yclid', 'gclid'] as const
const optionalText = (max: number) =>
z
.string()
.trim()
.max(max)
.optional()
.transform((v) => (v ? v : undefined))
export const leadSchema = z.object({
form: z.enum(leadFormIds),
name: z.string().trim().min(1, 'Укажите имя').max(200),
phone: z.string().trim().min(5, 'Укажите телефон').max(50),
email: z
.union([z.email().max(200), z.literal('')])
.optional()
.transform((v) => (v ? v : undefined)),
company: optionalText(200),
/** «Основные направления центра» — one of the select's options, or free text. */
profile: optionalText(200),
comment: optionalText(4000),
page: optionalText(300),
referrer: optionalText(500),
// partialRecord, not record: z.record over an enum requires every key.
utm: z.partialRecord(z.enum(utmKeys), z.string().max(300)).optional(),
/**
* The callback form was sent outside business hours, so the visitor was told
* to expect a call on the next working day rather than shortly.
*/
after_hours: z.boolean().optional(),
/** Honeypot. Bots fill it in; humans never see it. */
website: z.string().max(200).optional(),
})
export type LeadPayload = z.infer<typeof leadSchema>
/** What the client sends — before zod's optional/empty-string normalisation. */
export type LeadInput = z.input<typeof leadSchema>
export type LeadResponse =
| { ok: true; leadId: number; contactId: number }
| { ok: false; error: string; fields?: Record<string, string> }
/* -------------------------------------------------------------------------- */
/* Клик по кнопке звонка */
/* -------------------------------------------------------------------------- */
/**
* A visitor tapping the phone button leaves no contact details, so this shares
* nothing with `leadSchema` but the tracking data: it records where the click
* happened, and the lead it produces carries no contact at all.
*/
export const callClickSchema = z.object({
page: optionalText(300),
referrer: optionalText(500),
utm: z.partialRecord(z.enum(utmKeys), z.string().max(300)).optional(),
/** Honeypot. Bots fill it in; humans never see it. */
website: z.string().max(200).optional(),
})
export type CallClickPayload = z.infer<typeof callClickSchema>
/** What the client sends — before zod's optional/empty-string normalisation. */
export type CallClickInput = z.input<typeof callClickSchema>
export type CallClickResponse = { ok: true; leadId: number } | { ok: false; error: string }