diff --git a/src/components/sync/DiffTable.tsx b/src/components/sync/DiffTable.tsx new file mode 100644 index 0000000..b64471b --- /dev/null +++ b/src/components/sync/DiffTable.tsx @@ -0,0 +1,118 @@ +'use client' +import { useState } from 'react' +import type { SyncChange, SyncChangeType, DiffResult } from '@/types/sync' + +interface DiffTableProps { + diff: DiffResult +} + +const TYPE_CONFIG: Record = { + create: { label: '🟢 Nouveau', color: 'text-green-400', bg: 'bg-green-950/30' }, + update: { label: '🔵 Mis à jour', color: 'text-blue-400', bg: 'bg-blue-950/30' }, + deactivate: { label: '🔴 Désactivé', color: 'text-red-400', bg: 'bg-red-950/30' }, + unchanged: { label: '⚫ Inchangé', color: 'text-slate-500', bg: '' }, +} + +const PAGE_SIZE = 20 + +export function DiffTable({ diff }: DiffTableProps) { + const [filter, setFilter] = useState('all') + const [page, setPage] = useState(0) + + const visible = diff.changes.filter((c) => c.type !== 'unchanged') + const filtered = filter === 'all' ? visible : visible.filter((c) => c.type === filter) + const paginated = filtered.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE) + const totalPages = Math.ceil(filtered.length / PAGE_SIZE) + + return ( +
+ {/* Résumé */} +
+ {(['create', 'update', 'deactivate', 'unchanged'] as SyncChangeType[]).map((type) => ( + + {TYPE_CONFIG[type].label} : {diff.summary[type]} + + ))} +
+ + {/* Filtres */} +
+ {(['all', 'create', 'update', 'deactivate'] as const).map((f) => ( + + ))} +
+ + {/* Tableau */} + {paginated.length === 0 ? ( +

Aucun changement dans cette catégorie.

+ ) : ( +
+ + + + + + + + + + {paginated.map((change) => ( + + + + + + ))} + +
RefTypeChamps modifiés
{change.ref} + {TYPE_CONFIG[change.type].label} + + {change.type === 'update' && change.changedFields?.map((f) => ( + + {f.field} : + {f.from} + + {f.to} + + ))} + {change.type === 'create' && ( + {change.sheetProduct?.title} + )} + {change.type === 'deactivate' && ( + {change.shopifyProduct?.title} + )} +
+
+ )} + + {/* Pagination */} + {totalPages > 1 && ( +
+ + + {page + 1} / {totalPages} + + +
+ )} +
+ ) +}