From c9a199da919187edec8a44dde4b2bf4ec6c752ba Mon Sep 17 00:00:00 2001 From: Zotov Ivan Yuryevich Date: Tue, 21 Apr 2026 21:51:27 +0300 Subject: [PATCH] refactor: extract contact form --- src/components/ContactForm.tsx | 252 ++++++++++++++++++++++++++++++++ src/components/ContactModal.tsx | 182 ++++------------------- src/sections/Contact.tsx | 73 ++------- 3 files changed, 289 insertions(+), 218 deletions(-) create mode 100644 src/components/ContactForm.tsx diff --git a/src/components/ContactForm.tsx b/src/components/ContactForm.tsx new file mode 100644 index 0000000..008756c --- /dev/null +++ b/src/components/ContactForm.tsx @@ -0,0 +1,252 @@ +import { Calendar } from 'lucide-react' + +export type ContactFormField = + | 'name' + | 'company' + | 'email' + | 'phone' + | 'purpose' + | 'timeline' + | 'taskComment' + | 'meetingSlots' + | 'message' + +export interface ContactFormValues { + name?: string + company?: string + email?: string + phone?: string + purpose?: string + timeline?: string + taskComment?: string + meetingSlot1?: string + meetingSlot2?: string + message?: string +} + +export interface ContactFormProps { + visibleFields?: readonly ContactFormField[] + prefillValues?: Partial + submitLabel?: string + className?: string + idPrefix?: string + onSubmit?: (event: React.FormEvent) => void +} + +const DEFAULT_VISIBLE_FIELDS: readonly ContactFormField[] = ['name', 'company', 'email', 'phone', 'message'] + +function withPrefix(prefix: string, fieldName: string): string { + return `${prefix}-${fieldName}` +} + +export function ContactForm({ + visibleFields = DEFAULT_VISIBLE_FIELDS, + prefillValues, + submitLabel = 'Отправить заявку', + className = 'space-y-5', + idPrefix = 'contact-form', + onSubmit, +}: ContactFormProps) { + const fields = new Set(visibleFields) + const showNameCompanyRow = fields.has('name') || fields.has('company') + const showEmailPhoneRow = fields.has('email') || fields.has('phone') + const showPurposeTimelineRow = fields.has('purpose') || fields.has('timeline') + + return ( +
+ {showNameCompanyRow && ( +
+ {fields.has('name') && ( +
+ +
+ )} + + {fields.has('company') && ( +
+ +
+ )} +
+ )} + + {showEmailPhoneRow && ( +
+ {fields.has('email') && ( +
+ +
+ )} + + {fields.has('phone') && ( +
+ +
+ )} +
+ )} + + {showPurposeTimelineRow && ( +
+ {fields.has('purpose') && ( +
+ + +
+ )} + + {fields.has('timeline') && ( +
+ + +
+ )} +
+ )} + + {fields.has('taskComment') && ( +
+ + -
- - {/* Слоты для встречи в ВКС */} -
- -
-
- - -
-
- - -
-
-

- Мы отправим вам приглашение в ВКС на один из выбранных слотов -

-
- -
- -

Нажимая кнопку, вы соглашаетесь с политикой конфиденциальности

-
-
+
diff --git a/src/sections/Contact.tsx b/src/sections/Contact.tsx index de9d4b1..7b6f148 100644 --- a/src/sections/Contact.tsx +++ b/src/sections/Contact.tsx @@ -1,11 +1,14 @@ import { SiteContactItems } from '../components/SiteContactItems' +import { ContactForm, type ContactFormField, type ContactFormValues } from '../components/ContactForm' import type { SiteConfigContact } from '../lib/cms/contact/types' export interface ContactProps { contacts: readonly SiteConfigContact[] + formVisibleFields?: readonly ContactFormField[] + formPrefillValues?: Partial } -export function Contact({ contacts }: ContactProps) { +export function Contact({ contacts, formVisibleFields, formPrefillValues }: ContactProps) { return (
@@ -17,69 +20,11 @@ export function Contact({ contacts }: ContactProps) { {/* Форма */}
-
-
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
- -
- -
- -

Нажимая кнопку, вы соглашаетесь с политикой конфиденциальности

-
-
+