"use client" import * as React from "react" import { Loader, Trash } from "lucide-react" import { toast } from "sonner" import { useMediaQuery } from "@/hooks/use-media-query" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer" import { deleteDocumentClassOption } from "@/lib/docu-list-rule/document-class/service" import { documentClassOptions } from "@/db/schema/documentClasses" interface DeleteDocumentClassOptionDialogProps extends React.ComponentPropsWithoutRef { options: typeof documentClassOptions.$inferSelect[] showTrigger?: boolean onSuccess?: () => void } export function DeleteDocumentClassOptionDialog({ options, showTrigger = true, onSuccess, ...props }: DeleteDocumentClassOptionDialogProps) { const [isDeletePending, startDeleteTransition] = React.useTransition() const isDesktop = useMediaQuery("(min-width: 640px)") function onDelete() { startDeleteTransition(async () => { try { for (const option of options) { const result = await deleteDocumentClassOption(option.id) if (!result.success) { toast.error(`Document Class 옵션 삭제 실패: ${result.error}`) return } } props.onOpenChange?.(false) toast.success("Document Class 옵션이 성공적으로 삭제되었습니다.") onSuccess?.() } catch (error) { console.error("Delete error:", error) toast.error("Document Class 옵션 삭제 중 오류가 발생했습니다.") } }) } if (isDesktop) { return ( {showTrigger ? ( ) : null} 정말로 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다. 선택된{" "} {options.length} 개의 Document Class 옵션을 서버에서 영구적으로 삭제합니다. ) } return ( {showTrigger ? ( ) : null} 정말로 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다. 선택된{" "} {options.length} 개의 Document Class 옵션을 서버에서 영구적으로 삭제합니다. ) }