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/copy-pq-list-dialog.tsx | 244 +++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 lib/pq/table/copy-pq-list-dialog.tsx (limited to 'lib/pq/table/copy-pq-list-dialog.tsx') diff --git a/lib/pq/table/copy-pq-list-dialog.tsx b/lib/pq/table/copy-pq-list-dialog.tsx new file mode 100644 index 00000000..647ab1a3 --- /dev/null +++ b/lib/pq/table/copy-pq-list-dialog.tsx @@ -0,0 +1,244 @@ +"use client" + +// import { useState } from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { z } from "zod" +import { Button } from "@/components/ui/button" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog" +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" +import { DatePicker } from "@/components/ui/date-picker" +import { Loader2, Copy } from "lucide-react" +import { Badge } from "@/components/ui/badge" +import { Input } from "@/components/ui/input" +// import { Card, CardContent } from "@/components/ui/card" + +interface PQList { + id: number + name: string + type: "GENERAL" | "PROJECT" | "NON_INSPECTION" + projectId?: number | null + criteriaCount?: number + createdAt: Date +} + +interface Project { + id: number + name: string + code: string +} + +const copyPqSchema = z.object({ + sourcePqListId: z.number({ + required_error: "복사할 PQ 목록을 선택해주세요" + }), + targetProjectId: z.number({ + required_error: "대상 프로젝트를 선택해주세요" + }), + validTo: z.date(), + newName: z.string(), +}) + +type CopyPqFormData = z.infer + +interface CopyPqDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + pqLists: PQList[] + projects: Project[] + onCopy: (data: CopyPqFormData) => Promise + isLoading?: boolean +} + +const typeLabels = { + GENERAL: "일반 PQ", + PROJECT: "프로젝트 PQ", + NON_INSPECTION: "미실사 PQ" +} + +const typeColors = { + GENERAL: "bg-blue-100 text-blue-800", + PROJECT: "bg-green-100 text-green-800", + NON_INSPECTION: "bg-orange-100 text-orange-800" +} + +export function CopyPqDialog({ + open, + onOpenChange, + pqLists, + projects, + onCopy, + isLoading = false +}: CopyPqDialogProps) { + const form = useForm({ + resolver: zodResolver(copyPqSchema), + }) + const formState = form.formState + + const selectedSourceId = form.watch("sourcePqListId") + const selectedPqList = pqLists.find(list => list.id === selectedSourceId) + + const handleSubmit = async (data: CopyPqFormData) => { + try { + await onCopy(data) + form.reset() + onOpenChange(false) + } catch (error) { + // 에러는 상위 컴포넌트에서 처리 + console.error("Failed to copy PQ list:", error) + } + } + + return ( + + + + + + PQ 목록 불러오기 + + + 기존 PQ 목록을 선택하여 새로운 프로젝트 PQ를 생성합니다. + 선택한 PQ의 모든 항목이 새 프로젝트로 복사됩니다. + + + +
+ + {/* 대상 프로젝트 선택 */} + ( + + + 대상 프로젝트 * + + + + + )} + /> + {/* 복사할 PQ 목록 선택 */} + ( + + + 복사할 PQ 리스트 * + + + {selectedPqList && ( +
+ 선택된 PQ 리스트: {selectedPqList.name} + {selectedPqList.criteriaCount && ( + ({selectedPqList.criteriaCount}개 항목) + )} +
+ )} + +
+ )} + /> + {/* 새 PQ 목록 명 */} + ( + + + 새 PQ 리스트명 * + + + + + + + )} + /> + {/* 유효기간 설정 */} + ( + + + 유효기간 * + + + field.onChange(date ?? null)} + placeholder="유효기간 선택" + /> + + + + )} + /> + + {/* 버튼들 */} +
+ + +
+ + +
+
+ ) +} \ No newline at end of file -- cgit v1.2.3