summaryrefslogtreecommitdiff
path: root/lib/site-visit/site-visit-detail-dialog.tsx
blob: 7788454a49f8a95f01d3e2051b0f1bdf69f78bf3 (plain)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
"use client"

import * as React from "react"
import { format } from "date-fns"
import { ko } from "date-fns/locale"
import { FileText, Download } from "lucide-react"
import { toast } from "sonner"

import { Button } from "@/components/ui/button"
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog"
import { Separator } from "@/components/ui/separator"
import { formatDate } from "../utils"

interface SiteVisitRequest {
  id: number
  investigationId: number
  requesterId: number | null
  inspectionDuration: string | null
  requestedStartDate: Date | null
  requestedEndDate: Date | null
  shiAttendees: Record<string, unknown> | null
  shiAttendeeDetails?: string | null
  vendorRequests: Record<string, unknown> | null
  additionalRequests: string | null
  status: string
  sentAt: Date | null
  createdAt: Date
  updatedAt: Date
  
  // 실사정보
  investigationMethod: string | null // QM담당자가 작성한 실사방법
  investigationAddress: string | null
  investigationNotes: string | null
  forecastedAt: Date | null
  actualAt: Date | null
  result: string | null
  resultNotes: string | null
  
  // PQ 정보
  pqItems: string | null | Array<{itemCode: string, itemName: string}>
  
  // 요청자 정보
  requesterName: string | null
  requesterEmail: string | null
  requesterTitle: string | null
  
  // QM 매니저 정보
  qmManagerName: string | null
  qmManagerEmail: string | null
  qmManagerTitle: string | null
  
  // 협력업체 정보
  vendorInfo?: {
    id: number
    siteVisitRequestId: number
    factoryName: string
    factoryLocation: string
    factoryAddress: string
    factoryPicName: string
    factoryPicPhone: string
    factoryPicEmail: string
    factoryDirections: string | null
    accessProcedure: string | null
    hasAttachments: boolean
    otherInfo: string | null
    submittedAt: Date
    submittedBy: number
    createdAt: Date
    updatedAt: Date
  } | null

  // SHI 첨부파일
  shiAttachments?: Array<{
    id: number
    siteVisitRequestId: number
    vendorSiteVisitInfoId: number | null
    fileName: string
    originalFileName: string
    filePath: string
    fileSize: number
    mimeType: string
    createdAt: Date
    updatedAt: Date
  }> | null
}

interface SiteVisitDetailDialogProps {
  isOpen: boolean
  onOpenChange: (open: boolean) => void
  selectedRequest: SiteVisitRequest | null
}

export function SiteVisitDetailDialog({
  isOpen,
  onOpenChange,
  selectedRequest,
}: SiteVisitDetailDialogProps) {

  return (
    <Dialog open={isOpen} onOpenChange={onOpenChange}>
      <DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
        <DialogHeader>
          <DialogTitle>방문실사 상세 정보</DialogTitle>
          <DialogDescription>
            작성한 방문실사 정보의 상세 내용입니다.
          </DialogDescription>
        </DialogHeader>
        
        {selectedRequest && (
          <div className="space-y-6">
            {/* 기본 정보 */}

            {/* 협력업체 정보 */}
            {selectedRequest.vendorInfo && (
              <>
                <Separator />
                <div>
                  <h3 className="font-semibold mb-2">작성한 협력업체 정보</h3>
                  <div className="bg-muted p-4 rounded-md">
                    <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                      <div className="space-y-4">
                        <div>
                          <h4 className="font-semibold mb-2">공장 기본 정보</h4>
                          <div className="space-y-2 text-sm">
                            <div><span className="font-medium">공장명:</span> {selectedRequest.vendorInfo.factoryName}</div>
                            <div><span className="font-medium">공장위치:</span> {selectedRequest.vendorInfo.factoryLocation}</div>
                            <div><span className="font-medium">공장주소:</span> {selectedRequest.vendorInfo.factoryAddress}</div>
                          </div>
                        </div>
                        
                        <div>
                          <h4 className="font-semibold mb-2">공장 담당자 정보</h4>
                          <div className="space-y-2 text-sm">
                            <div><span className="font-medium">이름:</span> {selectedRequest.vendorInfo.factoryPicName}</div>
                            <div><span className="font-medium">전화번호:</span> {selectedRequest.vendorInfo.factoryPicPhone}</div>
                            <div><span className="font-medium">이메일:</span> {selectedRequest.vendorInfo.factoryPicEmail}</div>
                          </div>
                        </div>
                      </div>
                      
                      <div className="space-y-4">
                        {selectedRequest.vendorInfo.factoryDirections && (
                          <div>
                            <h4 className="font-semibold mb-2">공장 가는 법</h4>
                            <div className="bg-background p-3 rounded-md">
                              <p className="text-sm whitespace-pre-wrap">{selectedRequest.vendorInfo.factoryDirections}</p>
                            </div>
                          </div>
                        )}
                        
                        {selectedRequest.vendorInfo.accessProcedure && (
                          <div>
                            <h4 className="font-semibold mb-2">공장 출입절차</h4>
                            <div className="bg-background p-3 rounded-md">
                              <p className="text-sm whitespace-pre-wrap">{selectedRequest.vendorInfo.accessProcedure}</p>
                            </div>
                          </div>
                        )}
                      </div>
                    </div>
                    
                    {/* 기타 정보 */}
                    {selectedRequest.vendorInfo.otherInfo && (
                      <div className="mt-6">
                        <h4 className="font-semibold mb-2">기타 정보</h4>
                        <div className="bg-background p-3 rounded-md">
                          <p className="text-sm whitespace-pre-wrap">{selectedRequest.vendorInfo.otherInfo}</p>
                        </div>
                      </div>
                    )}
                    
                    {/* 제출 정보 */}
                    <div className="mt-6">
                      <h4 className="font-semibold mb-2">제출 정보</h4>
                      <div className="space-y-2 text-sm">
                        <div><span className="font-medium">제출일:</span> {formatDate(selectedRequest.vendorInfo.submittedAt, "kr")}</div>
                        <div><span className="font-medium">첨부파일:</span> {selectedRequest.vendorInfo.hasAttachments ? "있음" : "없음"}</div>
                      </div>
                    </div>
                  </div>
                </div>
              </>
            )}

            <Separator />

            {/* SHI 첨부파일 */}
            {selectedRequest.shiAttachments && selectedRequest.shiAttachments.length > 0 && (
              <>
                <div>
                  <h3 className="font-semibold mb-2">SHI 첨부파일 ({selectedRequest.shiAttachments.length}개)</h3>
                  <div className="bg-muted p-4 rounded-md">
                    <div className="space-y-2">
                      {selectedRequest.shiAttachments.map((attachment) => (
                        <div key={attachment.id} className="flex items-center justify-between p-2 border rounded-md">
                          <div className="flex items-center space-x-2 flex-1 min-w-0">
                            <FileText className="h-4 w-4 text-muted-foreground" />
                            <span className="text-sm truncate">{attachment.originalFileName}</span>
                            <span className="text-xs text-muted-foreground">
                              ({Math.round((attachment.fileSize || 0) / 1024)}KB)
                            </span>
                          </div>
                          <Button
                            type="button"
                            variant="outline"
                            size="sm"
                            className="p-2"
                            onClick={async () => {
                              try {
                                const { downloadFile } = await import('@/lib/file-download')
                                await downloadFile(attachment.filePath, attachment.originalFileName || '', {
                                  showToast: true,
                                  onError: (error) => {
                                    console.error('다운로드 오류:', error)
                                    toast.error("다운로드 실패: " + error)
                                  },
                                  onSuccess: (fileName, fileSize) => {
                                    console.log(`다운로드 성공: ${fileName} (${fileSize} bytes)`)
                                  }
                                })
                              } catch (error) {
                                console.error('다운로드 오류:', error)
                                toast.error("파일 다운로드 중 오류가 발생했습니다.")
                              }
                            }}
                            aria-label="파일 다운로드"
                          >
                            <Download className="h-4 w-4" />
                          </Button>
                        </div>
                      ))}
                    </div>
                  </div>
                </div>
              </>
            )}

            {/* 추가 요청사항 */}
            {selectedRequest.additionalRequests && (
              <>
                <div>
                  <h3 className="font-semibold mb-2">SHI 추가 요청사항</h3>
                  <div className="bg-muted p-4 rounded-md">
                    <p className="text-sm whitespace-pre-wrap">{selectedRequest.additionalRequests}</p>
                  </div>
                </div>
                <Separator />
              </>
            )}
          </div>
        )}
      </DialogContent>
    </Dialog>
  )
}