diff --git a/app/api/send-email/route.js b/app/api/send-email/route.js
index 3f91bdd..81db196 100644
--- a/app/api/send-email/route.js
+++ b/app/api/send-email/route.js
@@ -16,15 +16,18 @@ export async function POST(request) {
);
const message = response.data.message;
if (message?.success) {
- return Response.json({ success: true, message: message.message || 'Email sent successfully' });
+ const successMessage = typeof message.message === 'string' ? message.message : 'Email sent successfully';
+ return Response.json({ success: true, message: successMessage });
} else if (message?.error) {
- return Response.json({ error: message.error }, { status: 400 });
+ const errorMessage = typeof message.error === 'string' ? message.error : 'Failed to send email';
+ return Response.json({ error: errorMessage }, { status: 400 });
} else {
return Response.json({ error: 'Unknown error' }, { status: 500 });
}
} catch (error) {
+ const errorMessage = typeof error.message === 'string' ? error.message : 'Internal server error';
return Response.json(
- { error: error.message, detail: error?.response?.data || null },
+ { error: errorMessage, detail: error?.response?.data || null },
{ status: 500 }
);
}
diff --git a/app/contact/page.jsx b/app/contact/page.jsx
index a55dad4..e76b9bb 100644
--- a/app/contact/page.jsx
+++ b/app/contact/page.jsx
@@ -1,32 +1,61 @@
import Contact1 from "@/components/contact/Contact1";
import React from "react";
import Banner from "@/components/banner/Banner";
+import { getPageData, getSiteSettings, fetchComponentData } from "@/utils/data";
+import { notFound } from 'next/navigation';
export const revalidate = 3600;
export async function generateMetadata() {
const slugArr = ["contact"];
- const res = await fetch(`${process.env.PUBLIC_SITE_URL}/api/get-page-data`, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ slug_list: slugArr })
+ const { data, error, page_info } = await getPageData({
+ slug_list: slugArr,
+ downloadFiles: false // Do not download files for metadata
});
- const { data, error } = await res.json();
+ const siteSettings = await getSiteSettings();
+ const siteName = siteSettings.site_name || '';
+ const siteNameInPageTitles = siteSettings.site_name_in_page_titles || 'None';
+
if (error) {
return {
- title: error.title || '',
+ title: error.title || 'Contact Error',
description: error.message || '',
};
}
+
+ let title = '';
+ if (Array.isArray(data) && page_info) {
+ title = page_info.meta_title || page_info.title || '';
+ } else {
+ title = data?.meta_title || data?.title || '';
+ }
+
+ if (siteName && title) {
+ if (siteNameInPageTitles === 'After') {
+ title = `${title} - ${siteName}`;
+ } else if (siteNameInPageTitles === 'Before') {
+ title = `${siteName} - ${title}`;
+ }
+ }
+
return {
- title: data?.meta_title || data?.title || '',
+ title,
description: data?.meta_description || data?.description || '',
};
}
-export default async function ContactPage() {
- const res = await fetch(`${process.env.PUBLIC_SITE_URL}/api/get-component-data?component_name=Contact`, { cache: 'no-store' });
- const { data } = await res.json();
+export default async function Page() {
+ const slugArr = ["contact"];
+
+ // 获取页面数据
+ const { data, error } = await getPageData({
+ slug_list: slugArr,
+ downloadFiles: true // Download files for page rendering
+ });
+
+ if (error) {
+ notFound();
+ }
return (
<>
@@ -35,7 +64,7 @@ export default async function ContactPage() {
componentName="Banner-contact"
className="contact-banner"
/>
-
+
>
);
diff --git a/components/contact/Contact1.jsx b/components/contact/Contact1.jsx
deleted file mode 100644
index cbd0f86..0000000
--- a/components/contact/Contact1.jsx
+++ /dev/null
@@ -1,338 +0,0 @@
-"use client";
-import React, { useEffect, useState } from "react";
-import axios from "axios";
-
-export default function Contact1({ ssrData }) {
- const [data, setData] = useState(ssrData || null);
- const [loading, setLoading] = useState(!ssrData);
- const [error, setError] = useState(null);
- const [modal, setModal] = useState({ open: false, message: '', type: 'success' });
-
- useEffect(() => {
- if (!ssrData) {
- setLoading(true);
- axios.get("/api/get-component-data", { params: { component_name: "Contact" } })
- .then(res => setData(res.data.data))
- .catch(() => setError("Failed to get Contact data"))
- .finally(() => setLoading(false));
- } else {
- setLoading(false);
- }
- }, [ssrData]);
-
- if (loading) return
Loading...
;
- if (error) return null;
- if (!data) return null;
-
-
- const contacts = Array.isArray(data.items) ? data.items : [];
-
- const [form, setForm] = useState({
- name: '',
- phone: '',
- email: '',
- department: '',
- message: ''
- });
- const [submitting, setSubmitting] = useState(false);
- const [submitResult, setSubmitResult] = useState(null);
-
- function handleInputChange(e) {
- const { name, value } = e.target;
- setForm(prev => ({ ...prev, [name]: value }));
- }
-
- async function handleSubmit(e) {
- e.preventDefault();
- setSubmitting(true);
- setSubmitResult(null);
- try {
- const content = [
- `Name: ${form.name}`,
- `Phone: ${form.phone}`,
- `Email: ${form.email}`,
- `Department: ${form.department}`,
- `Message:
${form.message.replace(/\n/g, '
')}`
- ].join("
");
- const res = await axios.post('/api/send-email', {
- subject: `Website Contact Form: ${form.name}`,
- content
- });
- if (res.data.success) {
- setModal({ open: true, message: res.data.message || 'Email sent successfully!', type: 'success' });
- setSubmitResult(null);
- setForm({ name: '', phone: '', email: '', department: '', message: '' });
- } else {
- setModal({ open: true, message: res.data.error || 'Failed to send', type: 'error' });
- setSubmitResult(null);
- }
- } catch (err) {
- setModal({ open: true, message: err?.response?.data?.error || err.message || 'Failed to send', type: 'error' });
- setSubmitResult(null);
- } finally {
- setSubmitting(false);
- }
- }
-
- function closeModal() {
- setModal({ open: false, message: '', type: 'success' });
- }
-
- return (
-
-
-
-
-
-
-
-
-
- {contacts.map((item, idx) => (
-
- {(item.item_html_code || item.item_icon) && (
-
- {item.item_html_code ? (
-
- ) : (
-

- )}
-
- )}
-
- {item.item_title}
-
-
-
- ))}
-
-
- {/*/column */}
-
- {/*/.row */}
-
- {/* /.card */}
-
- {/* /column */}
-
- {/* /.row */}
-
-
-
- {data.title}
-
-
- {data.description}
-
-
- {/* /form */}
-
- {/* /column */}
-
- {/* /.row */}
-
- {/* /.container */}
-
- );
-}
diff --git a/components/contact/Contact1/UI.jsx b/components/contact/Contact1/UI.jsx
new file mode 100644
index 0000000..f2f89c0
--- /dev/null
+++ b/components/contact/Contact1/UI.jsx
@@ -0,0 +1,201 @@
+"use client";
+import React, { useState } from "react";
+import axios from "axios";
+
+export default function UI({ data }) {
+ if (!data) return null;
+
+ const contacts = Array.isArray(data.items) ? data.items : [];
+
+ const [form, setForm] = useState({
+ name: '', phone: '', email: '', department: '', message: ''
+ });
+ const [submitting, setSubmitting] = useState(false);
+ const [modal, setModal] = useState({ open: false, message: '', type: 'success' });
+
+ function handleInputChange(e) {
+ const { name, value } = e.target;
+ setForm(prev => ({ ...prev, [name]: value }));
+ }
+
+ async function handleSubmit(e) {
+ e.preventDefault();
+ setSubmitting(true);
+ try {
+ const content = [
+ `Name: ${form.name}`,
+ `Phone: ${form.phone}`,
+ `Email: ${form.email}`,
+ `Department: ${form.department}`,
+ `Message:
${form.message.replace(/\n/g, '
')}`
+ ].join("
");
+ const res = await axios.post('/api/send-email', {
+ subject: `Website Contact Form: ${form.name}`,
+ content
+ });
+ if (res.data.success) {
+ const message = typeof res.data.message === 'string' ? res.data.message : 'Email sent successfully!';
+ setModal({ open: true, message, type: 'success' });
+ setForm({ name: '', phone: '', email: '', department: '', message: '' });
+ } else {
+ const errorMessage = typeof res.data.error === 'string' ? res.data.error : 'Failed to send email';
+ setModal({ open: true, message: errorMessage, type: 'error' });
+ }
+ } catch (err) {
+ let errorMessage = 'Failed to send email';
+ if (err?.response?.data?.error) {
+ errorMessage = typeof err.response.data.error === 'string' ? err.response.data.error : 'Failed to send email';
+ } else if (err?.message) {
+ errorMessage = typeof err.message === 'string' ? err.message : 'Failed to send email';
+ }
+ setModal({ open: true, message: errorMessage, type: 'error' });
+ } finally {
+ setSubmitting(false);
+ }
+ }
+
+ function closeModal() {
+ setModal({ open: false, message: '', type: 'success' });
+ }
+
+ return (
+
+
+
+
+
+
+
+
+
+ {contacts.map((item, idx) => (
+
+ {(item.item_html_code || item.item_icon) && (
+
+ {item.item_html_code ? (
+
+ ) : (
+

+ )}
+
+ )}
+
+ {item.item_title}
+
+
+
+ ))}
+
+
+
+
+
+
+
+
+
+ {data.title}
+
+
+ {data.description}
+
+
+
+
+
+
+ );
+}
diff --git a/components/contact/Contact1/index.jsx b/components/contact/Contact1/index.jsx
new file mode 100644
index 0000000..6752207
--- /dev/null
+++ b/components/contact/Contact1/index.jsx
@@ -0,0 +1,16 @@
+import { getComponentName } from "@/utils/getComponentName";
+import { fetchComponentData } from "@/utils/data";
+import UI from "./UI";
+
+const componentName = getComponentName(import.meta.url);
+
+export default async function Component() {
+ const result = await fetchComponentData(componentName);
+
+ if (result.error || !result.data) {
+ if (result.error) console.error(`Failed to fetch ${componentName} data:`, result.error);
+ return null;
+ }
+
+ return ;
+}
diff --git a/components/headers/Header.jsx b/components/headers/Header.jsx
index c3b60f0..2393743 100644
--- a/components/headers/Header.jsx
+++ b/components/headers/Header.jsx
@@ -2,7 +2,7 @@ import React from "react";
import Nav from "./Nav";
import Link from "next/link";
import Image from "next/image";
-import LoginButton from "./LoginButton";
+import LanguageSelect from "./LanguageSelect";
import SocialLinks from "../contact/SocialLinks";
import { getSiteSettings } from "@/utils/data";
@@ -16,7 +16,7 @@ export default async function Header() {
return (