diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-26 01:17:56 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-26 01:17:56 +0000 |
| commit | 12e936c0b45ffa1c8f3c02ff77961212767be9a7 (patch) | |
| tree | 34f31b9a64c6d30e187c1114530c4d47b95d30a9 /lib/vendors/table/request-pq-dialog.tsx | |
| parent | 83f67ed333f0237b434a41d1eceef417c0d48313 (diff) | |
(대표님) 가입, 기본계약, 벤더
(최겸) 기술영업 아이템 관련
Diffstat (limited to 'lib/vendors/table/request-pq-dialog.tsx')
| -rw-r--r-- | lib/vendors/table/request-pq-dialog.tsx | 115 |
1 files changed, 102 insertions, 13 deletions
diff --git a/lib/vendors/table/request-pq-dialog.tsx b/lib/vendors/table/request-pq-dialog.tsx index 20388f71..14a1cd01 100644 --- a/lib/vendors/table/request-pq-dialog.tsx +++ b/lib/vendors/table/request-pq-dialog.tsx @@ -37,6 +37,7 @@ import { Checkbox } from "@/components/ui/checkbox" import { Label } from "@/components/ui/label"
import { Input } from "@/components/ui/input"
import { Badge } from "@/components/ui/badge"
+import { Progress } from "@/components/ui/progress"
import { Vendor } from "@/db/schema/vendors"
import { requestBasicContractInfo, requestPQVendors } from "../service"
import { getProjectsWithPQList } from "@/lib/pq/service"
@@ -98,6 +99,11 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro // 비밀유지 계약서 첨부파일 관련 상태
const [ndaAttachments, setNdaAttachments] = React.useState<File[]>([])
const [isUploadingNdaFiles, setIsUploadingNdaFiles] = React.useState(false)
+
+ // 프로그레스 관련 상태
+ const [progressValue, setProgressValue] = React.useState(0)
+ const [currentStep, setCurrentStep] = React.useState("")
+ const [showProgress, setShowProgress] = React.useState(false)
// 아이템 검색 필터링
React.useEffect(() => {
@@ -180,6 +186,9 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro setShowItemDropdown(false)
setNdaAttachments([])
setIsUploadingNdaFiles(false)
+ setProgressValue(0)
+ setCurrentStep("")
+ setShowProgress(false)
}
}, [props.open])
@@ -235,9 +244,22 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro if (!dueDate) return toast.error("마감일을 선택하세요.")
if (!session?.user?.id) return toast.error("인증 실패")
+ // 프로그레스 바를 즉시 표시
+ setShowProgress(true)
+ setProgressValue(0)
+ setCurrentStep("시작 중...")
+
startApproveTransition(async () => {
try {
+
+ // 전체 단계 수 계산
+ const totalSteps = 1 +
+ (selectedTemplateIds.length > 0 ? 1 : 0) +
+ (isNdaTemplateSelected() && ndaAttachments.length > 0 ? 1 : 0)
+ let completedSteps = 0
+
// 1단계: PQ 생성
+ setCurrentStep("PQ 생성 중...")
console.log("🚀 PQ 생성 시작")
const { error: pqError } = await requestPQVendors({
ids: vendors.map((v) => v.id),
@@ -252,9 +274,13 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro })
if (pqError) {
+ setShowProgress(false)
toast.error(`PQ 생성 실패: ${pqError}`)
return
}
+
+ completedSteps++
+ setProgressValue((completedSteps / totalSteps) * 100)
console.log("✅ PQ 생성 완료")
toast.success("PQ가 성공적으로 요청되었습니다")
@@ -264,12 +290,17 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro selectedTemplateIds.includes(t.id)
)
+ setCurrentStep(`기본계약서 생성 중... (${templates.length}개 템플릿)`)
console.log("📋 기본계약서 백그라운드 처리 시작", templates.length, "개 템플릿")
await processBasicContractsInBackground(templates, vendors)
+
+ completedSteps++
+ setProgressValue((completedSteps / totalSteps) * 100)
}
// 3단계: 비밀유지 계약서 첨부파일이 있는 경우 저장
if (isNdaTemplateSelected() && ndaAttachments.length > 0) {
+ setCurrentStep(`비밀유지 계약서 첨부파일 저장 중... (${ndaAttachments.length}개 파일)`)
console.log("📎 비밀유지 계약서 첨부파일 처리 시작", ndaAttachments.length, "개 파일")
const ndaResult = await saveNdaAttachments({
@@ -283,14 +314,24 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro } else {
toast.error(`첨부파일 처리 중 일부 오류가 발생했습니다: ${ndaResult.error}`)
}
+
+ completedSteps++
+ setProgressValue((completedSteps / totalSteps) * 100)
}
- // 완료 후 다이얼로그 닫기
- props.onOpenChange?.(false)
- onSuccess?.()
+ setCurrentStep("완료!")
+ setProgressValue(100)
+
+ // 잠시 완료 상태를 보여준 후 다이얼로그 닫기
+ setTimeout(() => {
+ setShowProgress(false)
+ props.onOpenChange?.(false)
+ onSuccess?.()
+ }, 1000)
} catch (error) {
console.error('PQ 생성 오류:', error)
+ setShowProgress(false)
toast.error(`처리 중 오류가 발생했습니다: ${error instanceof Error ? error.message : '알 수 없는 오류'}`)
}
})
@@ -328,6 +369,13 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro const template = templates[templateIndex]
processedCount++
+ // 진행률 업데이트 (2단계 범위 내에서)
+ const baseProgress = 33.33 // 1단계 완료 후
+ const contractProgress = (processedCount / totalContracts) * 33.33 // 2단계는 33.33% 차지
+ const newProgress = baseProgress + contractProgress
+ setProgressValue(newProgress)
+ setCurrentStep(`기본계약서 생성 중... (${processedCount}/${totalContracts})`)
+
console.log(`📄 처리 중: ${vendor.vendorName} - ${template.templateName} (${processedCount}/${totalContracts})`)
// 개별 벤더에 대한 기본계약 생성
@@ -720,11 +768,31 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro <div className="flex-1 overflow-y-auto">
{dialogContent}
</div>
- <DialogFooter>
- <DialogClose asChild><Button variant="outline">취소</Button></DialogClose>
- <Button onClick={onApprove} disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId)}>
- {isApprovePending && <Loader className="mr-2 size-4 animate-spin" />}요청하기
- </Button>
+ <DialogFooter className="flex-col gap-4">
+ {/* 프로그레스 바 */}
+ {(showProgress || isApprovePending) && (
+ <div className="w-full space-y-2">
+ <div className="flex items-center justify-between text-sm">
+ <span className="text-muted-foreground">{currentStep || "처리 중..."}</span>
+ <span className="font-medium">{Math.round(progressValue)}%</span>
+ </div>
+ <Progress value={progressValue} className="w-full" />
+ </div>
+ )}
+
+ {/* 버튼들 */}
+ <div className="flex justify-end gap-2">
+ <DialogClose asChild>
+ <Button variant="outline" disabled={isApprovePending}>취소</Button>
+ </DialogClose>
+ <Button
+ onClick={onApprove}
+ disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId)}
+ >
+ {isApprovePending && <Loader className="mr-2 size-4 animate-spin" />}
+ 요청하기
+ </Button>
+ </div>
</DialogFooter>
</DialogContent>
@@ -753,11 +821,32 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro <div className="flex-1 overflow-y-auto px-4">
{dialogContent}
</div>
- <DrawerFooter>
- <DrawerClose asChild><Button variant="outline">취소</Button></DrawerClose>
- <Button onClick={onApprove} disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId)}>
- {isApprovePending && <Loader className="mr-2 size-4 animate-spin" />}요청하기
- </Button>
+ <DrawerFooter className="gap-4">
+ {/* 프로그레스 바 */}
+ {(showProgress || isApprovePending) && (
+ <div className="w-full space-y-2">
+ <div className="flex items-center justify-between text-sm">
+ <span className="text-muted-foreground">{currentStep || "처리 중..."}</span>
+ <span className="font-medium">{Math.round(progressValue)}%</span>
+ </div>
+ <Progress value={progressValue} className="w-full" />
+ </div>
+ )}
+
+ {/* 버튼들 */}
+ <div className="flex gap-2">
+ <DrawerClose asChild>
+ <Button variant="outline" disabled={isApprovePending} className="flex-1">취소</Button>
+ </DrawerClose>
+ <Button
+ onClick={onApprove}
+ disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId)}
+ className="flex-1"
+ >
+ {isApprovePending && <Loader className="mr-2 size-4 animate-spin" />}
+ 요청하기
+ </Button>
+ </div>
</DrawerFooter>
</DrawerContent>
|
