"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" 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)") function onApprove() { startApproveTransition(async () => { const { error } = await approveVendors({ ids: vendors.map((vendor) => vendor.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. ) }