diff options
| author | joonhoekim <26rote@gmail.com> | 2025-11-24 20:16:56 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-11-24 20:16:56 +0900 |
| commit | 6bc4162b19f06ad4f919270ebcd4ef18f31cd490 (patch) | |
| tree | be37a152174789d269ef718c2a1f3794531e1c37 /lib/bidding/failure/biddings-closure-dialog.tsx | |
| parent | 775997501ef36bf07d7f1f2e1d4abe7c97505e96 (diff) | |
| parent | a8674e6b91fb4d356c311fad0251878de154da53 (diff) | |
(김준회) 최겸프로 작업사항 병합
Diffstat (limited to 'lib/bidding/failure/biddings-closure-dialog.tsx')
| -rw-r--r-- | lib/bidding/failure/biddings-closure-dialog.tsx | 77 |
1 files changed, 49 insertions, 28 deletions
diff --git a/lib/bidding/failure/biddings-closure-dialog.tsx b/lib/bidding/failure/biddings-closure-dialog.tsx index 64aba42f..93ba0eda 100644 --- a/lib/bidding/failure/biddings-closure-dialog.tsx +++ b/lib/bidding/failure/biddings-closure-dialog.tsx @@ -2,8 +2,9 @@ "use client" import { useState } from "react" +import { useSession } from "next-auth/react" import { toast } from "sonner" -import { bidClosureAction } from "@/lib/bidding/actions" +import { requestBiddingClosureWithApproval } from "@/lib/bidding/approval-actions" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" @@ -19,17 +20,29 @@ interface BiddingsClosureDialogProps { title: string; biddingNumber: string; } | null; - userId: string; onSuccess?: () => void; + onApprovalPreview?: (data: { + templateName: string + variables: Record<string, string> + title: string + description: string + files?: File[] + }) => void } + +interface ClosureFormData { + description: string; + files: File[]; +} export function BiddingsClosureDialog({ open, onOpenChange, bidding, - userId, - onSuccess + onSuccess, + onApprovalPreview }: BiddingsClosureDialogProps) { + const { data: session } = useSession() const [description, setDescription] = useState('') const [files, setFiles] = useState<File[]>([]) const [isSubmitting, setIsSubmitting] = useState(false) @@ -42,36 +55,44 @@ interface BiddingsClosureDialogProps { return } - setIsSubmitting(true) - + // 결재 템플릿 변수 준비 + const { mapBiddingClosureToTemplateVariables } = await import('@/lib/bidding/handlers') + try { - const result = await bidClosureAction(bidding.id, { + const variables = await mapBiddingClosureToTemplateVariables({ + biddingId: bidding.id, description: description.trim(), - files - }, userId) - - if (result.success) { - toast.success(result.message) - onOpenChange(false) - onSuccess?.() - // 페이지 새로고침 또는 상태 업데이트 - window.location.reload() - } else { - toast.error(result.error || '폐찰 처리 중 오류가 발생했습니다.') + requestedAt: new Date() + }) + + // 상위 컴포넌트로 결재 미리보기 데이터 전달 + if (onApprovalPreview) { + onApprovalPreview({ + templateName: '폐찰 품의 요청서', + variables, + title: `폐찰 - ${bidding.title}`, + description: description.trim(), + files + }) } + + onOpenChange(false) + // 폼 초기화 + setDescription('') + setFiles([]) } catch (error) { - toast.error('폐찰 처리 중 오류가 발생했습니다.') - } finally { - setIsSubmitting(false) + console.error('폐찰 템플릿 변수 준비 실패:', error) + toast.error('결재 문서 준비 중 오류가 발생했습니다.') } } - + const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => { if (e.target.files) { setFiles(Array.from(e.target.files)) } } - + + if (!bidding) return null return ( @@ -99,7 +120,7 @@ interface BiddingsClosureDialogProps { required /> </div> - + <div className="space-y-2"> <Label htmlFor="files">첨부파일</Label> <Input @@ -116,7 +137,7 @@ interface BiddingsClosureDialogProps { </div> )} </div> - + <div className="flex justify-end gap-2 pt-4"> <Button type="button" @@ -131,12 +152,12 @@ interface BiddingsClosureDialogProps { variant="destructive" disabled={isSubmitting || !description.trim()} > - {isSubmitting ? '처리 중...' : '폐찰하기'} + {isSubmitting ? '상신 중...' : '결재 상신'} </Button> </div> </form> </DialogContent> </Dialog> - ) - } + </> + )
\ No newline at end of file |
