From bac0228d21b7195065e9cddcc327ae33659c7bcc Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Sun, 1 Jun 2025 13:52:21 +0000
Subject: (대표님) 20250601까지 작업사항
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/vendor-document-list/table/add-doc-dialog.tsx | 28 +++++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

(limited to 'lib/vendor-document-list/table/add-doc-dialog.tsx')

diff --git a/lib/vendor-document-list/table/add-doc-dialog.tsx b/lib/vendor-document-list/table/add-doc-dialog.tsx
index b108721c..9bedc810 100644
--- a/lib/vendor-document-list/table/add-doc-dialog.tsx
+++ b/lib/vendor-document-list/table/add-doc-dialog.tsx
@@ -37,9 +37,10 @@ type CreateDocumentSchema = z.infer<typeof createDocumentSchema>;
 interface AddDocumentListDialogProps {
     projectType: "ship" | "plant";
     contractId: number;
+    onSuccess?: () => void; // ✅ onSuccess 콜백 추가
 }
 
-export function AddDocumentListDialog({ projectType, contractId }: AddDocumentListDialogProps) {
+export function AddDocumentListDialog({ projectType, contractId, onSuccess }: AddDocumentListDialogProps) {
     const [open, setOpen] = React.useState(false);
     const [isSubmitting, setIsSubmitting] = React.useState(false);
     const router = useRouter();
@@ -98,8 +99,12 @@ export function AddDocumentListDialog({ projectType, contractId }: AddDocumentLi
             } as CreateDocumentInputType);
             
             if (result.success) {
-                // 성공 시 캐시 무효화
-                await invalidateDocumentCache(contractId);
+                // ✅ 캐시 무효화 시도 (에러가 나더라도 계속 진행)
+                try {
+                    await invalidateDocumentCache(contractId);
+                } catch (cacheError) {
+                    console.warn('Cache invalidation failed:', cacheError);
+                }
                 
                 // 토스트 메시지
                 toast({
@@ -109,10 +114,23 @@ export function AddDocumentListDialog({ projectType, contractId }: AddDocumentLi
                 });
                 
                 // 모달 닫기 및 폼 리셋
-                form.reset();
+                form.reset({
+                    docNumber: "",
+                    title: "",
+                    stages: defaultStages
+                });
                 setOpen(false);
                 
-                router.refresh();
+                // ✅ 성공 콜백 호출 (부모 컴포넌트에서 추가 처리 가능)
+                if (onSuccess) {
+                    onSuccess();
+                }
+                
+                // ✅ 라우터 새로고침 (약간의 지연을 두고 실행)
+                setTimeout(() => {
+                    router.refresh();
+                }, 100);
+                
             } else {
                 // 실패 시 에러 토스트
                 toast({
-- 
cgit v1.2.3

