From 95bbe9c583ff841220da1267630e7b2025fc36dc Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Thu, 19 Jun 2025 09:44:28 +0000
Subject: (대표님) 20250619 1844 KST 작업사항
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../table/update-check-list-sheet.tsx              | 162 +++++++++++++++++++++
 1 file changed, 162 insertions(+)
 create mode 100644 lib/general-check-list/table/update-check-list-sheet.tsx

(limited to 'lib/general-check-list/table/update-check-list-sheet.tsx')

diff --git a/lib/general-check-list/table/update-check-list-sheet.tsx b/lib/general-check-list/table/update-check-list-sheet.tsx
new file mode 100644
index 00000000..6c845465
--- /dev/null
+++ b/lib/general-check-list/table/update-check-list-sheet.tsx
@@ -0,0 +1,162 @@
+"use client";
+
+import * as React from "react";
+import { z } from "zod";
+import { useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { toast } from "sonner";
+import {
+  Sheet,             // ⬅️ Drawer 대신 Sheet
+  SheetContent,
+  SheetHeader,
+  SheetTitle,
+  SheetFooter,
+  SheetClose,
+} from "@/components/ui/sheet";
+import { Button } from "@/components/ui/button";
+import {
+  Form, FormField, FormItem, FormLabel,
+  FormControl, FormMessage,
+} from "@/components/ui/form";
+import { Input } from "@/components/ui/input";
+import { updateGeneralEvaluation } from "@/lib/general-check-list/service";
+import { useRouter } from "next/navigation";
+
+const schema = z.object({
+  category: z.string(),
+  inspectionItem: z.string(),
+  remarks: z.string().optional(),
+  isActive: z.boolean().optional(),
+});
+
+type Values = z.infer<typeof schema>;
+
+export function EditEvaluationSheet({
+  open,
+  onOpenChange,
+  evaluation,
+  onSuccess,
+}: {
+  open: boolean;
+  onOpenChange: (v: boolean) => void;
+  evaluation: any;
+  onSuccess?: () => void;
+}) {
+  const [pending, setPending] = React.useState(false);
+  const router = useRouter();          // ⬅️
+
+  const form = useForm<Values>({
+    resolver: zodResolver(schema),
+    defaultValues: {
+      category: evaluation.category,
+      inspectionItem: evaluation.inspectionItem,
+      remarks: evaluation.remarks ?? "",
+      isActive: evaluation.isActive,
+    },
+  });
+
+  async function onSubmit(values: Values) {
+    setPending(true);
+    const res = await updateGeneralEvaluation(evaluation.id, values);
+    setPending(false);
+
+    if (res.success) {
+      toast.success(res.message);
+      router.refresh(); 
+      
+      onSuccess?.();
+      onOpenChange(false);
+    } else {
+      toast.error(res.message);
+    }
+  }
+
+  return (
+    <Sheet open={open} onOpenChange={(v) => !pending && onOpenChange(v)}>
+      <SheetContent className="flex flex-col gap-6 sm:max-w-lg">
+        <SheetHeader>
+          <SheetTitle>항목 수정 – {evaluation.serialNumber}</SheetTitle>
+        </SheetHeader>
+
+        <Form {...form}>
+          <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4 py-4">
+            {/* 카테고리 */}
+            <FormField
+              control={form.control}
+              name="category"
+              render={({ field }) => (
+                <FormItem>
+                  <FormLabel>카테고리</FormLabel>
+                  <FormControl>
+                    <Input {...field} disabled={pending} />
+                  </FormControl>
+                  <FormMessage />
+                </FormItem>
+              )}
+            />
+
+            {/* 점검 항목 */}
+            <FormField
+              control={form.control}
+              name="inspectionItem"
+              render={({ field }) => (
+                <FormItem>
+                  <FormLabel>점검 항목</FormLabel>
+                  <FormControl>
+                    <Input {...field} disabled={pending} />
+                  </FormControl>
+                  <FormMessage />
+                </FormItem>
+              )}
+            />
+
+            {/* 비고 */}
+            <FormField
+              control={form.control}
+              name="remarks"
+              render={({ field }) => (
+                <FormItem>
+                  <FormLabel>비고</FormLabel>
+                  <FormControl>
+                    <Input {...field} disabled={pending} />
+                  </FormControl>
+                  <FormMessage />
+                </FormItem>
+              )}
+            />
+
+            {/* 활성 체크 */}
+            <FormField
+              control={form.control}
+              name="isActive"
+              render={({ field }) => (
+                <FormItem className="flex items-center gap-2">
+                  <FormLabel className="m-0">활성</FormLabel>
+                  <FormControl>
+                    <input
+                      type="checkbox"
+                      checked={field.value}
+                      onChange={(e) => field.onChange(e.target.checked)}
+                      disabled={pending}
+                    />
+                  </FormControl>
+                </FormItem>
+              )}
+            />
+
+            <SheetFooter className="pt-4">
+              <SheetClose asChild>
+                <Button variant="outline" disabled={pending}>
+                  취소
+                </Button>
+              </SheetClose>
+              <Button type="submit" disabled={pending}>
+                {pending ? "저장중..." : "저장"}
+              </Button>
+            </SheetFooter>
+          </form>
+        </Form>
+      </SheetContent>
+    </Sheet>
+  );
+}
-- 
cgit v1.2.3

