From 871a6d46a769cbe9e87146434f4bcb2d6792ab81 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 30 Oct 2025 10:44:47 +0000 Subject: (최겸) 구매 PQ/실사 재개발(테스트 필요), 정규업체등록 결재 개발, 실사 의뢰 결재 후처리 등 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pq/pq-review-table-new/site-visit-dialog.tsx | 135 ++++++++++++++--------- 1 file changed, 81 insertions(+), 54 deletions(-) (limited to 'lib/pq/pq-review-table-new/site-visit-dialog.tsx') diff --git a/lib/pq/pq-review-table-new/site-visit-dialog.tsx b/lib/pq/pq-review-table-new/site-visit-dialog.tsx index 2b65d03e..b1474150 100644 --- a/lib/pq/pq-review-table-new/site-visit-dialog.tsx +++ b/lib/pq/pq-review-table-new/site-visit-dialog.tsx @@ -140,6 +140,7 @@ interface SiteVisitDialogProps { projectCode?: string pqItems?: Array<{itemCode: string, itemName: string}> | null } + isReinspection?: boolean // 재실사 모드 플래그 } export function SiteVisitDialog({ @@ -147,6 +148,7 @@ export function SiteVisitDialog({ onClose, onSubmit, investigation, + isReinspection = false, }: SiteVisitDialogProps) { const [isPending, setIsPending] = React.useState(false) const [selectedFiles, setSelectedFiles] = React.useState([]) @@ -184,58 +186,88 @@ export function SiteVisitDialog({ }, }) - // Dialog가 열릴 때마다 폼 재설정 및 기존 요청 확인 + // Dialog가 열릴 때마다 폼 재설정 및 기존 요청 로딩 React.useEffect(() => { if (isOpen) { - // 기존 방문실사 요청이 있는지 확인 - const checkExistingRequest = async () => { + const loadExistingRequest = async () => { try { + // 기존 방문실사 요청이 있는지 확인하고 최신 것을 로드 const existingRequest = await getSiteVisitRequestAction(investigation.id) - + if (existingRequest.success && existingRequest.data) { - toast.error("이미 방문실사 요청이 존재합니다. 추가 요청은 불가능합니다.") - onClose() + // 기존 데이터를 form에 로드 + const data = existingRequest.data + form.reset({ + inspectionDuration: data.inspectionDuration || 1.0, + requestedStartDate: data.requestedStartDate ? new Date(data.requestedStartDate) : undefined, + requestedEndDate: data.requestedEndDate ? new Date(data.requestedEndDate) : undefined, + shiAttendees: data.shiAttendees || { + technicalSales: { checked: false, count: 0, details: "" }, + design: { checked: false, count: 0, details: "" }, + procurement: { checked: false, count: 0, details: "" }, + quality: { checked: false, count: 0, details: "" }, + production: { checked: false, count: 0, details: "" }, + commissioning: { checked: false, count: 0, details: "" }, + other: { checked: false, count: 0, details: "" }, + }, + shiAttendeeDetails: data.shiAttendeeDetails || "", + vendorRequests: data.vendorRequests || { + availableDates: false, + factoryName: false, + factoryLocation: false, + factoryAddress: false, + factoryPicName: false, + factoryPicPhone: false, + factoryPicEmail: false, + factoryDirections: false, + accessProcedure: false, + other: false, + }, + otherVendorRequests: data.otherVendorRequests || "", + additionalRequests: data.additionalRequests || "", + }) return } + + // 기본값으로 폼 초기화 (기존 요청이 없는 경우) + form.reset({ + inspectionDuration: 1.0, + requestedStartDate: undefined, + requestedEndDate: undefined, + shiAttendees: { + technicalSales: { checked: false, count: 0, details: "" }, + design: { checked: false, count: 0, details: "" }, + procurement: { checked: false, count: 0, details: "" }, + quality: { checked: false, count: 0, details: "" }, + production: { checked: false, count: 0, details: "" }, + commissioning: { checked: false, count: 0, details: "" }, + other: { checked: false, count: 0, details: "" }, + }, + shiAttendeeDetails: "", + vendorRequests: { + availableDates: false, + factoryName: false, + factoryLocation: false, + factoryAddress: false, + factoryPicName: false, + factoryPicPhone: false, + factoryPicEmail: false, + factoryDirections: false, + accessProcedure: false, + other: false, + }, + otherVendorRequests: "", + additionalRequests: "", + }) } catch (error) { - console.error("방문실사 요청 상태 확인 중 오류:", error) - toast.error("방문실사 요청 상태 확인 중 오류가 발생했습니다.") + console.error("방문실사 요청 데이터 로드 중 오류:", error) + toast.error("방문실사 요청 데이터 로드 중 오류가 발생했습니다.") onClose() return } } - - checkExistingRequest() - - form.reset({ - inspectionDuration: 1.0, - requestedStartDate: undefined, - requestedEndDate: undefined, - shiAttendees: { - technicalSales: { checked: false, count: 0, details: "" }, - design: { checked: false, count: 0, details: "" }, - procurement: { checked: false, count: 0, details: "" }, - quality: { checked: false, count: 0, details: "" }, - production: { checked: false, count: 0, details: "" }, - commissioning: { checked: false, count: 0, details: "" }, - other: { checked: false, count: 0, details: "" }, - }, - shiAttendeeDetails: "", - vendorRequests: { - availableDates: false, - factoryName: false, - factoryLocation: false, - factoryAddress: false, - factoryPicName: false, - factoryPicPhone: false, - factoryPicEmail: false, - factoryDirections: false, - accessProcedure: false, - other: false, - }, - otherVendorRequests: "", - additionalRequests: "", - }) + + loadExistingRequest() setSelectedFiles([]) } }, [isOpen, form, investigation.id, onClose]) @@ -243,19 +275,11 @@ export function SiteVisitDialog({ async function handleSubmit(data: SiteVisitRequestFormValues) { setIsPending(true) try { - // 제출 전에 한 번 더 기존 요청이 있는지 확인 - const existingRequest = await getSiteVisitRequestAction(investigation.id) - - if (existingRequest.success && existingRequest.data) { - toast.error("이미 방문실사 요청이 존재합니다. 추가 요청은 불가능합니다.") - onClose() - return - } - + await onSubmit(data, selectedFiles) - toast.success("방문실사 요청이 성공적으로 발송되었습니다.") + toast.success(isReinspection ? "재실사 요청이 성공적으로 발송되었습니다." : "방문실사 요청이 성공적으로 발송되었습니다.") } catch (error) { - toast.error("방문실사 요청 발송 중 오류가 발생했습니다.") + toast.error(isReinspection ? "재실사 요청 발송 중 오류가 발생했습니다." : "방문실사 요청 발송 중 오류가 발생했습니다.") console.error("방문실사 요청 오류:", error) } finally { setIsPending(false) @@ -294,9 +318,12 @@ export function SiteVisitDialog({ !open && onClose()}> - 방문실사 요청 생성 + {isReinspection ? "재실사 요청 생성" : "방문실사 요청 생성"} - 협력업체에 방문실사 요청을 생성하고, 협력업체가 입력할 정보 항목을 설정합니다. + {isReinspection + ? "협력업체에 재실사 요청을 생성하고, 협력업체가 입력할 정보 항목을 설정합니다." + : "협력업체에 방문실사 요청을 생성하고, 협력업체가 입력할 정보 항목을 설정합니다." + } @@ -710,7 +737,7 @@ export function SiteVisitDialog({ 취소 -- cgit v1.2.3