From 969c25b56f6d29d7ffa4bc2ce04c5fb4e5846b34 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
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

---
 ...regular-registrations-table-toolbar-actions.tsx | 108 +++++++++++----------
 1 file changed, 59 insertions(+), 49 deletions(-)

(limited to 'lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx')

diff --git a/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx b/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx
index c3b4739a..3a1216f2 100644
--- a/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx
+++ b/lib/vendor-regular-registrations/table/vendor-regular-registrations-table-toolbar-actions.tsx
@@ -2,18 +2,20 @@
 
 import { type Table } from "@tanstack/react-table"
 import { toast } from "sonner"
+import { useRouter } from "next/navigation"
 
 import { Button } from "@/components/ui/button"
-import { FileText, RefreshCw, Download, Mail, FileWarning, Scale, Shield } from "lucide-react"
+import { Mail, FileWarning, Scale, FileText } from "lucide-react"
 import type { VendorRegularRegistration } from "@/config/vendorRegularRegistrationsColumnsConfig"
 import { 
   sendMissingContractRequestEmails,
   sendAdditionalInfoRequestEmails,
   skipLegalReview,
-  skipSafetyQualification
+  submitRegistrationRequest
 } from "../service"
 import { useState } from "react"
 import { SkipReasonDialog } from "@/components/vendor-regular-registrations/skip-reason-dialog"
+import { RegistrationRequestDialog } from "@/components/vendor-regular-registrations/registration-request-dialog"
 
 interface VendorRegularRegistrationsTableToolbarActionsProps {
   table: Table<VendorRegularRegistration>
@@ -22,24 +24,31 @@ interface VendorRegularRegistrationsTableToolbarActionsProps {
 export function VendorRegularRegistrationsTableToolbarActions({
   table,
 }: VendorRegularRegistrationsTableToolbarActionsProps) {
+  const router = useRouter()
   const [syncLoading, setSyncLoading] = useState<{ 
     missingContract: boolean; 
     additionalInfo: boolean;
     legalSkip: boolean;
-    safetySkip: boolean;
+    registrationRequest: boolean;
   }>({
     missingContract: false,
     additionalInfo: false,
     legalSkip: false,
-    safetySkip: false,
+    registrationRequest: false,
   })
 
   const [skipDialogs, setSkipDialogs] = useState<{
     legalReview: boolean;
-    safetyQualification: boolean;
   }>({
     legalReview: false,
-    safetyQualification: false,
+  })
+
+  const [registrationRequestDialog, setRegistrationRequestDialog] = useState<{
+    open: boolean;
+    registration: VendorRegularRegistration | null;
+  }>({
+    open: false,
+    registration: null,
   })
 
   const selectedRows = table.getFilteredSelectedRowModel().rows.map(row => row.original)
@@ -108,7 +117,7 @@ export function VendorRegularRegistrationsTableToolbarActions({
       
       if (result.success) {
         toast.success(result.message);
-        window.location.reload();
+        router.refresh();
       } else {
         toast.error(result.error);
       }
@@ -120,33 +129,52 @@ export function VendorRegularRegistrationsTableToolbarActions({
     }
   };
 
-  const handleSafetyQualificationSkip = async (reason: string) => {
-    if (selectedRows.length === 0) {
-      toast.error("업체를 선택해주세요.");
+  // 등록요청 핸들러
+  const handleRegistrationRequest = () => {
+    const approvalReadyRows = selectedRows.filter(row => row.status === "approval_ready");
+    
+    if (approvalReadyRows.length === 0) {
+      toast.error("조건충족 상태의 벤더를 선택해주세요.");
+      return;
+    }
+    
+    if (approvalReadyRows.length > 1) {
+      toast.error("정규업체 등록 요청은 한 번에 하나씩만 가능합니다.");
       return;
     }
 
-    setSyncLoading(prev => ({ ...prev, safetySkip: true }));
+    setRegistrationRequestDialog({
+      open: true,
+      registration: approvalReadyRows[0],
+    });
+  };
+
+  const handleRegistrationRequestSubmit = async (requestData: any) => {
+    if (!registrationRequestDialog.registration) return;
+
+    setSyncLoading(prev => ({ ...prev, registrationRequest: true }));
     try {
-      const vendorIds = selectedRows.map(row => row.vendorId);
-      const result = await skipSafetyQualification(vendorIds, reason);
-      
+      const result = await submitRegistrationRequest(registrationRequestDialog.registration.id, requestData);
       if (result.success) {
         toast.success(result.message);
-        window.location.reload();
+        setRegistrationRequestDialog({ open: false, registration: null });
+        window.location.reload(); // 데이터 새로고침
       } else {
         toast.error(result.error);
       }
     } catch (error) {
-      console.error("Error skipping safety qualification:", error);
-      toast.error("안전적격성평가 Skip 처리 중 오류가 발생했습니다.");
+      console.error("등록요청 오류:", error);
+      toast.error("등록요청 중 오류가 발생했습니다.");
     } finally {
-      setSyncLoading(prev => ({ ...prev, safetySkip: false }));
+      setSyncLoading(prev => ({ ...prev, registrationRequest: false }));
     }
   };
 
   // CP검토 상태인 선택된 행들 개수
   const cpReviewCount = selectedRows.filter(row => row.status === "cp_review").length;
+  
+  // 조건충족 상태인 선택된 행들 개수
+  const approvalReadyCount = selectedRows.filter(row => row.status === "approval_ready").length;
 
   return (
     <div className="flex items-center gap-2">
@@ -190,22 +218,6 @@ export function VendorRegularRegistrationsTableToolbarActions({
         {syncLoading.additionalInfo ? "발송 중..." : "추가정보요청"}
       </Button>
 
-      <Button
-        variant="outline"
-        size="sm"
-        onClick={() => {
-          if (selectedRows.length === 0) {
-            toast.error("내보낼 항목을 선택해주세요.")
-            return
-          }
-          toast.info("엑셀 내보내기 기능은 준비 중입니다.")
-        }}
-        disabled={selectedRows.length === 0}
-      >
-        <Download className="mr-2 h-4 w-4" />
-        엑셀 내보내기
-      </Button>
-
       <Button
         variant="outline"
         size="sm"
@@ -213,35 +225,33 @@ export function VendorRegularRegistrationsTableToolbarActions({
         disabled={syncLoading.legalSkip || cpReviewCount === 0}
       >
         <Scale className="mr-2 h-4 w-4" />
-        {syncLoading.legalSkip ? "처리 중..." : "법무검토 Skip"}
+        {syncLoading.legalSkip ? "처리 중..." : "GTC Skip"}
       </Button>
 
       <Button
-        variant="outline"
+        variant="default"
         size="sm"
-        onClick={() => setSkipDialogs(prev => ({ ...prev, safetyQualification: true }))}
-        disabled={syncLoading.safetySkip || selectedRows.length === 0}
+        onClick={handleRegistrationRequest}
+        disabled={syncLoading.registrationRequest || approvalReadyCount === 0}
       >
-        <Shield className="mr-2 h-4 w-4" />
-        {syncLoading.safetySkip ? "처리 중..." : "안전 Skip"}
+        <FileText className="mr-2 h-4 w-4" />
+        {syncLoading.registrationRequest ? "처리 중..." : "등록요청"}
       </Button>
 
       <SkipReasonDialog
         open={skipDialogs.legalReview}
         onOpenChange={(open) => setSkipDialogs(prev => ({ ...prev, legalReview: open }))}
-        title="법무검토 Skip"
-        description={`선택된 ${cpReviewCount}개 업체의 법무검토를 Skip하고 CP완료 상태로 변경합니다. Skip 사유를 입력해주세요.`}
+        title="GTC Skip"
+        description={`선택된 ${cpReviewCount}개 업체의 GTC를 Skip하고 CP완료 상태로 변경합니다. Skip 사유를 입력해주세요.`}
         onConfirm={handleLegalReviewSkip}
         loading={syncLoading.legalSkip}
       />
 
-      <SkipReasonDialog
-        open={skipDialogs.safetyQualification}
-        onOpenChange={(open) => setSkipDialogs(prev => ({ ...prev, safetyQualification: open }))}
-        title="안전적격성평가 Skip"
-        description={`선택된 ${selectedRows.length}개 업체의 안전적격성평가를 Skip하고 완료 상태로 변경합니다. Skip 사유를 입력해주세요.`}
-        onConfirm={handleSafetyQualificationSkip}
-        loading={syncLoading.safetySkip}
+      <RegistrationRequestDialog
+        open={registrationRequestDialog.open}
+        onOpenChange={(open) => setRegistrationRequestDialog(prev => ({ ...prev, open }))}
+        registration={registrationRequestDialog.registration}
+        onSubmit={handleRegistrationRequestSubmit}
       />
     </div>
   )
-- 
cgit v1.2.3

