diff --git a/src/components/sections/contact-section.tsx b/src/components/sections/contact-section.tsx index 3fd9402..2e39e04 100644 --- a/src/components/sections/contact-section.tsx +++ b/src/components/sections/contact-section.tsx @@ -115,7 +115,22 @@ export function ContactSection() { setIsSubmitting(true); try { - await new Promise(resolve => setTimeout(resolve, 1500)); + const response = await fetch('/api/contact', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + ...formData, + csrfToken: storedToken, + }), + }); + + const data = await response.json(); + + if (!response.ok) { + throw new Error(data.message || '提交失败'); + } const newCsrfToken = generateCSRFToken(); setCSRFTokenToStorage(newCsrfToken); @@ -127,7 +142,7 @@ export function ContactSection() { setShowToast(true); } catch (error) { setIsSubmitting(false); - setToastMessage('提交失败,请稍后重试。'); + setToastMessage(error instanceof Error ? error.message : '提交失败,请稍后重试。'); setToastType('error'); setShowToast(true); }