fix some bugs

This commit is contained in:
phanphan 2024-06-06 13:56:05 +07:00
parent edf8966fcc
commit 44c34f95f5

View File

@ -126,11 +126,11 @@ const ReviewPage = () => {
} }
}, []); }, []);
useEffect(() => { // useEffect(() => {
if (reason) { // if (reason) {
setSolution(counter_measure_map[reason]); // setSolution(counter_measure_map[reason]);
} // }
}, [reason]); // }, [reason]);
const updateSelectedFileDataSource = (fileContent) => { const updateSelectedFileDataSource = (fileContent) => {
let tempData = {}; let tempData = {};
@ -144,13 +144,14 @@ const ReviewPage = () => {
if (isEmpty(tempData[k][REVIEWED_RESULT])) { if (isEmpty(tempData[k][REVIEWED_RESULT])) {
isEmptyResult = true; isEmptyResult = true;
} }
if (tempData[k][REVIEWED_RESULT].length > 0) { if (Array.isArray(tempData[k][REVIEWED_RESULT]) && tempData[k][REVIEWED_RESULT].length > 0) {
isEmptyResult = tempData[k][REVIEWED_RESULT].every((r: any) => isEmptyResult = tempData[k][REVIEWED_RESULT].every((r: any) =>
isEmpty(r), isEmpty(r),
); );
} }
if (isEmptyResult) { if (isEmptyResult) {
tempData[k][REVIEWED_RESULT] = tempData[k][PREDICTED_RESULT]; tempData[k][REVIEWED_RESULT] = tempData[k][PREDICTED_RESULT];
} }
} }
}); });
@ -174,16 +175,20 @@ const ReviewPage = () => {
if (!reason) { if (!reason) {
setReason(null); setReason(null);
setOtherReason(null);
} else if (REASON_BAD_QUALITY.some((r) => r.value === reason)) { } else if (REASON_BAD_QUALITY.some((r) => r.value === reason)) {
setReason(reason); setReason(reason);
setOtherReason(null);
} else { } else {
setReason('other'); setReason('other');
setOtherReason(reason); setOtherReason(reason);
} }
if (!solution) { if (!solution) {
setSolution(null); setSolution(null);
setOtherSolution(null);
} else if (SOLUTION_BAD_QUALITY.some((r) => r.value === solution)) { } else if (SOLUTION_BAD_QUALITY.some((r) => r.value === solution)) {
setSolution(solution); setSolution(solution);
setOtherSolution(null);
} else { } else {
setSolution('other'); setSolution('other');
setOtherSolution(solution); setOtherSolution(solution);
@ -198,7 +203,6 @@ const ReviewPage = () => {
setImageLoading(false); setImageLoading(false);
} }
}; };
const loadCurrentRequest = (requestIndex) => { const loadCurrentRequest = (requestIndex) => {
setLoading(true); setLoading(true);
setImageLoading(true); setImageLoading(true);
@ -306,11 +310,18 @@ const ReviewPage = () => {
let request_file_result = {}; let request_file_result = {};
SOURCE_KEYS.forEach((k) => { SOURCE_KEYS.forEach((k) => {
request_file_result[k] = selectedFileDataSource[k][REVIEWED_RESULT]; request_file_result[k] = selectedFileDataSource[k][REVIEWED_RESULT];
if(Array.isArray(selectedFileDataSource[k][REVIEWED_RESULT])){
request_file_result[k] = selectedFileDataSource[k][REVIEWED_RESULT].toString();
}else{
request_file_result[k] = selectedFileDataSource[k][REVIEWED_RESULT];
}
}); });
let data = { let data = {
request_file_result, request_file_result,
reason: reason ? reason : otherReason, reason: reason !== 'other' ? reason : otherReason,
solution: solution ? solution : otherSolution, solution: solution !== 'other' ? solution : otherSolution,
}; };
try { try {
await updateRevisedDataByFile(currentRequest?.RequestID, fileId, data); await updateRevisedDataByFile(currentRequest?.RequestID, fileId, data);
@ -344,10 +355,10 @@ const ReviewPage = () => {
const [lightBox, setLightBox] = useState(false); const [lightBox, setLightBox] = useState(false);
const updateRevised = (fieldName) => { const updateRevisedByFeedback = (fieldName) => {
setSelectedFileDataSource((prevData) => { setSelectedFileDataSource((prevData) => {
prevData[fieldName][REVIEWED_RESULT] = prevData[fieldName][REVIEWED_RESULT] =
prevData[fieldName][FEEDBACK_RESULT]; prevData[fieldName][FEEDBACK_RESULT];
return { return {
...prevData, ...prevData,
}; };
@ -675,7 +686,7 @@ const ReviewPage = () => {
style={{ minWidth: '120px' }} style={{ minWidth: '120px' }}
onClick={handleConfirmReview} onClick={handleConfirmReview}
> >
(C) Confirm request Confirm request
</Button> </Button>
</div> </div>
</div> </div>
@ -746,7 +757,7 @@ const ReviewPage = () => {
ghost ghost
icon={<CopyOutlined />} icon={<CopyOutlined />}
size='small' size='small'
onClick={() => updateRevised(data)} onClick={() => updateRevisedByFeedback(data)}
/> />
</div> </div>
<Input <Input
@ -785,7 +796,11 @@ const ReviewPage = () => {
placeholder='Select a reason' placeholder='Select a reason'
style={{ width: 170, flexBasis: '50%', height: '32px' }} style={{ width: 170, flexBasis: '50%', height: '32px' }}
options={REASON_BAD_QUALITY} options={REASON_BAD_QUALITY}
onChange={setReason} onChange={(value) => {
let newReason = value;
setReason(newReason);
setSolution(counter_measure_map[newReason]);
}}
value={reason} value={reason}
/> />
{reason === 'other' && ( {reason === 'other' && (
@ -837,7 +852,7 @@ const ReviewPage = () => {
}} }}
onClick={submitRevisedData} onClick={submitRevisedData}
> >
(U) Update File Update File
</Button> </Button>
</div> </div>
</div> </div>