"use client"; import * as React from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Loader2, Eye, Globe, CheckCircle, Building2, Info } from "lucide-react"; import { cn } from "@/lib/utils"; import { toast } from "sonner"; import { getAvlVendorsForRfq } from "../service"; interface AvlVendor { id: number; vendorId: number | null; vendorName: string | null; vendorCode: string | null; avlVendorName: string | null; tier: string | null; headquarterLocation: string | null; manufacturingLocation: string | null; materialGroupCode: string; materialGroupName: string | null; packageName: string | null; isAgent: boolean; hasAvl: boolean; isBlacklist: boolean; isBcc: boolean; remark: string | null; } // 더 이상 계약 인터페이스 필요 없음 - 참조용으로만 사용 interface AvlVendorDialogProps { open: boolean; onOpenChange: (open: boolean) => void; rfqId: number; } export function AvlVendorDialog({ open, onOpenChange, rfqId, }: AvlVendorDialogProps) { const [isLoadingAvl, setIsLoadingAvl] = React.useState(false); const [avlVendors, setAvlVendors] = React.useState([]); const [existingVendorIds, setExistingVendorIds] = React.useState>(new Set()); // AVL 벤더 로드 (참조용) const loadAvlVendors = React.useCallback(async () => { setIsLoadingAvl(true); try { const result = await getAvlVendorsForRfq(rfqId); if (result.success && result.vendors) { setAvlVendors(result.vendors as AvlVendor[]); // 이미 RFQ에 추가된 벤더 ID 설정 (참조용) const existingIds = new Set(result.existingVendorIds || []); setExistingVendorIds(existingIds); if (result.vendors.length === 0) { toast.info("해당 프로젝트와 자재그룹에 대한 AVL 벤더가 없습니다."); } } else { toast.error(result.error || "AVL 데이터를 불러오는데 실패했습니다."); } } catch (error) { console.error("Failed to load AVL vendors:", error); toast.error("AVL 데이터를 불러오는데 실패했습니다."); } finally { setIsLoadingAvl(false); } }, [rfqId]); // 다이얼로그 열릴 때 데이터 로드 React.useEffect(() => { if (open) { loadAvlVendors(); } }, [open, loadAvlVendors]); // 초기화 React.useEffect(() => { if (!open) { setAvlVendors([]); setExistingVendorIds(new Set()); } }, [open]); // 더 이상 핸들러 함수나 필터링이 필요 없음 - 참조용으로만 사용 return ( AVL 벤더 목록 조회 동일한 자재그룹코드를 다루는 AVL 등록 벤더들의 목록을 확인할 수 있습니다. {isLoadingAvl ? (
) : (
{avlVendors.length === 0 ? ( 해당 프로젝트와 자재그룹에 대한 AVL 벤더가 없습니다. ) : ( AVL 등록 벤더 목록 총 {avlVendors.length}개 업체 동일한 자재그룹코드를 다루는 AVL 등록 벤더들의 정보입니다.
{avlVendors.map((vendor) => { const isInCurrentRfq = vendor.vendorId && existingVendorIds.has(vendor.vendorId); const isInternational = vendor.headquarterLocation && vendor.headquarterLocation !== "KR" && vendor.headquarterLocation !== "한국"; return (
{vendor.vendorName} {vendor.vendorCode && ( {vendor.vendorCode} )} {isInCurrentRfq && ( RFQ 참여중 )}
{vendor.tier && ( 등급: {vendor.tier} )} {isInternational ? ( {vendor.headquarterLocation} ) : ( 국내 )} {vendor.materialGroupName && ( {vendor.materialGroupName} )} {vendor.isAgent && ( Agent )}
{vendor.remark && (
{vendor.remark}
)}
{vendor.hasAvl && ( AVL )} {vendor.isBcc && ( BCC )} {vendor.isBlacklist && ( Blacklist )}
); })}
)}
)}
); }