From 53ad72732f781e6c6d5ddb3776ea47aec010af8e Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 4 Aug 2025 09:39:21 +0000 Subject: (최겸) PQ/실사 수정 및 개발 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/pq-input/pq-delete-dialog.tsx | 122 +++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 components/pq-input/pq-delete-dialog.tsx (limited to 'components/pq-input/pq-delete-dialog.tsx') diff --git a/components/pq-input/pq-delete-dialog.tsx b/components/pq-input/pq-delete-dialog.tsx new file mode 100644 index 00000000..2cb7c1d8 --- /dev/null +++ b/components/pq-input/pq-delete-dialog.tsx @@ -0,0 +1,122 @@ +"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는 삭제할 수 없습니다. +

+
+ )} + + + + + +
+
+ ) +} \ No newline at end of file -- cgit v1.2.3