refactor: fix ai slop

This commit is contained in:
2026-07-31 22:22:33 +07:00 Unverified
parent 8de32bcb3f
commit 255b895112
8 changed files with 214 additions and 74 deletions
+2 -2
View File
@@ -42,7 +42,7 @@ export default function NotFound() {
<h2 className="text-2xl font-semibold">404 ไม่พบหน้านี้</h2>
<span>{message}</span>
<div className="flex gap-2">
<Link href="/">
<Link href="/form">
<Button
onClick={() => {
goHome(true);
@@ -51,7 +51,7 @@ export default function NotFound() {
variant="destructive"
>
{goingHome ? <Spinner /> : <Home />}
กลับหน้าแรก
กลับหน้าเลือก
</Button>
</Link>
<Link href="https://status.sudloh.com">
+22 -30
View File
@@ -55,6 +55,7 @@ import {
decodeCheckboxAnswer,
type FormAnswerValue,
} from "@/lib/form-answer-values";
import { isImageOnlyResponse } from "@/lib/question-response-type";
export function FormLayoutClient({
userName,
@@ -148,14 +149,6 @@ const buildSchema = (questions: Question[]) => {
return z.object(shape);
};
function isImageOnlyQuestion(question: Question) {
return (
question.imageAnswerMode === "required" &&
!question.required &&
(question.type === "text" || question.type === "textarea")
);
}
function prepareInitialState(
questions: Question[],
answers: Record<string, AnswerDraft | undefined>,
@@ -445,6 +438,7 @@ export function FormFillerClient({
const formData = new FormData();
formData.append("file", file);
setUploadingAnswerId(questionId);
const uploadToastId = toast.loading("กำลังอัปโหลดรูป");
try {
const response = await fetch("/api/upload", {
@@ -457,9 +451,11 @@ export function FormFillerClient({
}
setImageAnswers((current) => ({ ...current, [questionId]: data.id }));
setImageErrors((current) => ({ ...current, [questionId]: null }));
toast.success("อัปโหลดรูปแล้ว");
toast.success("อัปโหลดรูปแล้ว", { id: uploadToastId });
} catch (error) {
toast.error(getErrorMessage(error, "ไม่สามารถอัปโหลดรูปได้"));
toast.error(getErrorMessage(error, "ไม่สามารถอัปโหลดรูปได้"), {
id: uploadToastId,
});
} finally {
setUploadingAnswerId(null);
}
@@ -576,7 +572,7 @@ export function FormFillerClient({
<span>{questions.length} คำถาม</span>
<span>{totalAnswers} คำตอบทั้งหมด</span>
{queueNumber !== null && (
<Badge variant="outline">ลำดับของคุณ #{queueNumber}</Badge>
<Badge variant="outline">ลำดับของคุณ #{queueNumber + 1}</Badge>
)}
</CardDescription>
</CardHeader>
@@ -597,9 +593,11 @@ export function FormFillerClient({
</CardContent>
)}
<CardFooter className="flex-wrap gap-2 border-t">
{questions.some((question) => question.required) && (
{questions.some(
(question) => question.required || question.imageAnswerMode === "required",
) && (
<span className="text-sm text-muted-foreground">
ช่องที่มีป้าย “จำเป็น” ต้องตอบให้ครบ
คำถามที่มี “จำเป็น” ต้องตอบให้ครบ
</span>
)}
{!isAcceptingSubmissions && (
@@ -665,10 +663,10 @@ export function FormFillerClient({
control={control}
name={q.id}
render={({ field, fieldState }) => (
<Card className="shadow-sm">
<Card>
<CardHeader>
<CardDescription>
ข้อ {questionIndex + 1} จาก {questions.length}
ข้อที่ {questionIndex + 1}
</CardDescription>
<div className="flex items-start justify-between gap-4">
<CardTitle
@@ -678,7 +676,7 @@ export function FormFillerClient({
<HtmlDisplay html={q.label} />
</CardTitle>
<div className="flex shrink-0 items-start gap-2">
{q.required && (
{(q.required || q.imageAnswerMode === "required") && (
<Badge variant="destructive">จำเป็น</Badge>
)}
{q.imageUrl && (
@@ -721,7 +719,7 @@ export function FormFillerClient({
</CardHeader>
<CardContent>
<FormItem>
{q.type === "text" && !isImageOnlyQuestion(q) && (
{q.type === "text" && !isImageOnlyResponse(q) && (
<Field data-invalid={fieldState.invalid || undefined}>
<FormControl
aria-describedby={
@@ -741,7 +739,7 @@ export function FormFillerClient({
</Field>
)}
{q.type === "textarea" && !isImageOnlyQuestion(q) && (
{q.type === "textarea" && !isImageOnlyResponse(q) && (
<Field data-invalid={fieldState.invalid || undefined}>
<FormControl
aria-describedby={
@@ -762,7 +760,7 @@ export function FormFillerClient({
</Field>
)}
{q.type === "radio" && q.options && (
{q.type === "radio" && q.options && !isImageOnlyResponse(q) && (
<FieldSet data-invalid={fieldState.invalid || undefined}>
<FieldLegend className="sr-only">
{plainQuestionLabel}
@@ -843,7 +841,7 @@ export function FormFillerClient({
</FieldSet>
)}
{q.type === "checkbox" && q.options && (
{q.type === "checkbox" && q.options && !isImageOnlyResponse(q) && (
<FieldSet data-invalid={fieldState.invalid || undefined}>
<FieldLegend className="sr-only">
{plainQuestionLabel}
@@ -984,12 +982,6 @@ export function FormFillerClient({
: undefined
}
/>
{uploadingAnswerId === q.id && (
<Badge variant="secondary">
<Spinner data-icon="inline-start" />
กำลังอัปโหลด
</Badge>
)}
{imageAnswers[q.id] && (
<Dialog>
<DialogTrigger asChild>
@@ -1016,7 +1008,7 @@ export function FormFillerClient({
{imageAnswers[q.id] && (
<Button
type="button"
variant="ghost"
variant="destructive"
onClick={() => clearAnswerImage(q.id)}
disabled={!isAcceptingSubmissions || isSubmitting}
>
@@ -1121,12 +1113,12 @@ export function FormFillerClient({
<AlertDialog open={showSuccessDialog} onOpenChange={setShowSuccessDialog}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle className="text-center text-2xl font-bold">
<AlertDialogTitle className="text-2xl">
ส่งคำตอบแล้ว
</AlertDialogTitle>
<AlertDialogDescription>
บันทึกคำตอบของคุณเรียบร้อย คุณอยู่ในคิวที่ #{queueNumber} จากทั้งหมด{" "}
{totalAnswers} คำตอบ และกลับมาแก้ไขได้ตราบใดที่แบบฟอร์มยังเปิดอยู่
บันทึกคำตอบของคุณเรียบร้อย คำตอบของคุณอยู่ลำดับที่ #{(queueNumber ?? 0) + 1} จากทั้งหมด{" "}
{totalAnswers} คำตอบ คุณสามารถแก้ไขได้คำตอบตอนไหนก็ได้ที่แบบฟอร์มยังเปิดอยู่
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>