This commit is contained in:
root
2026-06-07 18:06:52 +08:00
parent 9de2465793
commit a1daa040ef
33 changed files with 1917 additions and 439 deletions

View File

@@ -11,7 +11,7 @@ const positionOptions = [
{ value: "other", labelZh: "其他", labelEn: "Other" },
];
interface FormData {
interface JobFormData {
position: string;
name: string;
email: string;
@@ -52,7 +52,7 @@ function ChevronDown() {
export default function JobsContent() {
const { t } = useTranslation("jobs");
const locale = useLocale();
const [form, setForm] = useState<FormData>({
const [form, setForm] = useState<JobFormData>({
position: "",
name: "",
email: "",
@@ -61,23 +61,51 @@ export default function JobsContent() {
});
const [resume, setResume] = useState<File | null>(null);
const [resumeError, setResumeError] = useState<string | null>(null);
const [submitting, setSubmitting] = useState(false);
const [submitMessage, setSubmitMessage] = useState("");
const fileRef = useRef<HTMLInputElement>(null);
const set = (key: keyof FormData, value: string) =>
const set = (key: keyof JobFormData, value: string) =>
setForm((prev) => ({ ...prev, [key]: value }));
const handleSubmit = (e: FormEvent) => {
const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
setResumeError(null);
setSubmitMessage("");
if (!resume) {
setResumeError(locale === "zh" ? "请上传简历(PDF 或 Word)" : "Please upload your resume (PDF or Word)");
return;
}
// 暂不提交,无业务逻辑
if (locale === "zh") {
alert("表单已填写完成,提交功能即将上线。");
} else {
alert("Form completed. Submit feature coming soon.");
setSubmitting(true);
try {
const uploadForm = new window.FormData();
uploadForm.append("file", resume);
const uploadRes = await fetch("/api/digital/upload-media", {
method: "POST",
body: uploadForm,
});
const uploadData = await uploadRes.json().catch(() => ({}));
if (!uploadRes.ok || !uploadData?.url) {
throw new Error(uploadData?.error || (locale === "zh" ? "简历上传失败" : "Resume upload failed"));
}
const submitRes = await fetch("/api/digital/jobs", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ...form, resumeUrl: uploadData.url }),
});
const submitData = await submitRes.json().catch(() => ({}));
if (!submitRes.ok || !submitData?.ok) {
throw new Error(submitData?.error || (locale === "zh" ? "提交失败" : "Submit failed"));
}
setForm({ position: "", name: "", email: "", phone: "", intro: "" });
removeResume();
setSubmitMessage(locale === "zh" ? "申请已提交,我们会尽快联系你。" : "Application submitted. We will contact you soon.");
} catch (error) {
setResumeError(error instanceof Error ? error.message : (locale === "zh" ? "提交失败" : "Submit failed"));
} finally {
setSubmitting(false);
}
};
@@ -137,6 +165,12 @@ export default function JobsContent() {
onSubmit={handleSubmit}
className="mt-0 bg-white px-5 pb-8 pt-2 shadow-sm sm:mt-5 sm:rounded-2xl sm:px-8 sm:py-8 sm:shadow-md"
>
{submitMessage && (
<div className="mb-4 rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
{submitMessage}
</div>
)}
<div className="grid gap-0 sm:grid-cols-2 sm:gap-6">
<Field label={t("position")}>
<select
@@ -270,9 +304,10 @@ export default function JobsContent() {
<div className="mt-8 sm:mt-10">
<button
type="submit"
className="w-full rounded-full bg-amber-500 px-8 py-4 text-base font-semibold text-white transition-colors hover:bg-amber-600"
disabled={submitting}
className="w-full rounded-full bg-amber-500 px-8 py-4 text-base font-semibold text-white transition-colors hover:bg-amber-600 disabled:cursor-not-allowed disabled:bg-slate-300"
>
{t("submit")}
{submitting ? (locale === "zh" ? "提交中..." : "Submitting...") : t("submit")}
</button>
</div>
</form>