summaryrefslogtreecommitdiff
path: root/lib/b-rfq/attachment/revision-dialog.tsx
blob: b1fe157635f28a6b170fdfb966af0e5025b9f273 (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
"use client"

import * as React from "react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
    Dialog,
    DialogContent,
    DialogDescription,
    DialogHeader,
    DialogTitle,
    DialogTrigger,
} from "@/components/ui/dialog"
import {
    Table,
    TableBody,
    TableCell,
    TableHead,
    TableHeader,
    TableRow,
} from "@/components/ui/table"
import { History, Download, Upload } from "lucide-react"
import { formatDate, formatBytes } from "@/lib/utils"
import { getAttachmentRevisions } from "../service"
import { AddRevisionDialog } from "./add-revision-dialog"

interface RevisionDialogProps {
    attachmentId: number
    currentRevision: string
    originalFileName: string
}

export function RevisionDialog({
    attachmentId,
    currentRevision,
    originalFileName
}: RevisionDialogProps) {
    const [open, setOpen] = React.useState(false)
    const [revisions, setRevisions] = React.useState<any[]>([])
    const [isLoading, setIsLoading] = React.useState(false)
    const [isAddRevisionOpen, setIsAddRevisionOpen] = React.useState(false)

    // 리비전 목록 로드
    const loadRevisions = async () => {
        setIsLoading(true)
        try {
            const result = await getAttachmentRevisions(attachmentId)

            if (result.success) {
                setRevisions(result.revisions)
            } else {
                console.error("Failed to load revisions:", result.message)
            }
        } catch (error) {
            console.error("Failed to load revisions:", error)
        } finally {
            setIsLoading(false)
        }
    }

    React.useEffect(() => {
        if (open) {
            loadRevisions()
        }
    }, [open, attachmentId])

    return (
        <>
          <Dialog open={open} onOpenChange={setOpen}>
            <DialogTrigger asChild>
              <Button variant="ghost" size="sm" className="gap-2">
                <History className="h-4 w-4" />
                {currentRevision}
              </Button>
            </DialogTrigger>
            
            <DialogContent className="sm:max-w-[800px]" style={{maxWidth:800}}>
              <DialogHeader>
                <DialogTitle className="flex items-center gap-2">
                  <History className="h-5 w-5" />
                  리비전 히스토리: {originalFileName}
                </DialogTitle>
                <DialogDescription>
                  이 문서의 모든 버전을 확인하고 관리할 수 있습니다.
                </DialogDescription>
              </DialogHeader>
    
              <div className="space-y-4">
                {/* 새 리비전 추가 버튼 */}
                <div className="flex justify-end">
                  <Button 
                    onClick={() => setIsAddRevisionOpen(true)} 
                    className="gap-2"
                  >
                    <Upload className="h-4 w-4" />
                    새 리비전 추가
                  </Button>
                </div>
    
                {/* 리비전 목록 */}
                {isLoading ? (
                  <div className="text-center py-8">리비전을 불러오는 중...</div>
                ) : (
                  <div className="border rounded-lg">
                    <Table>
                      <TableHeader>
                        <TableRow>
                          <TableHead>리비전</TableHead>
                          <TableHead>파일명</TableHead>
                          <TableHead>크기</TableHead>
                          <TableHead>업로드 일시</TableHead>
                          <TableHead>업로드자</TableHead>
                          <TableHead>코멘트</TableHead>
                          <TableHead>액션</TableHead>
                        </TableRow>
                      </TableHeader>
                      <TableBody>
                        {revisions.map((revision) => (
                          <TableRow key={revision.id}>
                            <TableCell>
                              <div className="flex items-center gap-2">
                                <Badge 
                                  variant={revision.isLatest ? "default" : "outline"}
                                >
                                  {revision.revisionNo}
                                </Badge>
                                {revision.isLatest && (
                                  <Badge variant="secondary" className="text-xs">
                                    최신
                                  </Badge>
                                )}
                              </div>
                            </TableCell>
                            
                            <TableCell>
                              <div>
                                <div className="font-medium">{revision.originalFileName}</div>
                              </div>
                            </TableCell>
                            
                            <TableCell>
                              {formatBytes(revision.fileSize)}
                            </TableCell>
                            
                            <TableCell>
                              {formatDate(revision.createdAt)}
                            </TableCell>
                            
                            <TableCell>
                              {revision.createdByName || "-"}
                            </TableCell>
                            
                            <TableCell>
                              <div className="max-w-[200px] truncate" title={revision.revisionComment}>
                                {revision.revisionComment || "-"}
                              </div>
                            </TableCell>
                            
                            <TableCell>
                              <Button
                                variant="ghost"
                                size="sm"
                                className="gap-2"
                                onClick={() => {
                                  // 파일 다운로드
                                  window.open(revision.filePath, '_blank')
                                }}
                              >
                                <Download className="h-4 w-4" />
                                다운로드
                              </Button>
                            </TableCell>
                          </TableRow>
                        ))}
                      </TableBody>
                    </Table>
                  </div>
                )}
              </div>
            </DialogContent>
          </Dialog>
          
          {/* 새 리비전 추가 다이얼로그 */}
          <AddRevisionDialog
            open={isAddRevisionOpen}
            onOpenChange={setIsAddRevisionOpen}
            attachmentId={attachmentId}
            currentRevision={currentRevision}
            originalFileName={originalFileName}
            onSuccess={() => {
              loadRevisions() // 리비전 목록 새로고침
            }}
          />
        </>
      )
    }