feat: [검사문서] InspectionReportModal에서 documentRecords prop 전달
- resolveInspectionDocument API 호출 추가 (Promise.all 병렬 로딩) - existing_document.data에서 document_data EAV 레코드 추출 - documentRecords state 관리 (모달 닫힐 때 초기화) - TemplateInspectionContent에 documentRecords prop 전달
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
getInspectionReport,
|
||||
getInspectionTemplate,
|
||||
saveInspectionDocument,
|
||||
resolveInspectionDocument,
|
||||
} from '../actions';
|
||||
import type { WorkOrder, ProcessType } from '../types';
|
||||
import type { InspectionReportData, InspectionReportNodeGroup } from '../actions';
|
||||
@@ -169,6 +170,14 @@ export function InspectionReportModal({
|
||||
const [reportSummary, setReportSummary] = useState<InspectionReportData['summary'] | null>(null);
|
||||
// 자체 로딩한 템플릿 데이터 (prop으로 안 넘어올 때)
|
||||
const [selfTemplateData, setSelfTemplateData] = useState<InspectionTemplateData | null>(null);
|
||||
// 기존 문서의 document_data EAV 레코드 (bending 복원용)
|
||||
const [documentRecords, setDocumentRecords] = useState<Array<{
|
||||
section_id: number | null;
|
||||
column_id: number | null;
|
||||
row_index: number;
|
||||
field_key: string;
|
||||
field_value: string | null;
|
||||
}> | null>(null);
|
||||
|
||||
// props에서 목업 제외한 실제 개소만 사용 (WorkerScreen에서 apiItems + mockItems가 합쳐져 전달됨)
|
||||
// ★ 반드시 workItems와 inspectionDataMap을 같은 소스에서 가져와야 key 포맷이 일치함
|
||||
@@ -233,14 +242,16 @@ export function InspectionReportModal({
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
// 작업지시 기본정보 + 검사 성적서 + 템플릿 동시 로딩
|
||||
// 작업지시 기본정보 + 검사 성적서 + 템플릿 + 기존 문서 동시 로딩
|
||||
Promise.all([
|
||||
getWorkOrderById(workOrderId),
|
||||
getInspectionReport(workOrderId),
|
||||
// prop으로 템플릿이 안 넘어왔으면 자체 로딩
|
||||
!templateData ? getInspectionTemplate(workOrderId) : Promise.resolve(null),
|
||||
// 기존 저장된 문서 조회 (document_data EAV 복원용)
|
||||
resolveInspectionDocument(workOrderId),
|
||||
])
|
||||
.then(([orderResult, reportResult, templateResult]) => {
|
||||
.then(([orderResult, reportResult, templateResult, resolveResult]) => {
|
||||
// 1) WorkOrder 기본정보
|
||||
if (orderResult.success && orderResult.data) {
|
||||
const orderData = orderResult.data;
|
||||
@@ -277,6 +288,20 @@ export function InspectionReportModal({
|
||||
if (templateResult && templateResult.success && templateResult.data) {
|
||||
setSelfTemplateData(templateResult.data);
|
||||
}
|
||||
|
||||
// 4) 기존 문서의 document_data EAV 레코드 추출
|
||||
if (resolveResult?.success && resolveResult.data) {
|
||||
const existingDoc = (resolveResult.data as Record<string, unknown>).existing_document as
|
||||
| { data?: Array<{ section_id: number | null; column_id: number | null; row_index: number; field_key: string; field_value: string | null }> }
|
||||
| null;
|
||||
if (existingDoc?.data && existingDoc.data.length > 0) {
|
||||
setDocumentRecords(existingDoc.data);
|
||||
} else {
|
||||
setDocumentRecords(null);
|
||||
}
|
||||
} else {
|
||||
setDocumentRecords(null);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
setError('서버 오류가 발생했습니다.');
|
||||
@@ -290,6 +315,7 @@ export function InspectionReportModal({
|
||||
setApiInspectionDataMap(null);
|
||||
setReportSummary(null);
|
||||
setSelfTemplateData(null);
|
||||
setDocumentRecords(null);
|
||||
setError(null);
|
||||
}
|
||||
}, [open, workOrderId, processType, templateData]);
|
||||
@@ -366,6 +392,7 @@ export function InspectionReportModal({
|
||||
readOnly={readOnly}
|
||||
workItems={effectiveWorkItems}
|
||||
inspectionDataMap={effectiveInspectionDataMap}
|
||||
documentRecords={documentRecords ?? undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user