import { useState, useEffect } from 'react'; import { batchApi, type SyncDataPreviewResponse } from '../api/batchApi'; import LoadingSpinner from './LoadingSpinner'; interface Props { open: boolean; tableKey: string; tableName: string; onClose: () => void; } export default function SyncDataPreviewModal({ open, tableKey, tableName, onClose }: Props) { const [data, setData] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (!open || !tableKey) return; setLoading(true); setError(null); batchApi.getSyncDataPreview(tableKey, 10) .then(setData) .catch((e) => setError(e.message)) .finally(() => setLoading(false)); }, [open, tableKey]); if (!open) return null; return (
e.stopPropagation()} > {/* Header */}

{tableName}

{data ? `${data.targetSchema}.${data.targetTable} | 총 ${data.totalCount.toLocaleString()}건` : ''}

{/* Body */}
{loading && } {error && (

조회 실패: {error}

)} {!loading && !error && data && data.rows.length === 0 && (
데이터가 없습니다
)} {!loading && !error && data && data.rows.length > 0 && (
{data.columns.map((col) => ( ))} {data.rows.map((row, idx) => ( {data.columns.map((col) => ( ))} ))}
{col}
{formatCellValue(row[col])}
)}
{/* Footer */} {data && data.rows.length > 0 && (
최근 {data.rows.length}건 표시 (전체 {data.totalCount.toLocaleString()}건)
)}
); } function formatCellValue(value: unknown): string { if (value === null || value === undefined) return '-'; if (typeof value === 'object') return JSON.stringify(value); return String(value); }