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
|
"use client"
import * as React from "react"
import { useRouter } from "next/navigation"
import { useTransition } from "react"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { RefreshCw, RotateCw } from "lucide-react"
import { increaseRoundOrRebid } from "@/lib/bidding/service"
import { useToast } from "@/hooks/use-toast"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { useSession } from "next-auth/react"
interface BiddingRoundActionsProps {
biddingId: number
biddingStatus?: string
}
export function BiddingRoundActions({ biddingId, biddingStatus }: BiddingRoundActionsProps) {
const router = useRouter()
const { toast } = useToast()
const [isPending, startTransition] = useTransition()
const [showRoundDialog, setShowRoundDialog] = React.useState(false)
const [showRebidDialog, setShowRebidDialog] = React.useState(false)
const { data: session } = useSession()
const userId = session?.user?.id
// 차수증가는 유찰 상태에서만 가능
const canIncreaseRound = biddingStatus === 'bidding_disposal'
// 재입찰도 유찰 상태에서만 가능
const canRebid = biddingStatus === 'bidding_disposal'
const handleRoundIncrease = () => {
startTransition(async () => {
try {
const result = await increaseRoundOrRebid(biddingId, userId, 'round_increase')
if (result.success) {
toast({
title: "성공",
description: result.message,
variant: "default",
})
setShowRoundDialog(false)
// 새로 생성된 입찰 페이지로 이동
if (result.biddingId) {
router.push(`/evcp/bid/${result.biddingId}`)
router.refresh()
}
} else {
toast({
title: "오류",
description: result.error || "차수증가 중 오류가 발생했습니다.",
variant: "destructive",
})
}
} catch (error) {
console.error('차수증가 실패:', error)
toast({
title: "오류",
description: "차수증가 중 오류가 발생했습니다.",
variant: "destructive",
})
}
})
}
const handleRebid = () => {
startTransition(async () => {
try {
const result = await increaseRoundOrRebid(biddingId, userId, 'rebidding')
if (result.success) {
toast({
title: "성공",
description: result.message,
variant: "default",
})
setShowRebidDialog(false)
// 새로 생성된 입찰 페이지로 이동
if (result.biddingId) {
router.push(`/evcp/bid/${result.biddingId}`)
router.refresh()
}
} else {
toast({
title: "오류",
description: result.error || "재입찰 중 오류가 발생했습니다.",
variant: "destructive",
})
}
} catch (error) {
console.error('재입찰 실패:', error)
toast({
title: "오류",
description: "재입찰 중 오류가 발생했습니다.",
variant: "destructive",
})
}
})
}
// 유찰 상태가 아니면 컴포넌트를 렌더링하지 않음
if (!canIncreaseRound && !canRebid) {
return null
}
return (
<>
<Card className="mt-6">
<CardHeader>
<CardTitle>입찰 차수 관리</CardTitle>
</CardHeader>
<CardContent>
<div className="flex gap-4">
<Button
variant="outline"
onClick={() => setShowRoundDialog(true)}
disabled={!canIncreaseRound || isPending}
className="flex items-center gap-2"
>
<RotateCw className="w-4 h-4" />
차수증가
</Button>
<Button
variant="outline"
onClick={() => setShowRebidDialog(true)}
disabled={!canRebid || isPending}
className="flex items-center gap-2"
>
<RefreshCw className="w-4 h-4" />
재입찰
</Button>
</div>
<p className="text-sm text-muted-foreground mt-2">
유찰 상태에서 차수증가 또는 재입찰을 진행할 수 있습니다.
</p>
</CardContent>
</Card>
{/* 차수증가 확인 다이얼로그 */}
<AlertDialog open={showRoundDialog} onOpenChange={setShowRoundDialog}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>차수증가</AlertDialogTitle>
<AlertDialogDescription>
현재 입찰의 정보를 복제하여 새로운 차수의 입찰을 생성합니다.
<br />
기존 입찰 조건, 아이템, 벤더 정보가 복제되며, 벤더 제출 정보는 초기화됩니다.
<br />
<br />
계속하시겠습니까?
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isPending}>취소</AlertDialogCancel>
<AlertDialogAction onClick={handleRoundIncrease} disabled={isPending}>
{isPending ? "처리중..." : "확인"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
{/* 재입찰 확인 다이얼로그 */}
<AlertDialog open={showRebidDialog} onOpenChange={setShowRebidDialog}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>재입찰</AlertDialogTitle>
<AlertDialogDescription>
현재 입찰의 정보를 복제하여 재입찰을 생성합니다.
<br />
기존 입찰 조건, 아이템, 벤더 정보가 복제되며, 벤더 제출 정보는 초기화됩니다.
<br />
<br />
계속하시겠습니까?
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isPending}>취소</AlertDialogCancel>
<AlertDialogAction onClick={handleRebid} disabled={isPending}>
{isPending ? "처리중..." : "확인"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
)
}
|