From 53ad72732f781e6c6d5ddb3776ea47aec010af8e Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 4 Aug 2025 09:39:21 +0000 Subject: (최겸) PQ/실사 수정 및 개발 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pq/table/update-pq-sheet.tsx | 264 --------------------------------------- 1 file changed, 264 deletions(-) delete mode 100644 lib/pq/table/update-pq-sheet.tsx (limited to 'lib/pq/table/update-pq-sheet.tsx') diff --git a/lib/pq/table/update-pq-sheet.tsx b/lib/pq/table/update-pq-sheet.tsx deleted file mode 100644 index 4da3c264..00000000 --- a/lib/pq/table/update-pq-sheet.tsx +++ /dev/null @@ -1,264 +0,0 @@ -"use client" - -import * as React from "react" -import { zodResolver } from "@hookform/resolvers/zod" -import { Loader, Save } from "lucide-react" -import { useForm } from "react-hook-form" -import { toast } from "sonner" -import { z } from "zod" -import { useRouter } from "next/navigation" - -import { Button } from "@/components/ui/button" -import { - Form, - FormControl, - FormDescription, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form" -import { - Select, - SelectContent, - SelectGroup, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select" -import { - Sheet, - SheetClose, - SheetContent, - SheetDescription, - SheetFooter, - SheetHeader, - SheetTitle, -} from "@/components/ui/sheet" -import { Input } from "@/components/ui/input" -import { Textarea } from "@/components/ui/textarea" - -import { modifyPq } from "../service" -import { groupOptions } from "./add-pq-dialog" - -// PQ 수정을 위한 Zod 스키마 정의 -const updatePqSchema = z.object({ - code: z.string().min(1, "Code is required"), - checkPoint: z.string().min(1, "Check point is required"), - groupName: z.string().min(1, "Group is required"), - description: z.string().optional(), - remarks: z.string().optional() -}); - -type UpdatePqSchema = z.infer; - -interface UpdatePqSheetProps - extends React.ComponentPropsWithRef { - pq: { - id: number; - code: string; - checkPoint: string; - description: string | null; - remarks: string | null; - groupName: string | null; - } | null -} - -export function UpdatePqSheet({ pq, ...props }: UpdatePqSheetProps) { - const [isUpdatePending, startUpdateTransition] = React.useTransition() - const router = useRouter() - - const form = useForm({ - resolver: zodResolver(updatePqSchema), - defaultValues: { - code: pq?.code ?? "", - checkPoint: pq?.checkPoint ?? "", - groupName: pq?.groupName ?? groupOptions[0], - description: pq?.description ?? "", - remarks: pq?.remarks ?? "", - }, - }) - - // 폼 초기화 (pq가 변경될 때) - React.useEffect(() => { - if (pq) { - form.reset({ - code: pq.code, - checkPoint: pq.checkPoint, - groupName: pq.groupName ?? groupOptions[0], - description: pq.description ?? "", - remarks: pq.remarks ?? "", - }); - } - }, [pq, form]); - - function onSubmit(input: UpdatePqSchema) { - startUpdateTransition(async () => { - if (!pq) return - - const result = await modifyPq({ - id: pq.id, - ...input, - }) - - if (!result.success && 'error' in result) { - toast.error(result.error) - } else { - toast.error("Failed to update PQ criteria") - } - - form.reset() - props.onOpenChange?.(false) - toast.success("PQ criteria updated successfully") - router.refresh() - }) - } - return ( - - - - Update PQ Criteria - - Update the PQ criteria details and save the changes - - -
- - {/* Code 필드 */} - ( - - Code * - - - - - - )} - /> - - {/* Check Point 필드 */} - ( - - Check Point * - - - - - - )} - /> - - {/* Group Name 필드 (Select) */} - ( - - Group * - - - - )} - /> - - {/* Description 필드 */} - ( - - Description - -