"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 () => { try { console.log("🔍 [DEBUG] 승인 요청 시작 - vendors:", vendors.map(v => ({ id: v.id, vendorName: v.vendorName, email: v.email }))); console.log("🔍 [DEBUG] 세션 정보:", { userId: session.user.id, userType: typeof session.user.id }); const { error } = await approveVendors({ ids: vendors.map((vendor) => vendor.id), userId: Number(session.user.id) }) if (error) { console.error("🚨 [DEBUG] 승인 처리 에러:", error); toast.error(error) return } console.log("✅ [DEBUG] 승인 처리 성공"); props.onOpenChange?.(false) toast.success("Vendors successfully approved for review") onSuccess?.() } catch (error) { console.error("🚨 [DEBUG] 예상치 못한 에러:", error); toast.error("예상치 못한 오류가 발생했습니다.") } }) } 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. ) }