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
|
"use client"
import * as React from "react"
import { type Table } from "@tanstack/react-table"
import { useRouter } from "next/navigation"
import { useTransition } from "react"
import { Button } from "@/components/ui/button"
import { Plus, Send, RotateCcw, XCircle } from "lucide-react"
import { QuotationVendor, registerBidding, markAsDisposal, createRebidding } from "@/lib/bidding/detail/service"
import { BiddingDetailVendorCreateDialog } from "./bidding-detail-vendor-create-dialog"
import { Bidding } from "@/db/schema"
import { useToast } from "@/hooks/use-toast"
interface BiddingDetailVendorToolbarActionsProps {
table: Table<QuotationVendor>
biddingId: number
bidding: Bidding
onOpenItemsDialog: () => void
onOpenTargetPriceDialog: () => void
onOpenSelectionReasonDialog: () => void
onSuccess: () => void
}
export function BiddingDetailVendorToolbarActions({
table,
biddingId,
bidding,
onOpenItemsDialog,
onOpenTargetPriceDialog,
onOpenSelectionReasonDialog,
onSuccess
}: BiddingDetailVendorToolbarActionsProps) {
const router = useRouter()
const { toast } = useToast()
const [isPending, startTransition] = useTransition()
const [isCreateDialogOpen, setIsCreateDialogOpen] = React.useState(false)
const handleCreateVendor = () => {
setIsCreateDialogOpen(true)
}
const handleRegister = () => {
// 상태 검증
if (bidding.status !== 'bidding_generated') {
toast({
title: '실행 불가',
description: '입찰 등록은 입찰 생성 상태에서만 가능합니다.',
variant: 'destructive',
})
return
}
if (!confirm('입찰을 등록하시겠습니까?')) return
startTransition(async () => {
const result = await registerBidding(bidding.id, 'current-user') // TODO: 실제 사용자 ID
if (result.success) {
toast({
title: '성공',
description: result.message,
})
router.refresh()
} else {
toast({
title: '오류',
description: result.error,
variant: 'destructive',
})
}
})
}
const handleMarkAsDisposal = () => {
// 상태 검증
if (bidding.status !== 'bidding_closed') {
toast({
title: '실행 불가',
description: '유찰 처리는 입찰 마감 상태에서만 가능합니다.',
variant: 'destructive',
})
return
}
if (!confirm('입찰을 유찰 처리하시겠습니까?')) return
startTransition(async () => {
const result = await markAsDisposal(bidding.id, 'current-user') // TODO: 실제 사용자 ID
if (result.success) {
toast({
title: '성공',
description: result.message,
})
router.refresh()
} else {
toast({
title: '오류',
description: result.error,
variant: 'destructive',
})
}
})
}
const handleCreateRebidding = () => {
// 상태 검증
if (bidding.status !== 'bidding_disposal') {
toast({
title: '실행 불가',
description: '재입찰은 유찰 상태에서만 가능합니다.',
variant: 'destructive',
})
return
}
if (!confirm('재입찰을 생성하시겠습니까?')) return
startTransition(async () => {
const result = await createRebidding(bidding.id, 'current-user') // TODO: 실제 사용자 ID
if (result.success) {
toast({
title: '성공',
description: result.message,
})
if (result.data?.redirectTo) {
router.push(result.data.redirectTo)
} else {
router.refresh()
}
} else {
toast({
title: '오류',
description: result.error,
variant: 'destructive',
})
}
})
}
return (
<>
<div className="flex items-center gap-2">
{/* 상태별 액션 버튼 */}
{/* {bidding.status === 'bidding_generated' && (
<Button
variant="default"
size="sm"
onClick={handleRegister}
disabled={isPending}
>
<Send className="mr-2 h-4 w-4" />
입찰 등록
</Button>
)}
{bidding.status === 'bidding_closed' && (
<Button
variant="destructive"
size="sm"
onClick={handleMarkAsDisposal}
disabled={isPending}
>
<XCircle className="mr-2 h-4 w-4" />
유찰 처리
</Button>
)}
{bidding.status === 'bidding_disposal' && (
<Button
variant="outline"
size="sm"
onClick={handleCreateRebidding}
disabled={isPending}
>
<RotateCcw className="mr-2 h-4 w-4" />
재입찰 생성
</Button>
)} */}
{/* 기존 버튼들 */}
<Button
variant="outline"
size="sm"
onClick={onOpenItemsDialog}
>
품목 정보
</Button>
<Button
variant="outline"
size="sm"
onClick={onOpenTargetPriceDialog}
>
내정가 산정
</Button>
<Button
variant="outline"
size="sm"
onClick={onOpenSelectionReasonDialog}
>
선정 사유
</Button>
<Button
variant="default"
size="sm"
onClick={handleCreateVendor}
>
<Plus className="mr-2 h-4 w-4" />
업체 추가
</Button>
</div>
<BiddingDetailVendorCreateDialog
biddingId={biddingId}
open={isCreateDialogOpen}
onOpenChange={setIsCreateDialogOpen}
onSuccess={() => {
onSuccess()
setIsCreateDialogOpen(false)
}}
/>
</>
)
}
|