From 97ad3a0220524c81314b5aee7bb141fc7207cb0a Mon Sep 17 00:00:00 2001 From: HAKIZIMANA Franck Date: Thu, 26 Dec 2024 17:57:13 +0200 Subject: [PATCH] fix approve warning code --- .../components/PushGpsDialogComponent.tsx | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/hat/assets/js/apps/Iaso/domains/instances/components/PushGpsDialogComponent.tsx b/hat/assets/js/apps/Iaso/domains/instances/components/PushGpsDialogComponent.tsx index d8b5c35ff8..d46f422691 100644 --- a/hat/assets/js/apps/Iaso/domains/instances/components/PushGpsDialogComponent.tsx +++ b/hat/assets/js/apps/Iaso/domains/instances/components/PushGpsDialogComponent.tsx @@ -34,9 +34,9 @@ const PushGpsDialogComponent: FunctionComponent = ({ }) => { const currentUser = useCurrentUser(); const [approveOrgUnitHasGps, setApproveOrgUnitHasGps] = - useState(false); + useState(true); const [approveSubmissionNoHasGps, setApproveSubmissionNoHasGps] = - useState(false); + useState(true); const { mutateAsync: bulkgpspush } = useInstanceBulkgpspush(); const select_all = selection.selectAll; const selected_ids = selection.selectedItems; @@ -114,24 +114,37 @@ const PushGpsDialogComponent: FunctionComponent = ({ Permission.DATA_TASKS, currentUser, ); - const displayWarningOverWriteGps = useMemo( - () => + const displayWarningOverWriteGps = useMemo(() => { + const isWarning = (checkBulkGpsPush?.warning_overwrite?.length ?? 0) > 0 && - (checkBulkGpsPush?.error_ids?.length ?? 0) <= 0, - [ - checkBulkGpsPush?.error_ids?.length, - checkBulkGpsPush?.warning_overwrite?.length, - ], - ); - const displayWarningSubmissionsNoGps = useMemo( - () => + (checkBulkGpsPush?.error_ids?.length ?? 0) <= 0; + if (isWarning) { + setApproveOrgUnitHasGps(false); + } else { + setApproveOrgUnitHasGps(true); + } + + return isWarning; + }, [ + checkBulkGpsPush?.error_ids?.length, + checkBulkGpsPush?.warning_overwrite?.length, + ]); + + const displayWarningSubmissionsNoGps = useMemo(() => { + const isWarning = (checkBulkGpsPush?.warning_no_location?.length ?? 0) > 0 && - (checkBulkGpsPush?.error_ids?.length ?? 0) <= 0, - [ - checkBulkGpsPush?.error_ids?.length, - checkBulkGpsPush?.warning_no_location?.length, - ], - ); + (checkBulkGpsPush?.error_ids?.length ?? 0) <= 0; + if (isWarning) { + setApproveOrgUnitHasGps(false); + } else { + setApproveOrgUnitHasGps(true); + } + + return isWarning; + }, [ + checkBulkGpsPush?.error_ids?.length, + checkBulkGpsPush?.warning_no_location?.length, + ]); const noLoadingAndNoError = useMemo( () => !isLoadingCheckResult && !isError,