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/pq-review-table-new/send-results-dialog.tsx | 279 ++++++++++++++++----- 1 file changed, 211 insertions(+), 68 deletions(-) (limited to 'lib/pq/pq-review-table-new/send-results-dialog.tsx') diff --git a/lib/pq/pq-review-table-new/send-results-dialog.tsx b/lib/pq/pq-review-table-new/send-results-dialog.tsx index 0a423f7f..3c8614cc 100644 --- a/lib/pq/pq-review-table-new/send-results-dialog.tsx +++ b/lib/pq/pq-review-table-new/send-results-dialog.tsx @@ -1,69 +1,212 @@ -"use client" - -import * as React from "react" - -import { Button } from "@/components/ui/button" -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog" - -interface SendResultsDialogProps { - isOpen: boolean - onClose: () => void - onConfirm: () => Promise - selectedCount: number -} - -export function SendResultsDialog({ - isOpen, - onClose, - onConfirm, - selectedCount, -}: SendResultsDialogProps) { - const [isPending, setIsPending] = React.useState(false) - - async function handleConfirm() { - setIsPending(true) - try { - await onConfirm() - } finally { - setIsPending(false) - } - } - - return ( - !open && onClose()}> - - - 실사 결과 발송 - - 선택한 {selectedCount}개 협력업체의 실사 결과를 발송하시겠습니까? - 완료된 실사만 결과를 발송할 수 있습니다. - - - - - - - - - ) +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import * as z from "zod" + + +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { Textarea } from "@/components/ui/textarea" +import { Badge } from "@/components/ui/badge" +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" +import { Separator } from "@/components/ui/separator" + +// 실사 결과 발송을 위한 스키마 +const sendResultsSchema = z.object({ + purchaseComment: z.string().optional(), +}) + +type SendResultsFormValues = z.infer + +interface AuditResult { + id: number + vendorCode: string + vendorName: string + vendorEmail: string + vendorContactPerson: string + pqNumber: string + auditItem: string + auditFactoryAddress: string + auditMethod: string + auditResult: string + additionalNotes?: string + investigationNotes?: string +} + +interface SendResultsDialogProps { + isOpen: boolean + onClose: () => void + onConfirm: (data: SendResultsFormValues) => Promise + selectedCount: number + auditResults: AuditResult[] +} + +export function SendResultsDialog({ + isOpen, + onClose, + onConfirm, + selectedCount, + auditResults, +}: SendResultsDialogProps) { + const [isPending, setIsPending] = React.useState(false) + + const form = useForm({ + resolver: zodResolver(sendResultsSchema), + defaultValues: { + purchaseComment: "", + }, + }) + + async function handleSubmit(data: SendResultsFormValues) { + setIsPending(true) + try { + await onConfirm(data) + } finally { + setIsPending(false) + } + } + + const getResultBadgeVariant = (result: string) => { + if (result.includes("Pass")) return "default" + if (result.includes("Fail")) return "destructive" + return "secondary" + } + + return ( + !open && onClose()}> + + + 실사 결과 발송 + + 선택한 {selectedCount}개 협력업체의 실사 결과를 발송하시겠습니까? + 완료된 실사만 결과를 발송할 수 있습니다. + + + +
+ {/* 실사 결과 미리보기 */} +
+

실사 결과 미리보기

+
+ {auditResults.map((result) => ( + + + + {result.vendorName} ({result.vendorCode}) + + {result.auditResult} + + + + +
+
+
PQ No.
+
{result.pqNumber}
+
+
+
Vendor
+
{result.vendorCode} | {result.vendorName}
+
+
+
수신자
+
{result.vendorContactPerson} ({result.vendorEmail})
+
+
+
실사품목
+
{result.auditItem}
+
+
+
실사공장주소
+
{result.auditFactoryAddress}
+
+
+
QM 실사방법
+
{result.auditMethod}
+
+
+
실사결과
+
+ + {result.auditResult} + +
+
+ {result.investigationNotes && ( +
+
실사합격조건
+
{result.investigationNotes}
+
+ )} +
+
+
+ ))} +
+
+ + + + {/* 추가 Comment 입력 */} +
+ + ( + + + 추가 Comment (선택사항) + + +