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

---
 .../vendor-registration-status-view.tsx            | 260 ++++-----------------
 1 file changed, 45 insertions(+), 215 deletions(-)

(limited to 'lib/vendor-registration-status/vendor-registration-status-view.tsx')

diff --git a/lib/vendor-registration-status/vendor-registration-status-view.tsx b/lib/vendor-registration-status/vendor-registration-status-view.tsx
index b3000f73..850dd777 100644
--- a/lib/vendor-registration-status/vendor-registration-status-view.tsx
+++ b/lib/vendor-registration-status/vendor-registration-status-view.tsx
@@ -4,13 +4,11 @@ import { useState, useEffect } from "react"
 import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
 import { Badge } from "@/components/ui/badge"
 import { Button } from "@/components/ui/button"
-import { Separator } from "@/components/ui/separator"
+
 import { 
   CheckCircle, 
   XCircle, 
   FileText, 
-  Users, 
-  Building2,
   AlertCircle,
   Eye,
   Upload
@@ -21,6 +19,9 @@ import { format } from "date-fns"
 import { toast } from "sonner"
 import { fetchVendorRegistrationStatus } from "@/lib/vendor-regular-registrations/service"
 
+// 세션에서 벤더아이디 가져오기 위한 훅
+import { useSession } from "next-auth/react"
+
 // 상태별 정의
 const statusConfig = {
   audit_pass: {
@@ -81,11 +82,15 @@ export function VendorRegistrationStatusView() {
   const [data, setData] = useState<any>(null)
   const [loading, setLoading] = useState(true)
 
-  // 임시로 vendorId = 1 사용 (실제로는 세션에서 가져와야 함)
-  const vendorId = 1
+  // 세션에서 vendorId 가져오기
+  const { data: session, status: sessionStatus } = useSession()
+  const vendorId = session?.user?.companyId
+  console.log(vendorId)
 
   // 데이터 로드
   useEffect(() => {
+    if (!vendorId) return
+
     const initialLoad = async () => {
       try {
         const result = await fetchVendorRegistrationStatus(vendorId)
@@ -104,10 +109,14 @@ export function VendorRegistrationStatusView() {
     initialLoad()
   }, [vendorId])
 
-  if (loading) {
+  if (sessionStatus === "loading" || loading) {
     return <div className="p-8 text-center">로딩 중...</div>
   }
 
+  if (!vendorId) {
+    return <div className="p-8 text-center">벤더 정보가 없습니다. 다시 로그인 해주세요.</div>
+  }
+
   if (!data) {
     return <div className="p-8 text-center">데이터를 불러올 수 없습니다.</div>
   }
@@ -123,9 +132,10 @@ export function VendorRegistrationStatusView() {
   const registrationForDialog: any = {
     id: data.registration?.id || 0,
     vendorId: data.vendor.id,
-    companyName: data.vendor.companyName,
-    businessNumber: data.vendor.businessNumber,
-    representative: data.vendor.representative || "",
+    companyName: data.vendor.vendorName,
+    businessNumber: data.vendor.taxId,
+    representative: data.vendor.representativeName || "",
+    country: data.vendor.country || "KR", // 기본값 KR
     potentialCode: data.registration?.potentialCode || "",
     status: data.registration?.status || "audit_pass",
     majorItems: "[]", // 빈 JSON 문자열
@@ -136,9 +146,12 @@ export function VendorRegistrationStatusView() {
     assignedUser: data.registration?.assignedUser,
     assignedUserCode: data.registration?.assignedUserCode,
     remarks: data.registration?.remarks,
+    safetyQualificationContent: data.registration?.safetyQualificationContent || null,
+    gtcSkipped: data.registration?.gtcSkipped || false,
     additionalInfo: data.additionalInfo,
     documentSubmissions: data.documentStatus, // documentSubmissions를 documentStatus로 설정
     contractAgreements: [],
+    basicContracts: data.basicContracts || [], // 실제 데이터 사용
     documentSubmissionsStatus: data.documentStatus,
     contractAgreementsStatus: {
       cpDocument: data.documentStatus.cpDocument,
@@ -164,10 +177,12 @@ export function VendorRegistrationStatusView() {
   }
 
   const loadData = async () => {
+    if (!vendorId) return
     try {
       const result = await fetchVendorRegistrationStatus(vendorId)
       if (result.success) {
         setData(result.data)
+        toast.success("데이터가 새로고침되었습니다.")
       } else {
         toast.error(result.error)
       }
@@ -226,214 +241,28 @@ export function VendorRegistrationStatusView() {
         </CardContent>
       </Card>
 
-      {/* 기본 정보 */}
-      <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
-        <Card>
-          <CardHeader>
-            <CardTitle className="flex items-center gap-2">
-              <Building2 className="w-5 h-5" />
-              업체 정보
-            </CardTitle>
-          </CardHeader>
-          <CardContent className="space-y-3">
-            <div className="grid grid-cols-2 gap-4">
-              <div>
-                <span className="text-sm font-medium text-gray-600">업체명:</span>
-                <p className="mt-1">{data.vendor.companyName}</p>
-              </div>
-              <div>
-                <span className="text-sm font-medium text-gray-600">사업자번호:</span>
-                <p className="mt-1">{data.vendor.businessNumber}</p>
-              </div>
-            </div>
-            <div className="grid grid-cols-2 gap-4">
-              <div>
-                <span className="text-sm font-medium text-gray-600">업체구분:</span>
-                <p className="mt-1">{data.registration ? "정규업체" : "잠재업체"}</p>
-              </div>
-              <div>
-                <span className="text-sm font-medium text-gray-600">eVCP 가입:</span>
-                <p className="mt-1">{data.vendor.createdAt ? format(new Date(data.vendor.createdAt), "yyyy.MM.dd") : "-"}</p>
-              </div>
-            </div>
-          </CardContent>
-        </Card>
-
-        <Card>
-          <CardHeader>
-            <CardTitle className="flex items-center gap-2">
-              <Users className="w-5 h-5" />
-              담당자 정보
-            </CardTitle>
-          </CardHeader>
-          <CardContent className="space-y-3">
-            <div className="grid grid-cols-2 gap-4">
-              <div>
-                <span className="text-sm font-medium text-gray-600">SHI 담당자:</span>
-                <p className="mt-1">{data.registration?.assignedDepartment || "-"} {data.registration?.assignedUser || "-"}</p>
-              </div>
-              <div>
-                <span className="text-sm font-medium text-gray-600">진행상태:</span>
-                <Badge className={`mt-1 ${currentStatusConfig.color}`} variant="secondary">
-                  {currentStatusConfig.label}
-                </Badge>
-              </div>
-            </div>
-            <div className="grid grid-cols-2 gap-4">
-              <div>
-                <span className="text-sm font-medium text-gray-600">상태변경일:</span>
-                <p className="mt-1">{data.registration?.updatedAt ? format(new Date(data.registration.updatedAt), "yyyy.MM.dd") : "-"}</p>
-              </div>
-            </div>
-          </CardContent>
-        </Card>
+      {/* 간소화된 액션 버튼들 */}
+      <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
+        <Button
+          onClick={() => setDocumentDialogOpen(true)}
+          variant="outline"
+          size="lg"
+          className="h-16 flex flex-col items-center gap-2"
+        >
+          <Eye className="w-6 h-6" />
+          <span>문서 현황 확인</span>
+        </Button>
+        <Button
+          onClick={() => setAdditionalInfoDialogOpen(true)}
+          variant={data.additionalInfo ? "outline" : "default"}
+          size="lg"
+          className="h-16 flex flex-col items-center gap-2"
+        >
+          <FileText className="w-6 h-6" />
+          <span>{data.additionalInfo ? "추가정보 수정" : "추가정보 등록"}</span>
+        </Button>
       </div>
 
-      {/* 미완항목 */}
-      {missingDocuments.length > 0 && (
-        <Card className="border-red-200 bg-red-50">
-          <CardHeader>
-            <CardTitle className="flex items-center gap-2 text-red-800">
-              <AlertCircle className="w-5 h-5" />
-              미완항목
-            </CardTitle>
-          </CardHeader>
-          <CardContent>
-            <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
-              {data.incompleteItemsCount.documents > 0 && (
-                <div className="flex items-center justify-between p-3 bg-white rounded-lg border">
-                  <span className="text-sm font-medium">미제출문서</span>
-                  <Badge variant="destructive">{data.incompleteItemsCount.documents} 건</Badge>
-                </div>
-              )}
-              {!data.documentStatus.auditResult && (
-                <div className="flex items-center justify-between p-3 bg-white rounded-lg border">
-                  <span className="text-sm font-medium">실사결과</span>
-                  <Badge variant="destructive">미실시</Badge>
-                </div>
-              )}
-              {data.incompleteItemsCount.additionalInfo > 0 && (
-                <div className="flex items-center justify-between p-3 bg-white rounded-lg border">
-                  <span className="text-sm font-medium">추가정보</span>
-                  <Badge variant="destructive">미입력</Badge>
-                </div>
-              )}
-            </div>
-          </CardContent>
-        </Card>
-      )}
-
-      {/* 상세 진행현황 */}
-      <Card>
-        <CardHeader>
-          <CardTitle>상세 진행현황</CardTitle>
-        </CardHeader>
-        <CardContent>
-          <div className="space-y-6">
-            {/* 기본 진행상황 */}
-            <div className="grid grid-cols-4 gap-4 text-center">
-              <div className="space-y-2">
-                <div className="text-sm font-medium text-gray-600">PQ 제출</div>
-                <div className="text-lg font-semibold">
-                  {data.pqSubmission ? (
-                    <div className="flex items-center justify-center gap-2">
-                      <CheckCircle className="w-5 h-5 text-green-600" />
-                      {format(new Date(data.pqSubmission.createdAt), "yyyy.MM.dd")}
-                    </div>
-                  ) : (
-                    <div className="flex items-center justify-center gap-2">
-                      <XCircle className="w-5 h-5 text-red-500" />
-                      미제출
-                    </div>
-                  )}
-                </div>
-              </div>
-              <div className="space-y-2">
-                <div className="text-sm font-medium text-gray-600">실사 통과</div>
-                <div className="text-lg font-semibold">
-                  {data.auditPassed ? (
-                    <div className="flex items-center justify-center gap-2">
-                      <CheckCircle className="w-5 h-5 text-green-600" />
-                      통과
-                    </div>
-                  ) : (
-                    <div className="flex items-center justify-center gap-2">
-                      <XCircle className="w-5 h-5 text-red-500" />
-                      미통과
-                    </div>
-                  )}
-                </div>
-              </div>
-              <div className="space-y-2">
-                <div className="text-sm font-medium text-gray-600">문서 현황</div>
-                <Button
-                  onClick={() => setDocumentDialogOpen(true)}
-                  variant="outline"
-                  size="sm"
-                  className="flex items-center gap-2"
-                >
-                  <Eye className="w-4 h-4" />
-                  확인하기
-                </Button>
-              </div>
-              <div className="space-y-2">
-                <div className="text-sm font-medium text-gray-600">추가정보</div>
-                <Button
-                  onClick={() => setAdditionalInfoDialogOpen(true)}
-                  variant={data.additionalInfo ? "outline" : "default"}
-                  size="sm"
-                  className="flex items-center gap-2"
-                >
-                  <FileText className="w-4 h-4" />
-                  {data.additionalInfo ? "수정하기" : "등록하기"}
-                </Button>
-              </div>
-            </div>
-
-            <Separator />
-
-            {/* 필수문서 상태 */}
-            <div>
-              <h4 className="text-sm font-medium text-gray-600 mb-4">필수문서 제출 현황</h4>
-              <div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3">
-                {requiredDocuments.map((doc) => {
-                  const isSubmitted = data.documentStatus[doc.key as keyof typeof data.documentStatus]
-                  return (
-                    <div
-                      key={doc.key}
-                      className={`p-3 rounded-lg border text-center ${
-                        isSubmitted 
-                          ? 'bg-green-50 border-green-200' 
-                          : 'bg-red-50 border-red-200'
-                      }`}
-                    >
-                      <div className="flex items-center justify-center mb-2">
-                        {isSubmitted ? (
-                          <CheckCircle className="w-5 h-5 text-green-600" />
-                        ) : (
-                          <XCircle className="w-5 h-5 text-red-500" />
-                        )}
-                      </div>
-                      <div className="text-xs font-medium">{doc.label}</div>
-                      {isSubmitted && (
-                        <Button
-                          variant="ghost"
-                          size="sm"
-                          className="mt-2 h-6 text-xs"
-                        >
-                          <Eye className="w-3 h-3 mr-1" />
-                          보기
-                        </Button>
-                      )}
-                    </div>
-                  )
-                })}
-              </div>
-            </div>
-          </div>
-        </CardContent>
-      </Card>
-
       {/* 상태 설명 */}
       <Card>
         <CardHeader>
@@ -456,6 +285,7 @@ export function VendorRegistrationStatusView() {
         open={documentDialogOpen}
         onOpenChange={setDocumentDialogOpen}
         registration={registrationForDialog}
+        onRefresh={loadData}
       />
 
       {/* 추가정보 입력 Dialog */}
-- 
cgit v1.2.3

