"use client" import * as React from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { useToast } from "@/hooks/use-toast" import { deletePQSubmissionAction } from "@/lib/pq/service" import { useRouter } from "next/navigation" interface PQDeleteDialogProps { pqSubmissionId: number status: string children: React.ReactNode } export function PQDeleteDialog({ pqSubmissionId, status, children }: PQDeleteDialogProps) { const [open, setOpen] = React.useState(false) const [isDeleting, setIsDeleting] = React.useState(false) const { toast } = useToast() const router = useRouter() // REQUESTED 상태가 아니면 삭제 버튼 비활성화 const canDelete = status === "REQUESTED" const handleDelete = async () => { if (!canDelete) { toast({ title: "삭제 불가", description: "요청됨 상태가 아닌 PQ는 삭제할 수 없습니다.", variant: "destructive", }) return } try { setIsDeleting(true) const result = await deletePQSubmissionAction(pqSubmissionId) if (result.success) { toast({ title: "삭제 완료", description: "PQ가 성공적으로 삭제되었습니다.", }) setOpen(false) router.refresh() } else { toast({ title: "삭제 실패", description: result.error || "PQ 삭제 중 오류가 발생했습니다.", variant: "destructive", }) } } catch (error) { console.error("PQ 삭제 오류:", error) toast({ title: "삭제 실패", description: "PQ 삭제 중 오류가 발생했습니다.", variant: "destructive", }) } finally { setIsDeleting(false) } } return (
{children}
PQ 삭제 다음 PQ를 삭제하시겠습니까?
협력업체가 입력한 답변이 모두 삭제됩니다. 이 작업은 되돌릴 수 없습니다.
{!canDelete && (

요청됨 상태가 아닌 PQ는 삭제할 수 없습니다.

)}
) }