"use client" import * as React from "react" import { type Row } from "@tanstack/react-table" import { Loader, Check } 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 { Vendor } from "@/db/schema/vendors" import { approveVendors } from "../service" import { useSession } from "next-auth/react" interface ApprovalVendorDialogProps extends React.ComponentPropsWithoutRef { vendors: Row["original"][] showTrigger?: boolean onSuccess?: () => void } export function ApproveVendorsDialog({ vendors, showTrigger = true, onSuccess, ...props }: ApprovalVendorDialogProps) { const [isApprovePending, startApproveTransition] = React.useTransition() const isDesktop = useMediaQuery("(min-width: 640px)") const { data: session } = useSession() function onApprove() { if (!session?.user?.id) { toast.error("사용자 인증 정보를 찾을 수 없습니다.") return } startApproveTransition(async () => { const { error } = await approveVendors({ ids: vendors.map((vendor) => vendor.id), userId: Number(session.user.id) }) if (error) { toast.error(error) return } props.onOpenChange?.(false) toast.success("Vendors successfully approved for review") onSuccess?.() }) } if (isDesktop) { return ( {showTrigger ? ( ) : null} Confirm Vendor Approval Are you sure you want to approve{" "} {vendors.length} {vendors.length === 1 ? " vendor" : " vendors"}? After approval, vendors will be notified and can login to submit PQ information. ) } return ( {showTrigger ? ( ) : null} Confirm Vendor Approval Are you sure you want to approve{" "} {vendors.length} {vendors.length === 1 ? " vendor" : " vendors"}? After approval, vendors will be notified and can login to submit PQ information. ) }