1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
"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
contactTitle: 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<QuotationContact[]>([])
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 (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-2xl max-h-[70vh] overflow-hidden flex flex-col">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Users className="size-5" />
RFQ 발송 담당자 목록
</DialogTitle>
<DialogDescription>
{vendorName && (
<span className="font-medium">{vendorName}</span>
)} 에게 발송된 RFQ의 담당자 정보입니다.
</DialogDescription>
</DialogHeader>
<div className="flex-1 overflow-y-auto">
{isLoading ? (
<div className="space-y-3">
{[1, 2, 3].map((i) => (
<Skeleton key={i} className="h-20 w-full" />
))}
</div>
) : contacts.length === 0 ? (
<div className="text-center py-8 text-muted-foreground">
<Mail className="size-12 mx-auto mb-2 opacity-50" />
<p>발송된 담당자 정보가 없습니다.</p>
<p className="text-sm">아직 RFQ가 발송되지 않았거나 담당자 정보가 기록되지 않았습니다.</p>
</div>
) : (
<div className="space-y-3">
{contacts
.filter((contact) => contact.contactTitle) // contactTitle이 있는 담당자만 필터링 (체크표시된 담당자)
.map((contact) => (
<div
key={contact.id}
className="flex items-center justify-between p-4 border rounded-lg bg-gray-50"
>
<div className="flex items-center gap-3">
<User className="size-4 text-muted-foreground" />
<div>
<div className="flex items-center gap-2">
<span className="font-medium">{contact.contactName}</span>
{contact.isPrimary && (
<Badge variant="secondary" className="text-xs">
주담당자
</Badge>
)}
</div>
{contact.contactPosition && (
<p className="text-sm text-muted-foreground">
{contact.contactPosition}
</p>
)}
{contact.contactTitle && (
<p className="text-sm text-muted-foreground">
{contact.contactTitle}
</p>
)}
{contact.contactCountry && (
<p className="text-xs text-muted-foreground">
{contact.contactCountry}
</p>
)}
</div>
</div>
<div className="flex flex-col items-end gap-1 text-sm">
<div className="flex items-center gap-1">
<Mail className="size-4 text-muted-foreground" />
<span>{contact.contactEmail}</span>
</div>
{contact.contactPhone && (
<div className="flex items-center gap-1">
<Phone className="size-4 text-muted-foreground" />
<span>{contact.contactPhone}</span>
</div>
)}
<div className="text-xs text-muted-foreground">
발송일: {new Date(contact.createdAt).toLocaleDateString('ko-KR')}
</div>
</div>
</div>
))}
<div className="text-center pt-4 text-sm text-muted-foreground border-t">
총 {contacts.filter((contact) => contact.contactTitle).length}명의 담당자에게 발송됨
</div>
</div>
)}
</div>
<div className="flex justify-end pt-4">
<Button variant="outline" onClick={() => onOpenChange(false)}>
닫기
</Button>
</div>
</DialogContent>
</Dialog>
)
}
|