diff options
Diffstat (limited to 'lib/tech-vendors/table/delete-tech-vendors-dialog.tsx')
| -rw-r--r-- | lib/tech-vendors/table/delete-tech-vendors-dialog.tsx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/tech-vendors/table/delete-tech-vendors-dialog.tsx b/lib/tech-vendors/table/delete-tech-vendors-dialog.tsx new file mode 100644 index 00000000..4fd3f32a --- /dev/null +++ b/lib/tech-vendors/table/delete-tech-vendors-dialog.tsx @@ -0,0 +1,80 @@ +"use client" + +import * as React from "react" +import { toast } from "sonner" +import { Trash2 } from "lucide-react" + +import { Button } from "@/components/ui/button" +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@/components/ui/alert-dialog" + +import { deleteTechVendor } from "../service" +import type { TechVendor } from "@/db/schema/techVendors" + +interface DeleteTechVendorDialogProps { + vendor: TechVendor + onSuccess?: () => void +} +// 임시 삭제 버튼 +export function DeleteTechVendorDialog({ vendor, onSuccess }: DeleteTechVendorDialogProps) { + const [isDeleting, setIsDeleting] = React.useState(false) + + const handleDelete = async () => { + setIsDeleting(true) + try { + const result = await deleteTechVendor(vendor.id) + + if (result.success) { + toast.success("벤더가 성공적으로 삭제되었습니다.") + onSuccess?.() + } else { + toast.error(result.error || "벤더 삭제 중 오류가 발생했습니다.") + } + } catch (error) { + console.error("벤더 삭제 오류:", error) + toast.error("벤더 삭제 중 오류가 발생했습니다.") + } finally { + setIsDeleting(false) + } + } + + return ( + <AlertDialog> + <AlertDialogTrigger asChild> + <Button variant="ghost" size="sm" className="text-red-600 hover:text-red-700 hover:bg-red-50"> + <Trash2 className="size-4 mr-2" /> + 삭제 + </Button> + </AlertDialogTrigger> + <AlertDialogContent> + <AlertDialogHeader> + <AlertDialogTitle>벤더 삭제</AlertDialogTitle> + <AlertDialogDescription> + <strong>{vendor.vendorName}</strong> 벤더를 정말 삭제하시겠습니까? + <br /> + 이 작업은 되돌릴 수 없으며, 관련된 모든 데이터(담당자, 아이템 등)가 함께 삭제됩니다. + </AlertDialogDescription> + </AlertDialogHeader> + <AlertDialogFooter> + <AlertDialogCancel>취소</AlertDialogCancel> + <AlertDialogAction + onClick={handleDelete} + disabled={isDeleting} + className="bg-red-600 hover:bg-red-700" + > + {isDeleting ? "삭제 중..." : "삭제"} + </AlertDialogAction> + </AlertDialogFooter> + </AlertDialogContent> + </AlertDialog> + ) +} |
