"use client" import * as React from "react" import { type Row } from "@tanstack/react-table" 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 { removeCandidates } from "../service" import { VendorCandidatesWithVendorInfo } from "@/db/schema" import { useSession } from "next-auth/react" // next-auth 세션 훅 interface DeleteCandidatesDialogProps extends React.ComponentPropsWithoutRef { candidates: Row["original"][] showTrigger?: boolean onSuccess?: () => void } export function DeleteCandidatesDialog({ candidates, showTrigger = true, onSuccess, ...props }: DeleteCandidatesDialogProps) { const [isDeletePending, startDeleteTransition] = React.useTransition() const isDesktop = useMediaQuery("(min-width: 640px)") const { data: session, status } = useSession() function onDelete() { startDeleteTransition(async () => { if (!session?.user?.id) { toast.error("인증 오류. 로그인 정보를 찾을 수 없습니다.") return } const userId = Number(session.user.id) const { error } = await removeCandidates({ ids: candidates.map((candidate) => candidate.id), }, userId) if (error) { toast.error(error) return } props.onOpenChange?.(false) toast.success("Candidates deleted") onSuccess?.() }) } if (isDesktop) { return ( {showTrigger ? ( ) : null} Are you absolutely sure? This action cannot be undone. This will permanently delete your{" "} {candidates.length} {candidates.length === 1 ? " candidate" : " candidates"} from our servers. ) } return ( {showTrigger ? ( ) : null} Are you absolutely sure? This action cannot be undone. This will permanently delete your{" "} {candidates.length} {candidates.length === 1 ? " candidate" : " candidates"} from our servers. ) }