From 736d2cca8b927c981e2ee30cee3962d10ae48d2a Mon Sep 17 00:00:00 2001 From: Beygorghor Date: Fri, 24 May 2024 16:31:36 +0200 Subject: [PATCH] useCallback did the trick --- .../js/apps/Iaso/domains/orgUnits/utils.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hat/assets/js/apps/Iaso/domains/orgUnits/utils.js b/hat/assets/js/apps/Iaso/domains/orgUnits/utils.js index a8af3368fd..4ee0e8579c 100644 --- a/hat/assets/js/apps/Iaso/domains/orgUnits/utils.js +++ b/hat/assets/js/apps/Iaso/domains/orgUnits/utils.js @@ -1,11 +1,11 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import { textPlaceholder, useSafeIntl } from 'bluesquare-components'; import { orderOrgUnitsByDepth } from '../../utils/map/mapUtils.ts'; +import { useGetOrgUnitValidationStatus } from './hooks/utils/useGetOrgUnitValidationStatus.ts'; import MESSAGES from './messages'; -import { useGetValidationStatus } from '../forms/hooks/useGetValidationStatus.ts'; export const fetchLatestOrgUnitLevelId = levels => { if (levels) { @@ -191,13 +191,18 @@ export const getOrgUnitAncestors = orgUnit => { }; export const useGetStatusMessage = () => { - const { data: validationStatusOptions } = useGetValidationStatus(); - if (!validationStatusOptions) return () => ''; - const getStatusMessage = status => - validationStatusOptions.find(option => option.value === status)?.label; + const { data: validationStatusOptions } = useGetOrgUnitValidationStatus(); + const getStatusMessage = useCallback( + status => { + if (!validationStatusOptions) return ''; + return validationStatusOptions.find( + option => option.value === status, + )?.label; + }, + [validationStatusOptions], + ); return getStatusMessage; }; - export const getOrgUnitGroups = orgUnit => ( {orgUnit.groups &&