's'
This commit is contained in:
@@ -1,20 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Suspense, useEffect, useState } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useTranslation } from "@/i18n/navigation";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import { apiFetch } from "@/app/lib/api-client";
|
||||
|
||||
export default function FeedbackPage() {
|
||||
type FeedbackType = "suggestion" | "bug" | "report";
|
||||
|
||||
function FeedbackForm() {
|
||||
const { t } = useTranslation("feedback");
|
||||
const searchParams = useSearchParams();
|
||||
const initialType = searchParams.get("type") === "report" ? "report" : "suggestion";
|
||||
const reportTarget = searchParams.get("target") || "";
|
||||
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
const [form, setForm] = useState({
|
||||
type: "suggestion" as "suggestion" | "bug",
|
||||
type: initialType as FeedbackType,
|
||||
email: "",
|
||||
title: "",
|
||||
content: "",
|
||||
targetId: reportTarget,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (reportTarget) {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
type: "report",
|
||||
targetId: reportTarget,
|
||||
title: prev.title || t("reportTitle").replace("{target}", reportTarget),
|
||||
content: prev.content || t("reportContent").replace("{target}", reportTarget),
|
||||
}));
|
||||
}
|
||||
}, [reportTarget, t]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
await apiFetch("/api/feedback", {
|
||||
@@ -26,32 +46,34 @@ export default function FeedbackPage() {
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<main className="max-w-[640px] mx-auto px-4 sm:px-6 py-8 sm:py-12">
|
||||
<main className="mx-auto max-w-[640px] px-4 py-8 sm:px-6 sm:py-12">
|
||||
<header className="mb-8">
|
||||
<h1 className="text-2xl sm:text-3xl font-bold text-gray-900 dark:text-gray-100 flex items-center gap-2">
|
||||
<span className="w-1 h-8 bg-[#ff4d4f] rounded-full" />
|
||||
{t("title")}
|
||||
<h1 className="flex items-center gap-2 text-2xl font-bold text-gray-900 dark:text-gray-100 sm:text-3xl">
|
||||
<span className="h-8 w-1 rounded-full bg-[#ff4d4f]" />
|
||||
{form.type === "report" ? t("reportPageTitle") : t("title")}
|
||||
</h1>
|
||||
<p className="text-gray-500 dark:text-gray-400 mt-1 text-sm sm:text-base">
|
||||
{t("subtitle")}
|
||||
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400 sm:text-base">
|
||||
{form.type === "report" ? t("reportPageSubtitle") : t("subtitle")}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
{submitted ? (
|
||||
<div className="bg-white dark:bg-gray-900 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-800 p-8 text-center">
|
||||
<span className="text-5xl mb-4 block">🙏</span>
|
||||
<h2 className="text-xl font-bold text-gray-900 dark:text-gray-100 mb-2">
|
||||
{t("successTitle")}
|
||||
</h2>
|
||||
<p className="text-gray-500 dark:text-gray-400 mb-6">
|
||||
{t("successDesc")}
|
||||
</p>
|
||||
<div className="rounded-2xl border border-gray-100 bg-white p-8 text-center shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<span className="mb-4 block text-5xl">🙏</span>
|
||||
<h2 className="mb-2 text-xl font-bold text-gray-900 dark:text-gray-100">{t("successTitle")}</h2>
|
||||
<p className="mb-6 text-gray-500 dark:text-gray-400">{t("successDesc")}</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
setSubmitted(false);
|
||||
setForm({ type: "suggestion", email: "", title: "", content: "" });
|
||||
setForm({
|
||||
type: "suggestion",
|
||||
email: "",
|
||||
title: "",
|
||||
content: "",
|
||||
targetId: "",
|
||||
});
|
||||
}}
|
||||
className="px-6 py-2.5 rounded-xl border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 font-medium hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors"
|
||||
className="rounded-xl border border-gray-200 px-6 py-2.5 font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800"
|
||||
>
|
||||
{t("submitAnother")}
|
||||
</button>
|
||||
@@ -59,93 +81,76 @@ export default function FeedbackPage() {
|
||||
) : (
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="bg-white dark:bg-gray-900 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-800 p-6 sm:p-8 space-y-6"
|
||||
className="space-y-6 rounded-2xl border border-gray-100 bg-white p-6 shadow-sm dark:border-gray-800 dark:bg-gray-900 sm:p-8"
|
||||
>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||
{t("type")} *
|
||||
</label>
|
||||
<div className="flex gap-3">
|
||||
<label className="flex-1 flex items-center justify-center gap-2 p-3 rounded-xl border cursor-pointer transition-colors has-[:checked]:border-[#ff4d4f] has-[:checked]:bg-[#ff4d4f]/5">
|
||||
<input
|
||||
type="radio"
|
||||
name="type"
|
||||
value="suggestion"
|
||||
checked={form.type === "suggestion"}
|
||||
onChange={(e) =>
|
||||
setForm((f) => ({ ...f, type: e.target.value as "suggestion" }))
|
||||
}
|
||||
className="sr-only"
|
||||
/>
|
||||
<span>💡</span>
|
||||
<span>{t("suggestion")}</span>
|
||||
</label>
|
||||
<label className="flex-1 flex items-center justify-center gap-2 p-3 rounded-xl border cursor-pointer transition-colors has-[:checked]:border-[#ff4d4f] has-[:checked]:bg-[#ff4d4f]/5">
|
||||
<input
|
||||
type="radio"
|
||||
name="type"
|
||||
value="bug"
|
||||
checked={form.type === "bug"}
|
||||
onChange={(e) =>
|
||||
setForm((f) => ({ ...f, type: e.target.value as "bug" }))
|
||||
}
|
||||
className="sr-only"
|
||||
/>
|
||||
<span>🐛</span>
|
||||
<span>{t("bug")}</span>
|
||||
</label>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300">{t("type")} *</label>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{(["suggestion", "bug", "report"] as FeedbackType[]).map((type) => (
|
||||
<label
|
||||
key={type}
|
||||
className="flex flex-1 min-w-[120px] cursor-pointer items-center justify-center gap-2 rounded-xl border p-3 transition-colors has-[:checked]:border-[#ff4d4f] has-[:checked]:bg-[#ff4d4f]/5"
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name="type"
|
||||
value={type}
|
||||
checked={form.type === type}
|
||||
onChange={() => setForm((f) => ({ ...f, type }))}
|
||||
className="sr-only"
|
||||
/>
|
||||
<span>{type === "suggestion" ? "💡" : type === "bug" ? "🐛" : "🚩"}</span>
|
||||
<span>{t(type)}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{form.type === "report" && form.targetId ? (
|
||||
<div className="rounded-xl bg-rose-50 px-4 py-3 text-sm text-rose-800 dark:bg-rose-950/30 dark:text-rose-200">
|
||||
{t("reportTargetLabel")}: <code className="font-mono">{form.targetId}</code>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||
{t("email")} *
|
||||
</label>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300">{t("email")} *</label>
|
||||
<input
|
||||
type="email"
|
||||
required
|
||||
value={form.email}
|
||||
onChange={(e) => setForm((f) => ({ ...f, email: e.target.value }))}
|
||||
placeholder={t("emailPlaceholder")}
|
||||
className="w-full px-4 py-3 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 focus:border-[#ff4d4f]"
|
||||
className="w-full rounded-xl border border-gray-200 bg-white px-4 py-3 text-gray-900 placeholder-gray-400 focus:border-[#ff4d4f] focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||
{t("titleLabel")} *
|
||||
</label>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300">{t("titleLabel")} *</label>
|
||||
<input
|
||||
type="text"
|
||||
required
|
||||
value={form.title}
|
||||
onChange={(e) => setForm((f) => ({ ...f, title: e.target.value }))}
|
||||
placeholder={t("titlePlaceholder")}
|
||||
className="w-full px-4 py-3 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 focus:border-[#ff4d4f]"
|
||||
className="w-full rounded-xl border border-gray-200 bg-white px-4 py-3 text-gray-900 placeholder-gray-400 focus:border-[#ff4d4f] focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||
{t("content")} *
|
||||
</label>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300">{t("content")} *</label>
|
||||
<textarea
|
||||
required
|
||||
rows={5}
|
||||
value={form.content}
|
||||
onChange={(e) => setForm((f) => ({ ...f, content: e.target.value }))}
|
||||
placeholder={t("contentPlaceholder")}
|
||||
className="w-full px-4 py-3 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 focus:border-[#ff4d4f] resize-none"
|
||||
className="w-full resize-none rounded-xl border border-gray-200 bg-white px-4 py-3 text-gray-900 placeholder-gray-400 focus:border-[#ff4d4f] focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-gray-400 dark:text-gray-500">
|
||||
已接入本地 FastAPI + PocketBase,提交后会写入 feedback 集合。
|
||||
</p>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full py-3.5 rounded-xl bg-[#ff4d4f] text-white font-semibold hover:bg-[#ff7a45] transition-colors"
|
||||
className="w-full rounded-xl bg-[#ff4d4f] py-3.5 font-semibold text-white transition-colors hover:bg-[#ff7a45]"
|
||||
>
|
||||
{t("submit")}
|
||||
</button>
|
||||
@@ -156,3 +161,11 @@ export default function FeedbackPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function FeedbackPage() {
|
||||
return (
|
||||
<Suspense fallback={<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950" />}>
|
||||
<FeedbackForm />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user