feat: integrate contact form with API
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user