From 1b5ae5fe1c9a6db859fbe4c873dba202b014dea5 Mon Sep 17 00:00:00 2001 From: leeheejin Date: Tue, 13 Jan 2026 15:43:04 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=BC=EB=8B=A8=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniversalFormModalComponent.tsx | 8 +++++ frontend/lib/utils/buttonActions.ts | 36 +++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx b/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx index 3e043331..c03f4cce 100644 --- a/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx +++ b/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx @@ -308,6 +308,14 @@ export function UniversalFormModalComponent({ console.log("[UniversalFormModal] beforeFormSave 이벤트 수신"); console.log("[UniversalFormModal] 설정된 필드 목록:", Array.from(configuredFields)); + // 🆕 시스템 필드 병합: id는 설정 여부와 관계없이 항상 전달 (UPDATE/INSERT 판단용) + // - 신규 등록: formData.id가 없으므로 영향 없음 + // - 편집 모드: formData.id가 있으면 메인 테이블 UPDATE에 사용 + if (formData.id !== undefined && formData.id !== null && formData.id !== "") { + event.detail.formData.id = formData.id; + console.log(`[UniversalFormModal] 시스템 필드 병합: id =`, formData.id); + } + // UniversalFormModal에 설정된 필드만 병합 (채번 규칙 포함) // 외부 formData에 이미 값이 있어도 UniversalFormModal 값으로 덮어씀 // (UniversalFormModal이 해당 필드의 주인이므로) diff --git a/frontend/lib/utils/buttonActions.ts b/frontend/lib/utils/buttonActions.ts index 8bc65cca..e9d6eede 100644 --- a/frontend/lib/utils/buttonActions.ts +++ b/frontend/lib/utils/buttonActions.ts @@ -1971,19 +1971,43 @@ export class ButtonActionExecutor { } }); - console.log("📦 [handleUniversalFormModalTableSectionSave] 메인 테이블 저장 데이터:", mainRowToSave); + // 🆕 메인 테이블 UPDATE/INSERT 판단 + // - formData.id가 있으면 편집 모드 → UPDATE + // - formData.id가 없으면 신규 등록 → INSERT + const existingMainId = formData.id; + const isMainUpdate = existingMainId !== undefined && existingMainId !== null && existingMainId !== ""; - const mainSaveResult = await DynamicFormApi.saveFormData({ - screenId: screenId!, - tableName: tableName!, - data: mainRowToSave, + console.log("📦 [handleUniversalFormModalTableSectionSave] 메인 테이블 저장 데이터:", mainRowToSave); + console.log("📦 [handleUniversalFormModalTableSectionSave] UPDATE/INSERT 판단:", { + existingMainId, + isMainUpdate, }); + let mainSaveResult: { success: boolean; data?: any; message?: string }; + + if (isMainUpdate) { + // 🔄 편집 모드: UPDATE 실행 + console.log("🔄 [handleUniversalFormModalTableSectionSave] 메인 테이블 UPDATE 실행, ID:", existingMainId); + mainSaveResult = await DynamicFormApi.updateFormData(existingMainId, { + tableName: tableName!, + data: mainRowToSave, + }); + mainRecordId = existingMainId; + } else { + // ➕ 신규 등록: INSERT 실행 + console.log("➕ [handleUniversalFormModalTableSectionSave] 메인 테이블 INSERT 실행"); + mainSaveResult = await DynamicFormApi.saveFormData({ + screenId: screenId!, + tableName: tableName!, + data: mainRowToSave, + }); + mainRecordId = mainSaveResult.data?.id || null; + } + if (!mainSaveResult.success) { throw new Error(mainSaveResult.message || "메인 데이터 저장 실패"); } - mainRecordId = mainSaveResult.data?.id || null; console.log("✅ [handleUniversalFormModalTableSectionSave] 메인 테이블 저장 완료, ID:", mainRecordId); }