diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-07 04:43:43 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-07 04:43:43 +0000 |
| commit | 7f973de2a814a2040a646161b563c8990b7e2fd2 (patch) | |
| tree | a00faad2246fe03f448de758c7171c63294819c9 /lib/basic-contract/template/template-editor-wrapper.tsx | |
| parent | 18ca4ad784aeeab9ab7a13bbc8b3c13b42ca5e49 (diff) | |
(임수민) 기본계약서 서명란 변수 추가
Diffstat (limited to 'lib/basic-contract/template/template-editor-wrapper.tsx')
| -rw-r--r-- | lib/basic-contract/template/template-editor-wrapper.tsx | 97 |
1 files changed, 81 insertions, 16 deletions
diff --git a/lib/basic-contract/template/template-editor-wrapper.tsx b/lib/basic-contract/template/template-editor-wrapper.tsx index af5d42a8..2c1c7e4d 100644 --- a/lib/basic-contract/template/template-editor-wrapper.tsx +++ b/lib/basic-contract/template/template-editor-wrapper.tsx @@ -18,25 +18,35 @@ interface TemplateEditorWrapperProps { } const getVariablesForTemplate = (templateName: string): string[] => { + let variables: string[] = []; + // 정확한 매치 먼저 확인 if (TEMPLATE_VARIABLES_MAP[templateName as keyof typeof TEMPLATE_VARIABLES_MAP]) { - return [...TEMPLATE_VARIABLES_MAP[templateName as keyof typeof TEMPLATE_VARIABLES_MAP]]; - } - - // GTC가 포함된 경우 확인 - if (templateName.includes("GTC")) { - return [...TEMPLATE_VARIABLES_MAP["GTC"]]; - } - - // 다른 키워드들도 포함 관계로 확인 - for (const [key, variables] of Object.entries(TEMPLATE_VARIABLES_MAP)) { - if (templateName.includes(key)) { - return [...variables]; + variables = [...TEMPLATE_VARIABLES_MAP[templateName as keyof typeof TEMPLATE_VARIABLES_MAP]]; + } else if (templateName.includes("GTC")) { + // GTC가 포함된 경우 확인 + variables = [...TEMPLATE_VARIABLES_MAP["GTC"]]; + } else { + // 다른 키워드들도 포함 관계로 확인 + let found = false; + for (const [key, vars] of Object.entries(TEMPLATE_VARIABLES_MAP)) { + if (templateName.includes(key)) { + variables = [...vars]; + found = true; + break; + } + } + + // 기본값 반환 + if (!found) { + variables = ["company_name", "company_address", "representative_name", "signature_date"]; } } - // 기본값 반환 - return ["company_name", "company_address", "representative_name", "signature_date"]; + // 모든 템플릿에 서명란 변수 추가 (중복 제거) + const signatureVars = ["vendor_signature", "buyer_signature"]; + const allVariables = [...variables, ...signatureVars]; + return [...new Set(allVariables)]; // 중복 제거 }; // 템플릿 이름별 변수 매핑 @@ -67,9 +77,23 @@ const VARIABLE_DESCRIPTION_MAP = { "tax_id": "사업자등록번호", "phone_number": "전화번호", "phone": "전화번호", - "email": "이메일" + "email": "이메일", + "vendor_signature": "협력업체 서명란", + "buyer_signature": "구매자 서명란", + "협력업체_서명란": "협력업체 서명란", + "삼성중공업_서명란": "구매자 서명란" } as const; +// 서명란 텍스트를 변수명으로 변환 +const getSignatureVariableName = (searchText: string): string => { + if (searchText === '협력업체_서명란') { + return 'vendor_signature'; + } else if (searchText === '삼성중공업_서명란') { + return 'buyer_signature'; + } + return searchText; +}; + // 변수 패턴 감지를 위한 정규식 const VARIABLE_PATTERN = /\{\{([^}]+)\}\}/g; @@ -86,6 +110,7 @@ export function TemplateEditorWrapper({ const [documentVariables, setDocumentVariables] = React.useState<string[]>([]); const [templateName, setTemplateName] = React.useState<string>(""); const [predefinedVariables, setPredefinedVariables] = React.useState<string[]>([]); + const [signatureVariables, setSignatureVariables] = React.useState<string[]>([]); // 서명란 변수 // 템플릿 이름 로드 및 변수 설정 React.useEffect(() => { @@ -359,7 +384,7 @@ export function TemplateEditorWrapper({ </div> {/* 변수 도구 */} - {(documentVariables.length > 0 || predefinedVariables.length > 0) && ( + {(documentVariables.length > 0 || predefinedVariables.length > 0 || signatureVariables.length > 0) && ( <div className="mt-3 p-3 bg-white rounded border"> <div className="mb-2"> <h4 className="text-sm font-medium flex items-center"> @@ -388,6 +413,36 @@ export function TemplateEditorWrapper({ </div> )} + {/* 서명란 변수 */} + {signatureVariables.length > 0 && ( + <div> + <p className="text-xs text-muted-foreground mb-2"> + 서명란 변수 (클릭하여 복사): + </p> + <TooltipProvider> + <div className="flex flex-wrap gap-1"> + {signatureVariables.map((variable, index) => ( + <Tooltip key={`signature-${variable}-${index}`}> + <TooltipTrigger asChild> + <Button + variant="ghost" + size="sm" + className="h-6 px-2 text-xs hover:bg-green-50 border border-green-200" + onClick={() => insertVariable(variable)} + > + {`{{${variable}}}`} + </Button> + </TooltipTrigger> + <TooltipContent> + <p>{VARIABLE_DESCRIPTION_MAP[variable as keyof typeof VARIABLE_DESCRIPTION_MAP] || variable}</p> + </TooltipContent> + </Tooltip> + ))} + </div> + </TooltipProvider> + </div> + )} + {/* 템플릿별 미리 정의된 변수들 */} {predefinedVariables.length > 0 && ( <div> @@ -430,6 +485,16 @@ export function TemplateEditorWrapper({ filePath={filePath} instance={instance} setInstance={setInstance} + onSignatureFieldFound={(searchText) => { + // 서명란 발견 시 변수명으로 변환하여 추가 + const variableName = getSignatureVariableName(searchText); + setSignatureVariables(prev => { + if (!prev.includes(variableName)) { + return [...prev, variableName]; + } + return prev; + }); + }} /> </div> </div> |
