Ports the single-file MedCsFiz page — the medical centre that already runs physiotherapy and wants the existing room to earn more — to the same architecture as the fitness and hotel landings: Vite + React 19 + TypeScript + Tailwind v4 on the client, Express 5 for the API, zod schema shared between the two. The original stays in legacy/index.html as the visual reference. Its 4 MB of inlined CSS, JS and base64 images become 12 asset files (664 KB) plus a bundle loaded on demand; the two 1.5 MB / 750 KB device PNGs are recompressed to webp. The page is split into 18 components with all copy moved to src/data/content.ts. Leads reuse the fitness amoCRM integration: contact lookup by phone in every Russian spelling, deal in the first stage of pipeline 10980758, account fields matched automatically with the rest written to a note. Rate limit, honeypot and a localStorage fallback so a lead survives the CRM being down. Endpoint is /api/leads/medical-centers-existing-physio; Vite runs on 5173 and the API on 3000. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
/** Which form on the page produced the lead. Surfaces as an amoCRM tag. */
|
|
export const leadFormIds = ['request'] as const
|
|
export type LeadFormId = (typeof leadFormIds)[number]
|
|
|
|
export const utmKeys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'] 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. */
|
|
cabinet_state: 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(),
|
|
/** 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> }
|