"use client"; import * as React from "react"; import { Trash2, AlertTriangle } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Badge } from "@/components/ui/badge"; import { ScrollArea } from "@/components/ui/scroll-area"; import { useToast } from "@/hooks/use-toast"; import { deleteTechVendorPossibleItems } from "@/lib/tech-vendor-possible-items/service"; interface TechVendorPossibleItemsData { id: number; vendorId: number; vendorCode: string | null; vendorName: string; techVendorType: string; itemCode: string; itemList: string | null; workType: string | null; shipTypes: string | null; subItemList: string | null; createdAt: Date; updatedAt: Date; } interface DeletePossibleItemsDialogProps { selectedItems: TechVendorPossibleItemsData[]; children?: React.ReactNode; onSuccess?: () => void; } export function DeletePossibleItemsDialog({ selectedItems, children, onSuccess }: DeletePossibleItemsDialogProps) { const { toast } = useToast(); const [open, setOpen] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false); const handleDelete = async () => { if (selectedItems.length === 0) return; try { setIsLoading(true); const selectedIds = selectedItems.map(item => item.id); const result = await deleteTechVendorPossibleItems(selectedIds); if (result.success) { toast({ title: "성공", description: `${selectedIds.length}개의 아이템이 삭제되었습니다.`, }); setOpen(false); onSuccess?.(); } else { toast({ title: "오류", description: result.error || "삭제 중 오류가 발생했습니다.", variant: "destructive", }); } } catch (error) { console.error("Delete error:", error); toast({ title: "오류", description: "삭제 중 오류가 발생했습니다.", variant: "destructive", }); } finally { setIsLoading(false); } }; const parseVendorTypes = (vendorType: string): string[] => { try { return JSON.parse(vendorType); } catch { return vendorType.split(',').map(t => t.trim()); } }; return ( {children || ( )} 아이템 삭제 확인 선택한 {selectedItems.length}개의 벤더-아이템 조합을 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다.
삭제될 아이템 목록:
{selectedItems.map((item) => (
{item.vendorName} ({item.vendorCode})
아이템코드: {item.itemCode}
{item.itemList && (
아이템리스트: {item.itemList}
)} {item.workType && (
공종: {item.workType}
)}
{parseVendorTypes(item.techVendorType).map((type, index) => ( {type} ))}
))}
); }