diff options
Diffstat (limited to 'lib/bidding/failure/biddings-failure-table.tsx')
| -rw-r--r-- | lib/bidding/failure/biddings-failure-table.tsx | 131 |
1 files changed, 83 insertions, 48 deletions
diff --git a/lib/bidding/failure/biddings-failure-table.tsx b/lib/bidding/failure/biddings-failure-table.tsx index a0f98466..c4e3be06 100644 --- a/lib/bidding/failure/biddings-failure-table.tsx +++ b/lib/bidding/failure/biddings-failure-table.tsx @@ -25,7 +25,7 @@ import { FileX, RefreshCw, Undo2 } from "lucide-react" import { bidClosureAction, cancelDisposalAction } from "@/lib/bidding/actions"
import { increaseRoundOrRebid } from "@/lib/bidding/service"
import { ApprovalPreviewDialog } from "@/lib/approval/approval-preview-dialog"
-import { requestBiddingClosureWithApproval } from "@/lib/bidding/approval-actions"
+import { requestBiddingClosureWithApproval, prepareBiddingClosureApprovalData } from "@/lib/bidding/approval-actions"
import { useToast } from "@/hooks/use-toast"
type BiddingFailureItem = {
@@ -258,6 +258,86 @@ export function BiddingsFailureTable({ promises }: BiddingsFailureTableProps) { }
}, [session?.user?.id, toast, router])
+ // 폐찰 결재 준비 및 결재 다이얼로그 열기 핸들러
+ const handleClosureApprovalSend = async (data: { description: string; files: File[]; biddingId: number }) => {
+ try {
+ if (!session?.user?.id) {
+ toast({
+ title: '오류',
+ description: '사용자 정보가 없습니다.',
+ variant: 'destructive',
+ })
+ return
+ }
+
+ // 결재 데이터 준비 (템플릿 변수 등)
+ const approvalData = await prepareBiddingClosureApprovalData({
+ biddingId: data.biddingId,
+ description: data.description,
+ })
+
+ // 결재 준비 완료 - approvalPreviewData와 결재 데이터 저장 및 결재 다이얼로그 열기
+ setApprovalPreviewData({
+ templateName: '폐찰 품의 요청서',
+ variables: approvalData.variables,
+ title: `폐찰 - ${selectedBidding?.title || ''}`,
+ description: data.description,
+ files: data.files,
+ })
+ setIsApprovalPreviewDialogOpen(true)
+ } catch (error) {
+ console.error('결재 준비 중 오류 발생:', error)
+ toast({
+ title: '오류',
+ description: '결재 준비 중 오류가 발생했습니다.',
+ variant: 'destructive',
+ })
+ }
+ }
+
+ // 폐찰 결재 상신 핸들러 - 결재 완료 시 실제 폐찰 실행
+ const handleClosureApprovalSubmit = async (data: { approvers: string[]; title: string; attachments?: File[] }) => {
+ if (!session?.user?.id || !approvalPreviewData || !selectedBidding) return
+
+ try {
+ const result = await requestBiddingClosureWithApproval({
+ biddingId: selectedBidding.id,
+ description: approvalPreviewData.description,
+ files: approvalPreviewData.files,
+ currentUser: {
+ id: Number(session.user.id),
+ epId: session.user.epId || null,
+ email: session.user.email || undefined
+ },
+ approvers: data.approvers,
+ })
+
+ if (1) {
+ toast({
+ title: '성공',
+ description: `폐찰 결재가 상신되었습니다. (ID: ${result.approvalId})`,
+ })
+ setIsApprovalPreviewDialogOpen(false)
+ setApprovalPreviewData(null)
+ handleBiddingClosureDialogClose()
+ router.refresh()
+ } else {
+ toast({
+ title: '오류',
+ description: '폐찰 결재 상신 중 오류가 발생했습니다.',
+ variant: 'destructive',
+ })
+ }
+ } catch (error) {
+ console.error('폐찰 결재 상신 실패:', error)
+ toast({
+ title: '오류',
+ description: '폐찰 결재 상신 중 오류가 발생했습니다.',
+ variant: 'destructive',
+ })
+ }
+ }
+
const handleCancelDisposal = React.useCallback(async (bidding: BiddingFailureItem) => {
if (!session?.user?.id) {
toast({
@@ -438,10 +518,7 @@ export function BiddingsFailureTable({ promises }: BiddingsFailureTableProps) { router.refresh()
handleBiddingClosureDialogClose()
}}
- onApprovalPreview={(data) => {
- setApprovalPreviewData(data)
- setIsApprovalPreviewDialogOpen(true)
- }}
+ onApprovalPreview={handleClosureApprovalSend}
/>
)}
@@ -498,52 +575,10 @@ export function BiddingsFailureTable({ promises }: BiddingsFailureTableProps) { name: session.user.name || undefined,
email: session.user.email || undefined
}}
- onConfirm={handleClosureApprovalConfirm}
+ onConfirm={handleClosureApprovalSubmit}
/>
)}
</>
)
- // 폐찰 결재 상신 핸들러
- const handleClosureApprovalConfirm = async (data: { approvers: string[]; title: string; attachments?: File[] }) => {
- if (!session?.user?.id || !approvalPreviewData || !selectedBidding) return
-
- try {
- const result = await requestBiddingClosureWithApproval({
- biddingId: selectedBidding.id,
- description: approvalPreviewData.description,
- files: approvalPreviewData.files,
- currentUser: {
- id: Number(session.user.id),
- epId: session.user.epId || null,
- email: session.user.email || undefined
- },
- approvers: data.approvers,
- })
-
- if (result.status === 'pending_approval') {
- toast({
- title: '성공',
- description: `폐찰 결재가 상신되었습니다. (ID: ${result.approvalId})`,
- })
- setIsApprovalPreviewDialogOpen(false)
- setApprovalPreviewData(null)
- handleBiddingClosureDialogClose()
- router.refresh()
- } else {
- toast({
- title: '오류',
- description: '폐찰 결재 상신 중 오류가 발생했습니다.',
- variant: 'destructive',
- })
- }
- } catch (error) {
- console.error('폐찰 결재 상신 실패:', error)
- toast({
- title: '오류',
- description: '폐찰 결재 상신 중 오류가 발생했습니다.',
- variant: 'destructive',
- })
- }
- }
}
|
