diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a642dee..8aeca4a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,7 +10,7 @@ importers: dependencies: '@c2s/payload-contracts': specifier: github:complexcaresolutions/payload-contracts - version: git+https://git@github.com:complexcaresolutions/payload-contracts.git#64847594b2150bfdce09a7bd7f54ad2f52d6f2b7(react@19.2.1) + version: git+https://git@github.com:complexcaresolutions/payload-contracts.git#c168832a128a38ae2c4f87057bc28b1b56b60236(react@19.2.1) clsx: specifier: ^2.1.1 version: 2.1.1 @@ -134,8 +134,8 @@ packages: resolution: {integrity: sha512-qQ5m48eI/MFLQ5PxQj4PFaprjyCTLI37ElWMmNs0K8Lk3dVeOdNpB3ks8jc7yM5CDmVC73eMVk/trk3fgmrUpA==} engines: {node: '>=6.9.0'} - '@c2s/payload-contracts@git+https://git@github.com:complexcaresolutions/payload-contracts.git#64847594b2150bfdce09a7bd7f54ad2f52d6f2b7': - resolution: {commit: 64847594b2150bfdce09a7bd7f54ad2f52d6f2b7, repo: git@github.com:complexcaresolutions/payload-contracts.git, type: git} + '@c2s/payload-contracts@git+https://git@github.com:complexcaresolutions/payload-contracts.git#c168832a128a38ae2c4f87057bc28b1b56b60236': + resolution: {commit: c168832a128a38ae2c4f87057bc28b1b56b60236, repo: git@github.com:complexcaresolutions/payload-contracts.git, type: git} version: 1.0.0 peerDependencies: react: ^19.0.0 @@ -2080,7 +2080,7 @@ snapshots: '@babel/helper-string-parser': 7.27.1 '@babel/helper-validator-identifier': 7.28.5 - '@c2s/payload-contracts@git+https://git@github.com:complexcaresolutions/payload-contracts.git#64847594b2150bfdce09a7bd7f54ad2f52d6f2b7(react@19.2.1)': + '@c2s/payload-contracts@git+https://git@github.com:complexcaresolutions/payload-contracts.git#c168832a128a38ae2c4f87057bc28b1b56b60236(react@19.2.1)': optionalDependencies: react: 19.2.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..8e4c181 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +onlyBuiltDependencies: + - "@c2s/payload-contracts" diff --git a/src/components/blocks/ContactFormBlock.tsx b/src/components/blocks/ContactFormBlock.tsx index b5ba901..afcbf17 100644 --- a/src/components/blocks/ContactFormBlock.tsx +++ b/src/components/blocks/ContactFormBlock.tsx @@ -5,14 +5,21 @@ import { motion } from 'framer-motion' import { Container } from '../ui/Container' import { Button } from '../ui/Button' import { cn } from '@/lib/utils' +import { submitContactForm } from '@/lib/api' interface ContactFormBlockProps { block: Record } export function ContactFormBlock({ block }: ContactFormBlockProps) { - const title = (block.title as string) || (block.headline as string) || 'Kontakt' - const subtitle = (block.subtitle as string) || 'Haben Sie Fragen? Schreiben Sie mir.' + const title = (block.headline as string) || 'Kontakt' + const description = (block.description as string) || 'Haben Sie Fragen? Schreiben Sie mir.' + const successText = (block.successMessage as string) || 'Vielen Dank! Ich werde mich schnellstmöglich bei Ihnen melden.' + + // Extract formId from the form relationship (can be number or { id: number }) + const formRef = block.form as number | { id: number } | undefined + const formId = typeof formRef === 'object' ? formRef?.id : formRef + const [status, setStatus] = useState<'idle' | 'sending' | 'success' | 'error'>('idle') const handleSubmit = async (e: React.FormEvent) => { @@ -21,22 +28,14 @@ export function ContactFormBlock({ block }: ContactFormBlockProps) { try { const formData = new FormData(e.currentTarget) - const response = await fetch('/api/contact', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - name: formData.get('name'), - email: formData.get('email'), - subject: formData.get('subject'), - message: formData.get('message'), - }), + await submitContactForm({ + name: formData.get('name') as string, + email: formData.get('email') as string, + subject: formData.get('subject') as string, + message: formData.get('message') as string, + formId: formId || undefined, }) - - if (response.ok) { - setStatus('success') - } else { - setStatus('error') - } + setStatus('success') } catch { setStatus('error') } @@ -73,13 +72,13 @@ export function ContactFormBlock({ block }: ContactFormBlockProps) {

{title}

-

{subtitle}

+

{description}

{/* Success Message */} {status === 'success' && (
- Vielen Dank! Ich werde mich schnellstmöglich bei Ihnen melden. + {successText}
)}