summaryrefslogtreecommitdiff
path: root/lib/basic-contract/template/template-editor-wrapper.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-08-07 05:04:39 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-08-07 05:04:39 +0000
commite270e477f362dd68249bb4a013c66eab293bba82 (patch)
treeef29ec732fc62c220ca2f6ab12aa282b0db7c9ab /lib/basic-contract/template/template-editor-wrapper.tsx
parenta5cecbef039e29beaa616e3a36e7f15b8b35623c (diff)
(최겸) PQ요청+기본계약 로직 수정(한글화 미적용)
Diffstat (limited to 'lib/basic-contract/template/template-editor-wrapper.tsx')
-rw-r--r--lib/basic-contract/template/template-editor-wrapper.tsx103
1 files changed, 79 insertions, 24 deletions
diff --git a/lib/basic-contract/template/template-editor-wrapper.tsx b/lib/basic-contract/template/template-editor-wrapper.tsx
index ea353b91..96e2330f 100644
--- a/lib/basic-contract/template/template-editor-wrapper.tsx
+++ b/lib/basic-contract/template/template-editor-wrapper.tsx
@@ -7,7 +7,7 @@ import { Save, RefreshCw, Type, FileText, AlertCircle } from "lucide-react";
import type { WebViewerInstance } from "@pdftron/webviewer";
import { Badge } from "@/components/ui/badge";
import { BasicContractTemplateViewer } from "./basic-contract-template-viewer";
-import { saveTemplateFile } from "../service";
+import { getExistingTemplateNamesById, saveTemplateFile } from "../service";
interface TemplateEditorWrapperProps {
templateId: string | number;
@@ -16,9 +16,27 @@ interface TemplateEditorWrapperProps {
refreshAction?: () => Promise<void>;
}
+// 템플릿 이름별 변수 매핑 (영문 변수명 사용)
+const TEMPLATE_VARIABLES_MAP = {
+ "준법서약 (한글)": ["vendor_name", "address", "representative_name", "today_date"],
+ "준법서약 (영문)": ["vendor_name", "address", "representative_name", "today_date"],
+ "기술자료 요구서": ["vendor_name", "address", "representative_name", "today_date"],
+ "비밀유지 계약서": ["vendor_name", "address", "representative_name", "today_date"],
+ "표준하도급기본 계약서": ["vendor_name", "address", "representative_name", "today_date"],
+ "GTC": ["vendor_name", "address", "representative_name", "today_date"],
+ "안전보건관리 약정서": ["vendor_name", "address", "representative_name", "today_date"],
+ "동반성장": ["vendor_name", "address", "representative_name", "today_date"],
+ "윤리규범 준수 서약서": ["vendor_name", "address", "representative_name", "today_date"],
+ "기술자료 동의서": ["vendor_name", "address", "representative_name", "today_date"],
+ "내국신용장 미개설 합의서": ["vendor_name", "address", "representative_name", "today_date"],
+ "직납자재 하도급대급등 연동제 의향서": ["vendor_name", "address", "representative_name", "today_date"]
+} as const;
+
// 변수 패턴 감지를 위한 정규식
const VARIABLE_PATTERN = /\{\{([^}]+)\}\}/g;
+
+
export function TemplateEditorWrapper({
templateId,
filePath,
@@ -28,6 +46,35 @@ export function TemplateEditorWrapper({
const [instance, setInstance] = React.useState<WebViewerInstance | null>(null);
const [isSaving, setIsSaving] = React.useState(false);
const [documentVariables, setDocumentVariables] = React.useState<string[]>([]);
+ const [templateName, setTemplateName] = React.useState<string>("");
+ const [predefinedVariables, setPredefinedVariables] = React.useState<string[]>([]);
+
+ console.log(templateId, "templateId");
+
+ // 템플릿 이름 로드 및 변수 설정
+ React.useEffect(() => {
+ const loadTemplateInfo = async () => {
+ try {
+ const name = await getExistingTemplateNamesById(Number(templateId));
+ setTemplateName(name);
+
+ // 템플릿 이름에 따른 변수 설정
+ const variables = TEMPLATE_VARIABLES_MAP[name as keyof typeof TEMPLATE_VARIABLES_MAP] || [];
+ setPredefinedVariables(variables);
+
+ console.log("🏷️ 템플릿 이름:", name);
+ console.log("📝 할당된 변수들:", variables);
+ } catch (error) {
+ console.error("템플릿 정보 로드 오류:", error);
+ // 기본 변수 설정
+ setPredefinedVariables(["회사명", "주소", "대표자명", "오늘날짜"]);
+ }
+ };
+
+ if (templateId) {
+ loadTemplateInfo();
+ }
+ }, [templateId]);
// 문서에서 변수 추출
const extractVariablesFromDocument = async () => {
@@ -220,13 +267,6 @@ export function TemplateEditorWrapper({
window.location.reload();
};
- // 미리 정의된 변수들
- const predefinedVariables = [
- "회사명", "계약자명", "계약일자", "계약금액",
- "납기일자", "담당자명", "담당자연락처", "프로젝트명",
- "계약번호", "사업부", "부서명", "승인자명"
- ];
-
return (
<div className="h-full flex flex-col">
{/* 상단 도구 모음 */}
@@ -267,6 +307,12 @@ export function TemplateEditorWrapper({
<FileText className="mr-1 h-3 w-3" />
{fileName}
</Badge>
+ {templateName && (
+ <Badge variant="secondary">
+ <Type className="mr-1 h-3 w-3" />
+ {templateName}
+ </Badge>
+ )}
{documentVariables.length > 0 && (
<Badge variant="secondary">
<Type className="mr-1 h-3 w-3" />
@@ -283,6 +329,11 @@ export function TemplateEditorWrapper({
<h4 className="text-sm font-medium flex items-center">
<Type className="mr-2 h-4 w-4 text-blue-500" />
변수 관리
+ {templateName && (
+ <span className="ml-2 text-xs text-muted-foreground">
+ ({templateName})
+ </span>
+ )}
</h4>
</div>
@@ -301,23 +352,27 @@ export function TemplateEditorWrapper({
</div>
)}
- {/* 미리 정의된 변수들 */}
- <div>
- <p className="text-xs text-muted-foreground mb-2">자주 사용하는 변수 (클릭하여 복사):</p>
- <div className="flex flex-wrap gap-1">
- {predefinedVariables.map((variable, index) => (
- <Button
- key={index}
- variant="ghost"
- size="sm"
- className="h-6 px-2 text-xs"
- onClick={() => insertVariable(variable)}
- >
- {`{{${variable}}}`}
- </Button>
- ))}
+ {/* 템플릿별 미리 정의된 변수들 */}
+ {predefinedVariables.length > 0 && (
+ <div>
+ <p className="text-xs text-muted-foreground mb-2">
+ {templateName ? `${templateName}에 권장되는 변수` : "자주 사용하는 변수"} (클릭하여 복사):
+ </p>
+ <div className="flex flex-wrap gap-1">
+ {predefinedVariables.map((variable, index) => (
+ <Button
+ key={index}
+ variant="ghost"
+ size="sm"
+ className="h-6 px-2 text-xs hover:bg-blue-50"
+ onClick={() => insertVariable(variable)}
+ >
+ {`{{${variable}}}`}
+ </Button>
+ ))}
+ </div>
</div>
- </div>
+ )}
</div>
</div>
)}