mirror of
https://github.com/complexcaresolutions/frontend.porwoll.de.git
synced 2026-03-17 16:23:41 +00:00
fix(contact): use direct fetch instead of contracts client for form submission
The @c2s/payload-contracts API client does not load properly in client-side bundles. Use direct fetch() for the form submission POST request. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
582dbfbd12
commit
390036f090
1 changed files with 16 additions and 7 deletions
|
|
@ -5,7 +5,8 @@ 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'
|
||||
|
||||
const PAYLOAD_URL = process.env.NEXT_PUBLIC_PAYLOAD_URL || 'https://cms.c2sgmbh.de'
|
||||
|
||||
interface ContactFormBlockProps {
|
||||
block: Record<string, unknown>
|
||||
|
|
@ -28,13 +29,21 @@ export function ContactFormBlock({ block }: ContactFormBlockProps) {
|
|||
|
||||
try {
|
||||
const formData = new FormData(e.currentTarget)
|
||||
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,
|
||||
const res = await fetch(`${PAYLOAD_URL}/api/form-submissions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
form: formId || 1,
|
||||
submissionData: [
|
||||
{ field: 'name', value: formData.get('name') as string },
|
||||
{ field: 'email', value: formData.get('email') as string },
|
||||
{ field: 'subject', value: formData.get('subject') as string },
|
||||
{ field: 'message', value: formData.get('message') as string },
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
setStatus('success')
|
||||
} catch {
|
||||
setStatus('error')
|
||||
|
|
|
|||
Loading…
Reference in a new issue