diff options
Diffstat (limited to 'lib/basic-contract/viewer')
| -rw-r--r-- | lib/basic-contract/viewer/SurveyComponent.tsx | 20 | ||||
| -rw-r--r-- | lib/basic-contract/viewer/basic-contract-sign-viewer.tsx | 44 |
2 files changed, 50 insertions, 14 deletions
diff --git a/lib/basic-contract/viewer/SurveyComponent.tsx b/lib/basic-contract/viewer/SurveyComponent.tsx index 299fe6fa..8662155e 100644 --- a/lib/basic-contract/viewer/SurveyComponent.tsx +++ b/lib/basic-contract/viewer/SurveyComponent.tsx @@ -34,6 +34,7 @@ interface SurveyComponentProps { contractId?: number; surveyTemplate: SurveyTemplateWithQuestions | null; surveyLoading: boolean; + surveyLoadAttempted?: boolean; // 로드 시도 여부 추가 conditionalHandler: ConditionalSurveyHandler | null; onSurveyComplete?: () => void; onSurveyDataUpdate: (data: any) => void; @@ -45,6 +46,7 @@ export const SurveyComponent: React.FC<SurveyComponentProps> = ({ contractId, surveyTemplate, surveyLoading, + surveyLoadAttempted = false, conditionalHandler, onSurveyComplete, onSurveyDataUpdate, @@ -487,7 +489,21 @@ export const SurveyComponent: React.FC<SurveyComponentProps> = ({ ); } + if (!surveyTemplate) { + if (!surveyLoadAttempted) { + return ( + <div className="h-full w-full"> + <Card className="h-full"> + <CardContent className="flex flex-col items-center justify-center h-full py-12"> + <Loader2 className="h-8 w-8 text-blue-500 animate-spin mb-4" /> + <p className="text-sm text-muted-foreground">설문조사를 준비하는 중...</p> + </CardContent> + </Card> + </div> + ); + } + return ( <div className="h-full w-full"> <Card className="h-full"> @@ -836,8 +852,8 @@ export const SurveyComponent: React.FC<SurveyComponentProps> = ({ {uploadedFiles[question.id].map((file, index) => ( <div key={index} className="flex items-center space-x-2 text-sm"> <FileText className="h-4 w-4 text-blue-500" /> - <span>{file.fileName}</span> - <span className="text-gray-500">({(file.fileSize / 1024).toFixed(1)} KB)</span> + <span>{file.name || file.fileName}</span> + <span className="text-gray-500">({((file.size || file.fileSize || 0) / 1024).toFixed(1)} KB)</span> </div> ))} </div> diff --git a/lib/basic-contract/viewer/basic-contract-sign-viewer.tsx b/lib/basic-contract/viewer/basic-contract-sign-viewer.tsx index 77bfaf41..b6024b29 100644 --- a/lib/basic-contract/viewer/basic-contract-sign-viewer.tsx +++ b/lib/basic-contract/viewer/basic-contract-sign-viewer.tsx @@ -641,6 +641,7 @@ export function BasicContractSignViewer({ const [isInitialLoaded, setIsInitialLoaded] = useState<boolean>(false); const [surveyTemplate, setSurveyTemplate] = useState<SurveyTemplateWithQuestions | null>(null); const [surveyLoading, setSurveyLoading] = useState<boolean>(false); + const [surveyLoadAttempted, setSurveyLoadAttempted] = useState<boolean>(false); const [gtcCommentStatus, setGtcCommentStatus] = useState<{ hasComments: boolean; commentCount: number; @@ -756,16 +757,16 @@ export function BasicContractSignViewer({ useEffect(() => { setShowDialog(isOpen); - // 구매자 모드가 아닐 때만 설문조사 템플릿 로드 - if (isOpen && isComplianceTemplate && !surveyTemplate && mode !== 'buyer') { - loadSurveyTemplate(); - } - if (isOpen) { setIsInitialLoaded(false); currentDocumentPath.current = ""; } - }, [isOpen, isComplianceTemplate, mode]); + + // 구매자 모드가 아닐 때만 설문조사 템플릿 로드 + if (isOpen && isComplianceTemplate && !surveyTemplate && !surveyLoading && mode !== 'buyer') { + loadSurveyTemplate(); + } + }, [isOpen, isComplianceTemplate, surveyTemplate, surveyLoading, mode]); useEffect(() => { if (!filePath) return; @@ -790,13 +791,28 @@ export function BasicContractSignViewer({ }, [filePath, instance]); const loadSurveyTemplate = async () => { + // 이미 로딩 중이거나 템플릿이 있으면 중복 호출 방지 + if (surveyLoading || surveyTemplate) { + return; + } + setSurveyLoading(true); + setSurveyLoadAttempted(true); // 로드 시도 표시 try { - const template = await getActiveSurveyTemplate(); + + // 계약서 템플릿 이름에서 언어 판단 + let language = 'ko'; // 기본값 한글 + if (templateName && (templateName.includes('영문') || templateName.toLowerCase().includes('english'))) { + language = 'en'; + } + + + const template = await getActiveSurveyTemplate(language); + setSurveyTemplate(template); } catch (error) { - console.error('📛 설문조사 템플릿 로드 실패:', error); + setSurveyTemplate(null); } finally { setSurveyLoading(false); @@ -1046,15 +1062,17 @@ export function BasicContractSignViewer({ const handleTabChange = async (newTab: string) => { setActiveTab(newTab); - if (newTab === "survey" || newTab === "clauses") return; - - const currentInstance = webViewerInstance.current || instance; - if (!currentInstance || fileLoading) return; + // survey 탭으로 변경 시 템플릿 로드 확인 if (newTab === 'survey' && !surveyTemplate && !surveyLoading && mode !== 'buyer') { loadSurveyTemplate(); } + if (newTab === "survey" || newTab === "clauses") return; + + const currentInstance = webViewerInstance.current || instance; + if (!currentInstance || fileLoading) return; + let targetFile: FileInfo | undefined; if (newTab === "main") { targetFile = allFiles.find(f => f.type === "main"); @@ -1272,6 +1290,7 @@ export function BasicContractSignViewer({ contractId={contractId} surveyTemplate={surveyTemplate} surveyLoading={surveyLoading} + surveyLoadAttempted={surveyLoadAttempted} conditionalHandler={conditionalHandler} onSurveyComplete={onSurveyComplete} onSurveyDataUpdate={setSurveyData} @@ -1456,6 +1475,7 @@ export function BasicContractSignViewer({ contractId={contractId} surveyTemplate={surveyTemplate} surveyLoading={surveyLoading} + surveyLoadAttempted={surveyLoadAttempted} conditionalHandler={conditionalHandler} onSurveyComplete={onSurveyComplete} onSurveyDataUpdate={setSurveyData} |
