diff --git a/frontend/lib/registry/components/repeat-screen-modal/RepeatScreenModalComponent.tsx b/frontend/lib/registry/components/repeat-screen-modal/RepeatScreenModalComponent.tsx index 360a1585..662dacea 100644 --- a/frontend/lib/registry/components/repeat-screen-modal/RepeatScreenModalComponent.tsx +++ b/frontend/lib/registry/components/repeat-screen-modal/RepeatScreenModalComponent.tsx @@ -1154,26 +1154,70 @@ export function RepeatScreenModalComponent({ } }; - // πŸ†• v3.1: μ™ΈλΆ€ ν…Œμ΄λΈ” ν–‰ μ‚­μ œ μ‹€ν–‰ (μ†Œν”„νŠΈ μ‚­μ œ - _isDeleted ν”Œλž˜κ·Έ μ„€μ •) - const handleDeleteExternalRow = (cardId: string, rowId: string, contentRowId: string) => { + // πŸ†• v3.14: μ™ΈλΆ€ ν…Œμ΄λΈ” ν–‰ μ‚­μ œ μ‹€ν–‰ (μ¦‰μ‹œ DELETE API 호좜) + const handleDeleteExternalRow = async (cardId: string, rowId: string, contentRowId: string) => { const key = `${cardId}-${contentRowId}`; - setExternalTableData((prev) => { - const newData = { - ...prev, - [key]: (prev[key] || []).map((row) => - row._rowId === rowId - ? { ...row, _isDeleted: true, _isDirty: true } - : row - ), - }; - - // πŸ†• v3.5: ν–‰ μ‚­μ œ μ‹œ 집계 μž¬κ³„μ‚° (μ‚­μ œλœ ν–‰ μ œμ™Έ) - setTimeout(() => { - recalculateAggregationsWithExternalData(newData); - }, 0); - - return newData; - }); + const rows = externalTableData[key] || []; + const targetRow = rows.find((row) => row._rowId === rowId); + + // κΈ°μ‘΄ DB 데이터인 경우 (idκ°€ μžˆλŠ” 경우) μ¦‰μ‹œ μ‚­μ œ + if (targetRow?._originalData?.id) { + try { + const contentRow = contentRows.find((r) => r.id === contentRowId); + const targetTable = contentRow?.tableCrud?.targetTable || contentRow?.tableDataSource?.sourceTable; + + if (!targetTable) { + console.error("[RepeatScreenModal] μ‚­μ œ λŒ€μƒ ν…Œμ΄λΈ”μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."); + return; + } + + console.log(`[RepeatScreenModal] DELETE API 호좜: ${targetTable}, id=${targetRow._originalData.id}`); + + // λ°±μ—”λ“œλŠ” λ°°μ—΄ ν˜•νƒœμ˜ 데이터λ₯Ό κΈ°λŒ€ν•¨ + await apiClient.request({ + method: "DELETE", + url: `/table-management/tables/${targetTable}/delete`, + data: [{ id: targetRow._originalData.id }], + }); + + console.log(`[RepeatScreenModal] DELETE 성곡: ${targetTable}, id=${targetRow._originalData.id}`); + + // 성곡 μ‹œ UIμ—μ„œ μ™„μ „νžˆ 제거 + setExternalTableData((prev) => { + const newData = { + ...prev, + [key]: prev[key].filter((row) => row._rowId !== rowId), + }; + + // ν–‰ μ‚­μ œ μ‹œ 집계 μž¬κ³„μ‚° + setTimeout(() => { + recalculateAggregationsWithExternalData(newData); + }, 0); + + return newData; + }); + } catch (error: any) { + console.error(`[RepeatScreenModal] DELETE μ‹€νŒ¨:`, error.response?.data || error.message); + // μ—λŸ¬ μ‹œμ—λ„ λ‹€μ΄μ–Όλ‘œκ·Έ λ‹«κΈ° + } + } else { + // μƒˆλ‘œ μΆ”κ°€λœ ν–‰ (아직 DB에 μ—†μŒ) - UIμ—μ„œλ§Œ 제거 + console.log(`[RepeatScreenModal] μƒˆ ν–‰ μ‚­μ œ (DB μ—†μŒ): rowId=${rowId}`); + setExternalTableData((prev) => { + const newData = { + ...prev, + [key]: prev[key].filter((row) => row._rowId !== rowId), + }; + + // ν–‰ μ‚­μ œ μ‹œ 집계 μž¬κ³„μ‚° + setTimeout(() => { + recalculateAggregationsWithExternalData(newData); + }, 0); + + return newData; + }); + } + setDeleteConfirmOpen(false); setPendingDeleteInfo(null); };