"use client" import * as React from "react" import { Trash2, AlertTriangle } from "lucide-react" import { toast } from "sonner" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Badge } from "@/components/ui/badge" import { ScrollArea } from "@/components/ui/scroll-area" import { EvaluationTargetWithDepartments } from "@/db/schema" import { deleteEvaluationTargets } from "../service" interface DeleteTargetsDialogProps { open: boolean onOpenChange: (open: boolean) => void targets: EvaluationTargetWithDepartments[] onSuccess?: () => void } export function DeleteTargetsDialog({ open, onOpenChange, targets, onSuccess }: DeleteTargetsDialogProps) { const [isLoading, setIsLoading] = React.useState(false) // PENDING 상태인 타겟들만 필터링 (추가 안전장치) const pendingTargets = React.useMemo(() => { return targets.filter(target => target.status === "PENDING") }, [targets]) const handleDelete = async () => { if (pendingTargets.length === 0) { toast.error("삭제할 수 있는 평가 대상이 없습니다.") return } setIsLoading(true) try { const targetIds = pendingTargets.map(target => target.id) const result = await deleteEvaluationTargets(targetIds) if (result.success) { toast.success(result.message || "평가 대상이 성공적으로 삭제되었습니다.", { description: `${result.deletedCount || pendingTargets.length}개의 항목이 삭제되었습니다.` }) onSuccess?.() onOpenChange(false) } else { toast.error(result.error || "삭제 중 오류가 발생했습니다.") } } catch (error) { console.error('Error deleting targets:', error) toast.error("삭제 중 오류가 발생했습니다.") } finally { setIsLoading(false) } } const handleCancel = () => { if (!isLoading) { onOpenChange(false) } } return ( 평가 대상 삭제 선택한 평가 대상을 영구적으로 삭제합니다. 이 작업은 되돌릴 수 없습니다. {pendingTargets.length > 0 ? (
{/* 경고 메시지 */}

주의: 삭제된 데이터는 복구할 수 없습니다

PENDING 상태의 평가 대상만 삭제할 수 있습니다. 확정(CONFIRMED)되거나 제외(EXCLUDED)된 대상은 삭제할 수 없습니다.

{/* 삭제 대상 목록 */}

삭제될 평가 대상 ({pendingTargets.length}개)

삭제 예정
{pendingTargets.map((target) => (
{target.vendorName || '알 수 없는 업체'}
• {target.evaluationYear}년
{target.status}
))}
) : (

삭제할 수 있는 평가 대상이 없습니다.

PENDING 상태의 대상만 삭제할 수 있습니다.

)}
) }