feat: integrate contact form with API
This commit is contained in:
@@ -115,7 +115,22 @@ export function ContactSection() {
|
|||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
|
|
||||||
try {
|
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();
|
const newCsrfToken = generateCSRFToken();
|
||||||
setCSRFTokenToStorage(newCsrfToken);
|
setCSRFTokenToStorage(newCsrfToken);
|
||||||
@@ -127,7 +142,7 @@ export function ContactSection() {
|
|||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
setToastMessage('提交失败,请稍后重试。');
|
setToastMessage(error instanceof Error ? error.message : '提交失败,请稍后重试。');
|
||||||
setToastType('error');
|
setToastType('error');
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user