Skip to content

Commit aa4fd41

Browse files
committed
Change logic for the isNewLocalUnit
1 parent 609cccf commit aa4fd41

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,
@@ -182,7 +184,6 @@ function LocalUnitsForm(props: Props) {
182184
validate,
183185
setError,
184186
setValue,
185-
pristine,
186187
} = useForm(
187188
schema,
188189
{
@@ -223,7 +224,9 @@ function LocalUnitsForm(props: Props) {
223224
},
224225
});
225226

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

449459
return (
@@ -559,7 +569,6 @@ function LocalUnitsForm(props: Props) {
559569
{hasValidatePermission && (
560570
<LocalUnitValidateButton
561571
onClick={setShowValidateLocalUnitModalTrue}
562-
readOnly={pristine}
563572
isValidated={localUnitDetailsResponse.validated}
564573
hasValidatePermission={hasValidatePermission}
565574
/>

0 commit comments

Comments
 (0)