Skip to content

Commit 50e9d4c

Browse files
committed
Change logic for the isNewLocalUnit
1 parent bdc8543 commit 50e9d4c

File tree

1 file changed

+13
-4
lines changed
  • app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm

1 file changed

+13
-4
lines changed

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
type RefObject,
33
useCallback,
4+
useMemo,
45
useRef,
56
} from 'react';
67
import { useOutletContext } from 'react-router-dom';
@@ -31,6 +32,7 @@ import {
3132
import {
3233
isDefined,
3334
isNotDefined,
35+
isObject,
3436
} from '@togglecorp/fujs';
3537
import {
3638
createSubmitHandler,
@@ -183,7 +185,6 @@ function LocalUnitsForm(props: Props) {
183185
validate,
184186
setError,
185187
setValue,
186-
pristine,
187188
} = useForm(
188189
schema,
189190
{
@@ -224,7 +225,9 @@ function LocalUnitsForm(props: Props) {
224225
},
225226
});
226227

227-
const { response: localUnitPreviousResponse } = useRequest({
228+
const {
229+
response: localUnitPreviousResponse,
230+
} = useRequest({
228231
url: '/api/v2/local-units/{id}/latest-change-request/',
229232
pathVariables: isDefined(localUnitId) ? { id: localUnitId } : undefined,
230233
/*
@@ -444,7 +447,14 @@ function LocalUnitsForm(props: Props) {
444447
const previousData = (
445448
localUnitPreviousResponse?.previous_data_details as unknown as LocalUnitResponse
446449
);
447-
const isNewLocalUnit = isNotDefined(previousData);
450+
const isNewLocalUnit = useMemo(() => {
451+
if (isObject(previousData)) {
452+
if (Object.keys(previousData).length <= 0) {
453+
return true;
454+
}
455+
}
456+
return false;
457+
}, [previousData]);
448458
const showChanges = !isNewLocalUnit && !!localUnitDetailsResponse?.is_locked;
449459

450460
return (
@@ -560,7 +570,6 @@ function LocalUnitsForm(props: Props) {
560570
{hasValidatePermission && (
561571
<LocalUnitValidateButton
562572
onClick={setShowValidateLocalUnitModalTrue}
563-
readOnly={pristine}
564573
isValidated={localUnitDetailsResponse.validated}
565574
hasValidatePermission={hasValidatePermission}
566575
/>

0 commit comments

Comments
 (0)