"use client" import { EsgEvaluationsView } from "@/db/schema" import React from "react" import { toast } from "sonner" import { useTransition } from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { ScrollArea } from "@/components/ui/scroll-area" import { Badge } from "@/components/ui/badge" // 서비스 함수 import import { deleteEsgEvaluationsBatch, softDeleteEsgEvaluationsBatch } from "../service" interface EsgEvaluationBatchDeleteDialogProps { open: boolean onOpenChange: (open: boolean) => void evaluations: EsgEvaluationsView[] onSuccess: () => void useSoftDelete?: boolean // 소프트 삭제 사용 여부 } export function EsgEvaluationBatchDeleteDialog({ open, onOpenChange, evaluations, onSuccess, useSoftDelete = false, }: EsgEvaluationBatchDeleteDialogProps) { const [isPending, startTransition] = useTransition() const evaluationCount = evaluations.length const isSingle = evaluationCount === 1 const handleDelete = async () => { if (evaluationCount === 0) return startTransition(async () => { try { const ids = evaluations.map((evaluation) => evaluation.id) let result if (useSoftDelete) { result = await softDeleteEsgEvaluationsBatch(ids) } else { result = await deleteEsgEvaluationsBatch(ids) } // 성공 메시지 if (result.failed > 0) { toast.warning( `${result.deleted}개 삭제 완료, ${result.failed}개 실패했습니다.` ) } else { toast.success( isSingle ? '평가표가 삭제되었습니다.' : `${result.deleted}개의 평가표가 삭제되었습니다.` ) } onSuccess() onOpenChange(false) } catch (error) { console.error('Error deleting evaluations:', error) toast.error( error instanceof Error ? error.message : '삭제 중 오류가 발생했습니다.' ) } }) } if (evaluationCount === 0) return null return ( {isSingle ? '평가표 삭제' : `평가표 일괄 삭제 (${evaluationCount}개)`} {isSingle ? ( <> 정말로 이 ESG 평가표를 삭제하시겠습니까?
이 작업은 되돌릴 수 없으며, 연관된 모든 평가항목과 답변옵션들도 함께 삭제됩니다. ) : ( <> 선택된 {evaluationCount}개의 ESG 평가표를 삭제하시겠습니까?
이 작업은 되돌릴 수 없으며, 연관된 모든 평가항목과 답변옵션들도 함께 삭제됩니다. )}
{/* 삭제될 평가표 목록 */}

{isSingle ? '삭제될 평가표:' : '삭제될 평가표 목록:'}

5 ? "h-[200px]" : "h-auto"}>
{evaluations.map((evaluation, index) => (
{evaluation.serialNumber} {evaluation.category}

{evaluation.inspectionItem}

평가항목: {evaluation.totalEvaluationItems}개 답변옵션: {evaluation.totalAnswerOptions}개
))}
) }