import { drawerInputClass, drawerTextareaClass, Field, Section, Toggle, useScopedFormContext } from '@components/common/page-builder/index.js'; import { Alert, AlertDescription, AlertTitle } from '@components/common/ui/Alert.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import { Mail, TriangleAlert } from 'lucide-react'; import React from 'react'; import { useQuery } from 'urql'; const StoreEmailQuery = ` query StoreEmail { setting { storeEmail } storeSettingUrl: url(routeId: "storeSetting") } `; /** * Where the messages go. * * The recipient is the store email setting and nothing else — never a * per-widget address, which would be scraped straight off the page source. That * is invisible from inside the drawer, so state it either way rather than only * when something is wrong: a merchant configuring this form should not have to * guess where a customer's message will land. * * Both branches also say that submissions are stored regardless, because the * email is a notification, not the record. */ function StoreEmailNote() { const [{ data, fetching }] = useQuery({ query: StoreEmailQuery }); if (fetching) { return null; } const storeEmail = data?.setting?.storeEmail; const settingsUrl = data?.storeSettingUrl; if (!storeEmail) { return ( {_('Store email is not set')} {_( 'Messages will still be saved and visible under CMS → Contact messages, but no notification email will be sent.' )}{' '} {settingsUrl && ( {_('Add a store email')} )} ); } // Quiet by design — this is reassurance on every open, not an alert. return (
{_( 'Messages are sent to ${email} and saved under CMS → Contact messages.', { email: storeEmail } )}{' '} {settingsUrl && ( {_('Change')} )}
); } interface ContactFormSettingProps { contactFormWidget?: { title?: string | null; subtitle?: string | null; submitLabel?: string | null; successMessage?: string | null; showPhone?: boolean | null; showSubject?: boolean | null; consentEnabled?: boolean | null; consentText?: string | null; }; } export default function ContactFormSetting({ contactFormWidget }: ContactFormSettingProps) { // Optional-chained: in the page-builder drawer this mounts via // with no GraphQL props — the page-level form // already holds the values. const { title = '', subtitle = '', submitLabel = '', successMessage = '', showPhone, showSubject, consentEnabled, consentText = '' } = contactFormWidget ?? {}; const { setValue, watch } = useScopedFormContext(); const phoneOn = (watch('settings.showPhone') as boolean | null) ?? showPhone ?? false; const subjectOn = (watch('settings.showSubject') as boolean | null) ?? showSubject ?? false; const consentOn = (watch('settings.consentEnabled') as boolean | null) ?? consentEnabled ?? false; return ( // The drawer's `space-y-6` applies to the wrapper, not to what the // setting component renders inside it — so the spacing between sections is // ours to supply, like every other widget setting component.
setValue('settings.title', e.target.value, { shouldDirty: true }) } placeholder={_('e.g. Get in touch')} className={drawerInputClass} />