From 969c25b56f6d29d7ffa4bc2ce04c5fb4e5846b34 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 14 Aug 2025 11:54:47 +0000 Subject: (대표님) 정규벤더등록, 벤더문서관리, 벤더데이터입력, 첨부파일관리 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../table/safety-qualification-update-sheet.tsx | 143 +++++++++++++++++++++ .../vendor-regular-registrations-table-columns.tsx | 105 +++++++++++---- ...regular-registrations-table-toolbar-actions.tsx | 108 +++++++++------- 3 files changed, 284 insertions(+), 72 deletions(-) create mode 100644 lib/vendor-regular-registrations/table/safety-qualification-update-sheet.tsx (limited to 'lib/vendor-regular-registrations/table') diff --git a/lib/vendor-regular-registrations/table/safety-qualification-update-sheet.tsx b/lib/vendor-regular-registrations/table/safety-qualification-update-sheet.tsx new file mode 100644 index 00000000..c2aeba70 --- /dev/null +++ b/lib/vendor-regular-registrations/table/safety-qualification-update-sheet.tsx @@ -0,0 +1,143 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { z } from "zod" +import { toast } from "sonner" + +import { + Sheet, + SheetContent, + SheetDescription, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" +import { updateSafetyQualification } from "../service" + +const formSchema = z.object({ + safetyQualificationContent: z.string().min(1, "안전적격성 평가 내용을 입력해주세요."), +}) + +interface SafetyQualificationUpdateSheetProps { + open: boolean + onOpenChange: (open: boolean) => void + registrationId?: number + vendorName?: string + currentContent?: string | null + onSuccess?: () => void +} + +export function SafetyQualificationUpdateSheet({ + open, + onOpenChange, + registrationId, + vendorName, + currentContent, + onSuccess, +}: SafetyQualificationUpdateSheetProps) { + const [isLoading, setIsLoading] = React.useState(false) + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + safetyQualificationContent: currentContent || "", + }, + }) + + // 폼 값 초기화 + React.useEffect(() => { + if (open) { + form.reset({ + safetyQualificationContent: currentContent || "", + }) + } + }, [open, currentContent, form]) + + async function onSubmit(values: z.infer) { + if (!registrationId) { + toast.error("등록 ID가 없습니다.") + return + } + + setIsLoading(true) + try { + const result = await updateSafetyQualification( + registrationId, + values.safetyQualificationContent + ) + + if (result.success) { + toast.success("안전적격성 평가가 등록되었습니다.") + onOpenChange(false) + onSuccess?.() + } else { + toast.error(result.error || "안전적격성 평가 등록에 실패했습니다.") + } + } catch (error) { + console.error("안전적격성 평가 등록 오류:", error) + toast.error("안전적격성 평가 등록 중 오류가 발생했습니다.") + } finally { + setIsLoading(false) + } + } + + return ( + + + + 안전적격성 평가 입력 + + {vendorName && `${vendorName}의 `}안전적격성 평가 내용을 입력해주세요. + + + +
+ + ( + + 안전적격성 평가 내용 + +