From c7e431d99eb035888a13cd44c0df58ac1c3a45d4 Mon Sep 17 00:00:00 2001 From: gunshiz Date: Sat, 20 Jun 2026 19:53:51 +0700 Subject: [PATCH] refactor: move AdminSidebar component to client file and update form layout and submission date formatting --- app/form/admin/client.tsx | 81 ++++++++++++++- app/form/admin/layout.tsx | 10 +- app/form/admin/result/[id]/client.tsx | 4 +- app/form/client.tsx | 140 +++++++++----------------- app/form/layout.tsx | 8 +- components/admin-sidebar.tsx | 81 --------------- 6 files changed, 136 insertions(+), 188 deletions(-) delete mode 100644 components/admin-sidebar.tsx diff --git a/app/form/admin/client.tsx b/app/form/admin/client.tsx index 2c9ad20..5d89a8c 100644 --- a/app/form/admin/client.tsx +++ b/app/form/admin/client.tsx @@ -1,7 +1,8 @@ "use client"; import React, { useState, useTransition, useRef, useCallback, useEffect } from "react"; -import { useRouter } from "next/navigation"; +import { useRouter, usePathname } from "next/navigation"; +import Link from "next/link"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -18,10 +19,21 @@ import { createQuestion, updateQuestion, deleteQuestion, - reorderQuestions, bulkUpdateQuestions, } from "@/app/actions/questions"; -import { Plus, Trash, ArrowUp, ArrowDown, Loader2, Save, Image as ImageIcon, X, Check } from "lucide-react"; +import { + Sidebar, + SidebarContent, + SidebarGroup, + SidebarGroupContent, + SidebarGroupLabel, + SidebarMenu, + SidebarMenuButton, + SidebarMenuItem, + SidebarHeader, + SidebarFooter, +} from "@/components/ui/sidebar"; +import { Plus, Trash, ArrowUp, ArrowDown, Loader2, Save, Image as ImageIcon, X, Check, LayoutDashboard, ClipboardList, ArrowLeft, Webhook } from "lucide-react"; import Image from 'next/image'; import { RichTextEditor } from "@/components/rich-text-editor"; import { FormattedText } from "@/components/formatted-text"; @@ -596,3 +608,66 @@ function AnswerPreview({ question }: { question: Question }) { ); } + +export function AdminSidebar() { + const pathname = usePathname(); + + return ( + + + + Form admin + + + + + + Navigation + + + + + + + Dashboard + + + + + + + + + Response + + + + + + + + + Extra + + + + + + + + + + + + + + + Go public + + + + + + + ); +} diff --git a/app/form/admin/layout.tsx b/app/form/admin/layout.tsx index 98768f4..270c643 100644 --- a/app/form/admin/layout.tsx +++ b/app/form/admin/layout.tsx @@ -1,8 +1,8 @@ -import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"; -import { AdminSidebar } from "@/components/admin-sidebar"; import { getServerSession } from "next-auth"; import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { redirect } from "next/navigation"; +import { SidebarProvider } from "@/components/ui/sidebar"; +import { AdminSidebar } from "./client"; export default async function AdminLayout({ children, @@ -22,11 +22,11 @@ export default async function AdminLayout({ return ( -
+
-
+
{children} -
+
); diff --git a/app/form/admin/result/[id]/client.tsx b/app/form/admin/result/[id]/client.tsx index 7e8c1d9..553ccb8 100644 --- a/app/form/admin/result/[id]/client.tsx +++ b/app/form/admin/result/[id]/client.tsx @@ -77,14 +77,14 @@ export default function SubmissionDetailClient({
Initial Submission: - {new Date(submission.submittedAt).toLocaleString()} + {new Date(submission.submittedAt).toLocaleString(undefined, { hour12: false })}
{editHistory.length > 0 && (
Edit History:
diff --git a/app/form/client.tsx b/app/form/client.tsx index deda920..c7fe5af 100644 --- a/app/form/client.tsx +++ b/app/form/client.tsx @@ -16,7 +16,7 @@ import { Dialog, DialogContent, DialogTrigger, DialogTitle } from "@/components/ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"; import { toast } from "sonner"; import { submitForm, deleteOwnSubmission } from "@/app/actions/submissions"; -import { Loader2, LogOut, ChevronRight, ChevronLeft } from "lucide-react"; +import { Loader2, LogOut } from "lucide-react"; import { signOut } from "next-auth/react"; import Image from "next/image"; import { z } from "zod"; @@ -87,7 +87,6 @@ interface FormFillerClientProps { } const LS_KEY = (formId: string) => `form-draft-${formId}`; -const QUESTIONS_PER_STEP = 3; const buildSchema = (questions: Question[]) => { const shape: Record = {}; @@ -177,27 +176,7 @@ export function FormFillerClient({ form, questions, initialAnswers = {} }: FormF return () => subscription.unsubscribe(); }, [watch, form.id]); - const [currentStep, setCurrentStep] = useState(0); - const totalSteps = Math.ceil(questions.length / QUESTIONS_PER_STEP); - - const currentQuestions = questions.slice( - currentStep * QUESTIONS_PER_STEP, - (currentStep + 1) * QUESTIONS_PER_STEP - ); - const nextStep = async () => { - const fieldsToValidate = currentQuestions.map(q => q.id); - const isStepValid = await trigger(fieldsToValidate); - if (isStepValid) { - setCurrentStep(prev => Math.min(prev + 1, totalSteps - 1)); - window.scrollTo(0, 0); - } - }; - - const prevStep = () => { - setCurrentStep(prev => Math.max(prev - 1, 0)); - window.scrollTo(0, 0); - }; const onSubmit = async (values: z.infer) => { if (!form.isOpen) return; @@ -276,7 +255,7 @@ export function FormFillerClient({ form, questions, initialAnswers = {} }: FormF
- {currentQuestions.map((q) => ( + {questions.map((q) => (
@@ -453,82 +432,55 @@ export function FormFillerClient({ form, questions, initialAnswers = {} }: FormF ))}
-
-
- หน้า {currentStep + 1} จาก {totalSteps || 1} -
- -
- {currentStep > 0 && ( - - )} - - {currentStep < totalSteps - 1 ? ( - - ) : ( -
- {isUpdating && ( - - - - - - - ยืนยันการลบข้อมูล? - - คุณแน่ใจหรือไม่ว่าต้องการลบข้อมูลที่ส่งไปแล้ว? การกระทำนี้ไม่สามารถย้อนกลับได้ - - - - ยกเลิก - - ยืนยันการลบ - - - - - )} - -
+ + + + ยืนยันการลบข้อมูล? + + คุณแน่ใจหรือไม่ว่าต้องการลบข้อมูลที่ส่งไปแล้ว? การกระทำนี้ไม่สามารถย้อนกลับได้ + + + + ยกเลิก + + ยืนยันการลบ + + + + + )} +
+
); } + + diff --git a/app/form/layout.tsx b/app/form/layout.tsx index 50d5d95..cc8c7a0 100644 --- a/app/form/layout.tsx +++ b/app/form/layout.tsx @@ -19,8 +19,8 @@ export default async function FormLayout({ const session = await getServerSession(authOptions); return ( -
-
+
+
ฟอร์ม @@ -31,7 +31,9 @@ export default async function FormLayout({ /> )}
-
{children}
+
+ {children} +
{!session && }
); diff --git a/components/admin-sidebar.tsx b/components/admin-sidebar.tsx deleted file mode 100644 index 3c3792b..0000000 --- a/components/admin-sidebar.tsx +++ /dev/null @@ -1,81 +0,0 @@ -"use client"; - -import * as React from "react"; -import Link from "next/link"; -import { usePathname } from "next/navigation"; -import { - Sidebar, - SidebarContent, - SidebarGroup, - SidebarGroupContent, - SidebarGroupLabel, - SidebarMenu, - SidebarMenuButton, - SidebarMenuItem, - SidebarHeader, - SidebarFooter, -} from "@/components/ui/sidebar"; -import { LayoutDashboard, ClipboardList, ArrowLeft, Webhook } from "lucide-react"; - -export function AdminSidebar() { - const pathname = usePathname(); - - return ( - - - - Erika Admin - - - - - - Navigation - - - - - - - Dashboard - - - - - - - - - Response - - - - - - - - - Extra - - - - - - - - - - - - - - - Go public - - - - - - - ); -}