feat: integrate contact form with API

This commit is contained in:
张翔
2026-02-26 17:56:25 +08:00
parent 87a0620670
commit c174370e60
+17 -2
View File
@@ -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);
}