"use client" import * as React from "react" import { useState, useEffect, useCallback } from "react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Skeleton } from "@/components/ui/skeleton" import { Mail, Phone, User, Users } from "lucide-react" import { getQuotationContacts } from "../../service" interface QuotationContact { id: number contactId: number contactName: string contactPosition: string | null contactEmail: string contactPhone: string | null contactCountry: string | null isPrimary: boolean createdAt: Date } interface QuotationContactsViewDialogProps { open: boolean onOpenChange: (open: boolean) => void quotationId: number | null vendorName?: string } export function QuotationContactsViewDialog({ open, onOpenChange, quotationId, vendorName }: QuotationContactsViewDialogProps) { const [contacts, setContacts] = useState([]) const [isLoading, setIsLoading] = useState(false) // 담당자 정보 로드 const loadQuotationContacts = useCallback(async () => { if (!quotationId) return setIsLoading(true) try { const result = await getQuotationContacts(quotationId) if (result.success) { setContacts(result.data || []) } else { console.error("담당자 정보 로드 실패:", result.error) setContacts([]) } } catch (error) { console.error("담당자 정보 로드 오류:", error) setContacts([]) } finally { setIsLoading(false) } }, [quotationId]) // Dialog가 열릴 때 데이터 로드 useEffect(() => { if (open && quotationId) { loadQuotationContacts() } }, [open, quotationId, loadQuotationContacts]) // Dialog가 닫힐 때 상태 초기화 useEffect(() => { if (!open) { setContacts([]) } }, [open]) return ( RFQ 발송 담당자 목록 {vendorName && ( {vendorName} )} 에게 발송된 RFQ의 담당자 정보입니다.
{isLoading ? (
{[1, 2, 3].map((i) => ( ))}
) : contacts.length === 0 ? (

발송된 담당자 정보가 없습니다.

아직 RFQ가 발송되지 않았거나 담당자 정보가 기록되지 않았습니다.

) : (
{contacts.map((contact) => (
{contact.contactName} {contact.isPrimary && ( 주담당자 )}
{contact.contactPosition && (

{contact.contactPosition}

)} {contact.contactCountry && (

{contact.contactCountry}

)}
{contact.contactEmail}
{contact.contactPhone && (
{contact.contactPhone}
)}
발송일: {new Date(contact.createdAt).toLocaleDateString('ko-KR')}
))}
총 {contacts.length}명의 담당자에게 발송됨
)}
) }