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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
'use client'
import * as React from 'react'
import { useRouter } from 'next/navigation'
import type {
DataTableAdvancedFilterField,
DataTableFilterField,
DataTableRowAction,
} from '@/types/table'
import { useDataTable } from '@/hooks/use-data-table'
import { useToast } from '@/hooks/use-toast'
import { DataTable } from '@/components/data-table/data-table'
import { DataTableAdvancedToolbar } from '@/components/data-table/data-table-advanced-toolbar'
import { getPartnersBiddingListColumns } from './partners-bidding-list-columns'
import { getBiddingListForPartners, PartnersBiddingListItem } from '../detail/service'
import { PartnersBiddingToolbarActions } from './partners-bidding-toolbar-actions'
import { PartnersBiddingAttendanceDialog } from './partners-bidding-attendance-dialog'
import { PartnersBiddingParticipationDialog } from './partners-bidding-participation-dialog'
import { PartnersBiddingAttachmentsDialog } from './partners-bidding-attachments-dialog'
import { setPreQuoteParticipation, getBiddingCompaniesForPartners } from '../pre-quote/service'
interface PartnersBiddingListProps {
companyId: number
}
export function PartnersBiddingList({ companyId }: PartnersBiddingListProps) {
const [data, setData] = React.useState<PartnersBiddingListItem[]>([])
const [pageCount, setPageCount] = React.useState<number>(1)
const [isLoading, setIsLoading] = React.useState(true)
const [rowAction, setRowAction] = React.useState<{ type: string; row: { original: PartnersBiddingListItem } } | null>(null)
const [isParticipationDialogOpen, setIsParticipationDialogOpen] = React.useState(false)
const [selectedBiddingForParticipation, setSelectedBiddingForParticipation] = React.useState<PartnersBiddingListItem | null>(null)
const [selectedBiddingForPreQuoteParticipation, setSelectedBiddingForPreQuoteParticipation] = React.useState<any | null>(null)
const [isAttachmentsDialogOpen, setIsAttachmentsDialogOpen] = React.useState(false)
const [selectedBiddingForAttachments, setSelectedBiddingForAttachments] = React.useState<PartnersBiddingListItem | null>(null)
const router = useRouter()
const { toast } = useToast()
// 데이터 새로고침 함수
const refreshData = React.useCallback(async () => {
try {
setIsLoading(true)
const result = await getBiddingListForPartners(companyId)
setData(result)
} catch (error) {
console.error('Failed to refresh bidding list:', error)
} finally {
setIsLoading(false)
}
}, [companyId])
// 입찰 참여의사 결정 핸들러
const handlePreQuoteParticipationDecision = React.useCallback(async (participate: boolean) => {
if (!selectedBiddingForPreQuoteParticipation?.biddingCompanyId) {
throw new Error('업체 정보를 찾을 수 없습니다.')
}
const result = await setPreQuoteParticipation(
selectedBiddingForPreQuoteParticipation.biddingCompanyId,
participate
)
if (result.success) {
await refreshData() // 데이터 새로고침
} else {
throw new Error(result.error)
}
}, [selectedBiddingForPreQuoteParticipation?.biddingCompanyId, refreshData])
// 데이터 로드
React.useEffect(() => {
const loadData = async () => {
try {
setIsLoading(true)
const result = await getBiddingListForPartners(companyId)
setData(result)
setPageCount(1) // 클라이언트 사이드 페이징이므로 1로 설정
} catch (error) {
console.error('Failed to load bidding list:', error)
setData([])
} finally {
setIsLoading(false)
}
}
loadData()
}, [companyId])
// rowAction 변경 감지하여 해당 페이지로 이동 또는 다이얼로그 열기
React.useEffect(() => {
if (rowAction) {
switch (rowAction.type) {
case 'view':
// 본입찰 초대 여부 확인
const bidding = rowAction.row.original
// 사전견적 요청 상태에서는 상세보기 제한
if (bidding.status === 'request_for_quotation') {
toast({
title: '접근 제한',
description: '사전견적 요청 상태에서는 상세보기를 이용할 수 없습니다.',
variant: 'destructive',
})
return
}
if (bidding.status === 'bidding_opened' && !bidding.isBiddingInvited) {
// 본입찰이 오픈되었지만 초대받지 않은 경우
toast({
title: '접근 제한',
description: '본입찰에 초대받지 않은 업체입니다.',
variant: 'destructive',
})
return
}
// 상세 페이지로 이동 (biddingId 사용)
router.push(`/partners/bid/${rowAction.row.original.biddingId}`)
break
case 'pre-quote':
// 사전견적 페이지로 이동
router.push(`/partners/bid/${rowAction.row.original.biddingId}/pre-quote`)
break
case 'participation':
// 입찰 참여 의사 결정 다이얼로그 열기 - 상세 데이터 로드 필요
handlePreQuoteParticipationDecision(true)
setRowAction(null) // rowAction 초기화
break
case 'view-documents':
// 첨부파일 다이얼로그 열기
setSelectedBiddingForAttachments(rowAction.row.original)
setIsAttachmentsDialogOpen(true)
setRowAction(null) // rowAction 초기화
break
default:
break
}
}
}, [rowAction, router, handlePreQuoteParticipationDecision])
const columns = React.useMemo(
() => getPartnersBiddingListColumns({ setRowAction }),
[setRowAction]
)
const filterFields: DataTableFilterField<PartnersBiddingListItem>[] = [
{
id: 'title',
label: '입찰명',
placeholder: '입찰명으로 검색...',
},
{
id: 'biddingNumber',
label: '입찰번호',
placeholder: '입찰번호로 검색...',
},
{
id: 'itemName',
label: '품목명',
placeholder: '품목명으로 검색...',
},
{
id: 'projectName',
label: '프로젝트명',
placeholder: '프로젝트명으로 검색...',
},
{
id: 'managerName',
label: '담당자',
placeholder: '담당자로 검색...',
},
{
id: 'invitationStatus',
label: '참여의사',
placeholder: '참여의사로 필터링...',
},
{
id: 'status',
label: '입찰상태',
placeholder: '입찰상태로 필터링...',
},
]
const advancedFilterFields: DataTableAdvancedFilterField<PartnersBiddingListItem>[] = [
{ id: 'title', label: '입찰명', type: 'text' },
{ id: 'biddingNumber', label: '입찰번호', type: 'text' },
{ id: 'itemName', label: '품목명', type: 'text' },
{ id: 'projectName', label: '프로젝트명', type: 'text' },
{ id: 'managerName', label: '담당자', type: 'text' },
{ id: 'contractType', label: '계약구분', type: 'text' },
{ id: 'invitationStatus', label: '참여의사', type: 'text' },
{ id: 'status', label: '입찰상태', type: 'text' },
{ id: 'submissionStartDate', label: '입찰시작일', type: 'date' },
{ id: 'submissionEndDate', label: '입찰마감일', type: 'date' },
{ id: 'responseDeadline', label: '참여회신마감일', type: 'date' },
{ id: 'createdAt', label: '등록일', type: 'date' },
{ id: 'updatedAt', label: '수정일', type: 'date' },
]
const { table } = useDataTable({
data,
columns,
pageCount,
filterFields,
enableAdvancedFilter: true,
initialState: {
sorting: [{ id: 'createdAt', desc: true }],
columnPinning: { right: ['actions'] },
},
getRowId: (originalRow) => String(originalRow.id),
shallow: false,
clearOnDefault: true,
})
if (isLoading) {
return (
<div className="flex items-center justify-center py-12">
<div className="text-center">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto mb-4"></div>
<p className="text-muted-foreground">입찰 목록을 불러오는 중...</p>
</div>
</div>
)
}
return (
<>
<DataTable table={table}>
<DataTableAdvancedToolbar
table={table}
filterFields={advancedFilterFields}
shallow={false}
>
<PartnersBiddingToolbarActions table={table} companyId={companyId} onRefresh={refreshData} setRowAction={setRowAction} />
</DataTableAdvancedToolbar>
</DataTable>
<PartnersBiddingAttendanceDialog
open={rowAction?.type === "attendance"}
onOpenChange={() => setRowAction(null)}
biddingDetail={rowAction?.row.original ? {
id: rowAction.row.original.biddingId,
biddingNumber: rowAction.row.original.biddingNumber,
title: rowAction.row.original.title,
preQuoteDate: null,
biddingRegistrationDate: rowAction.row.original.submissionStartDate?.toISOString() || null,
evaluationDate: null,
hasSpecificationMeeting: (rowAction.row.original as any).hasSpecificationMeeting || false, // 사양설명회 여부 추가
} : null}
biddingCompanyId={rowAction?.row.original?.biddingCompanyId || 0}
isAttending={rowAction?.row.original?.isAttendingMeeting || null}
onSuccess={refreshData}
/>
{/*
<PartnersBiddingParticipationDialog
open={isParticipationDialogOpen}
onOpenChange={setIsParticipationDialogOpen}
bidding={selectedBiddingForParticipation}
companyId={companyId}
onSuccess={() => {
refreshData()
setSelectedBiddingForParticipation(null)
}}
/> */}
<PartnersBiddingAttachmentsDialog
open={isAttachmentsDialogOpen}
onOpenChange={setIsAttachmentsDialogOpen}
biddingId={selectedBiddingForAttachments?.biddingId || 0}
biddingTitle={selectedBiddingForAttachments?.title || ''}
/>
</>
)
}
|