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/add-pq-dialog.tsx | 454 ----------------------------------------- 1 file changed, 454 deletions(-) delete mode 100644 lib/pq/table/add-pq-dialog.tsx (limited to 'lib/pq/table/add-pq-dialog.tsx') diff --git a/lib/pq/table/add-pq-dialog.tsx b/lib/pq/table/add-pq-dialog.tsx deleted file mode 100644 index 2fac9e43..00000000 --- a/lib/pq/table/add-pq-dialog.tsx +++ /dev/null @@ -1,454 +0,0 @@ -"use client" - -import * as React from "react" -import { useForm } from "react-hook-form" -import { zodResolver } from "@hookform/resolvers/zod" -import { z } from "zod" -import { Plus } from "lucide-react" -import { useRouter } from "next/navigation" - -import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog" -import { Button } from "@/components/ui/button" -import { Input } from "@/components/ui/input" -import { Textarea } from "@/components/ui/textarea" -import { - Form, - FormControl, - FormDescription, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form" -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select" -import { Checkbox } from "@/components/ui/checkbox" -import { useToast } from "@/hooks/use-toast" -import { createPq, invalidatePqCache } from "../service" -import { ProjectSelector } from "@/components/ProjectSelector" -import { type Project } from "@/lib/rfqs/service" -import { ScrollArea } from "@/components/ui/scroll-area" - -// PQ 생성을 위한 Zod 스키마 정의 -const createPqSchema = 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(), - // 프로젝트별 PQ 여부 체크박스 - isProjectSpecific: z.boolean().default(false), - // 프로젝트 관련 추가 필드는 isProjectSpecific가 true일 때만 필수 - contractInfo: z.string().optional(), - additionalRequirement: z.string().optional(), -}); - -type CreatePqFormType = z.infer; - -// 그룹 이름 옵션 -export const groupOptions = [ - "GENERAL", - "Quality Management System", - "Workshop & Environment", - "Warranty", -]; - -// 설명 예시 텍스트 -const descriptionExample = `Address : -Tel. / Fax : -e-mail :`; - -interface AddPqDialogProps { - currentProjectId?: number | null; // 현재 선택된 프로젝트 ID (옵션) -} - -export function AddPqDialog({ currentProjectId }: AddPqDialogProps) { - const [open, setOpen] = React.useState(false) - const [isSubmitting, setIsSubmitting] = React.useState(false) - const [selectedProject, setSelectedProject] = React.useState(null) - const router = useRouter() - const { toast } = useToast() - - // react-hook-form 설정 - const form = useForm({ - resolver: zodResolver(createPqSchema), - defaultValues: { - code: "", - checkPoint: "", - groupName: groupOptions[0], - description: "", - remarks: "", - isProjectSpecific: !!currentProjectId, // 현재 프로젝트 ID가 있으면 기본값 true - contractInfo: "", - additionalRequirement: "", - }, - }) - - // 프로젝트별 PQ 여부 상태 감시 - const isProjectSpecific = form.watch("isProjectSpecific") - - // 현재 프로젝트 ID가 있으면 선택된 프로젝트 설정 - React.useEffect(() => { - if (currentProjectId) { - form.setValue("isProjectSpecific", true) - } - }, [currentProjectId, form]) - - // 예시 텍스트를 description 필드에 채우는 함수 - const fillExampleText = () => { - form.setValue("description", descriptionExample); - }; - - async function onSubmit(data: CreatePqFormType) { - try { - setIsSubmitting(true) - - // 서버 액션 호출용 데이터 준비 - const submitData = { - ...data, - projectId: data.isProjectSpecific ? selectedProject?.id || currentProjectId : null, - } - - // 프로젝트별 PQ인데 프로젝트가 선택되지 않은 경우 검증 - if (data.isProjectSpecific && !submitData.projectId) { - toast({ - title: "Error", - description: "Please select a project", - variant: "destructive", - }) - setIsSubmitting(false) - return - } - - // 서버 액션 호출 - const result = await createPq(submitData) - - if (!result.success) { - toast({ - title: "Error", - description: result.message || "Failed to create PQ criteria", - variant: "destructive", - }) - return - } - - await invalidatePqCache(); - - // 성공 시 처리 - toast({ - title: "Success", - description: result.message || "PQ criteria created successfully", - }) - - // 모달 닫고 폼 리셋 - form.reset() - setSelectedProject(null) - setOpen(false) - - // 페이지 새로고침 - router.refresh() - - } catch (error) { - console.error('Error creating PQ criteria:', error) - toast({ - title: "Error", - description: "An unexpected error occurred", - variant: "destructive", - }) - } finally { - setIsSubmitting(false) - } - } - - function handleDialogOpenChange(nextOpen: boolean) { - if (!nextOpen) { - form.reset() - setSelectedProject(null) - } - setOpen(nextOpen) - } - - // 프로젝트 선택 핸들러 - const handleProjectSelect = (project: Project | null) => { - // project가 null인 경우 선택 해제를 의미 - if (project === null) { - setSelectedProject(null); - // 필요한 경우 추가 처리 - return; - } - - // 기존 처리 - 프로젝트가 선택된 경우 - setSelectedProject(project); - } - - return ( - - {/* 모달을 열기 위한 버튼 */} - - - - - - - Create New PQ Criteria - - 새 PQ 기준 정보를 입력하고 Create 버튼을 누르세요. - - - - {/* shadcn/ui Form을 이용해 react-hook-form과 연결 */} -
- - {/* 프로젝트별 PQ 여부 체크박스 */} - -
- ( - - - - -
- 프로젝트별 PQ 생성 - - 특정 프로젝트에만 적용되는 PQ 항목을 생성합니다 - -
-
- )} - /> - - {/* 프로젝트 선택 필드 (프로젝트별 PQ 선택 시에만 표시) */} - {isProjectSpecific && ( -
- Project * - - - PQ 항목을 적용할 프로젝트를 선택하세요 - -
- )} - -
- - - {/* Code 필드 */} - ( - - Code * - - - - - PQ 항목의 고유 코드를 입력하세요 (예: "1-1", "A.2.3") - - - - )} - /> - - {/* Check Point 필드 */} - ( - - Check Point * - - - - - - )} - /> - - {/* Group Name 필드 (Select) */} - ( - - Group * - - - PQ 항목의 분류 그룹을 선택하세요 - - - - )} - /> - - {/* Description 필드 - 예시 템플릿 버튼 추가 */} - ( - -
- Description - -
- -