From c174370e603e1d71d36c1861c902d2a19a986665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 26 Feb 2026 17:56:25 +0800 Subject: [PATCH] feat: integrate contact form with API --- src/components/sections/contact-section.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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); }