"use client"; import React, { useState, useEffect } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; import apiClient from "@/lib/api/client"; interface BomHistoryItem { id: string; revision: string; version: string; change_type: string; change_description: string; changed_by: string; changed_date: string; } interface BomHistoryModalProps { open: boolean; onOpenChange: (open: boolean) => void; bomId: string | null; tableName?: string; } const CHANGE_TYPE_STYLE: Record = { "등록": "bg-blue-50 text-blue-600 ring-blue-200", "수정": "bg-amber-50 text-amber-600 ring-amber-200", "추가": "bg-emerald-50 text-emerald-600 ring-emerald-200", "삭제": "bg-red-50 text-red-600 ring-red-200", }; export function BomHistoryModal({ open, onOpenChange, bomId, tableName = "bom_history" }: BomHistoryModalProps) { const [history, setHistory] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { if (open && bomId) { loadHistory(); } }, [open, bomId]); const loadHistory = async () => { if (!bomId) return; setLoading(true); try { const res = await apiClient.get(`/bom/${bomId}/history`, { params: { tableName } }); if (res.data?.success) { setHistory(res.data.data || []); } } catch (error) { console.error("[BomHistory] 로드 실패:", error); } finally { setLoading(false); } }; const formatDate = (dateStr: string) => { if (!dateStr) return "-"; try { return new Date(dateStr).toLocaleString("ko-KR", { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", }); } catch { return dateStr; } }; return ( 이력 관리 BOM 변경 이력을 확인합니다
{loading ? (
) : history.length === 0 ? (

이력이 없습니다

) : ( {history.map((item, idx) => ( ))}
차수 버전 변경구분 변경내용 변경자 변경일시
{item.revision || "-"} {item.version || "-"} {item.change_type} {item.change_description || "-"} {item.changed_by || "-"} {formatDate(item.changed_date)}
)}
); }