From 21546788f89e43b23fec881cecf45f74e2aaa40d Mon Sep 17 00:00:00 2001 From: Shreeyash Shrestha Date: Fri, 31 Oct 2025 18:46:16 +0545 Subject: [PATCH 1/2] fix(local-unit): update field orientation and add missing field in local unit --- .../LocalUnitsForm/i18n.json | 1 + .../LocalUnitsForm/index.tsx | 343 +++++++++--------- .../LocalUnitsForm/schema.ts | 6 + go-api | 2 +- 4 files changed, 185 insertions(+), 167 deletions(-) diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/i18n.json b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/i18n.json index 5b76094bf..6a8089556 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/i18n.json +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/i18n.json @@ -67,6 +67,7 @@ "dentist": "Dentist", "nursingAid": "Nursing aid", "midwife": "Midwife", + "pharmacists": "Pharmacists", "otherMedicalHeal": "Other medical heal", "commentsNS": "Comments by the NS", "addOtherProfilesButtonLabel": "Add Other Profiles", diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx index 3c734ff28..ad0e95391 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx @@ -271,8 +271,7 @@ function LocalUnitsForm(props: Props) { ); }, [externallyManagedLocalUnitsResponse]); - const isEditable = isDefined(localUnitDetailsResponse?.status) - && localUnitDetailsResponse.status === VALIDATED; + const isEditable = localUnitDetailsResponse?.status === VALIDATED; const isNewlyCreated = localUnitDetailsResponse?.status === UNVALIDATED; const isExternallyManaged = localUnitDetailsResponse?.status === EXTERNALLY_MANAGED; @@ -280,7 +279,7 @@ function LocalUnitsForm(props: Props) { ? !!(externallyManagedByLocalUnitType?.[value.type]) : false; - const readOnly = readOnlyFromProps || !isEditable || isExternallyManaged; + const readOnly = readOnlyFromProps || isExternallyManaged || isExternallyManagedType; const { response: localUnitsOptions, @@ -867,110 +866,105 @@ function LocalUnitsForm(props: Props) { /> {value.type === TYPE_HEALTH_CARE && ( - <> - - + + + + + + + - - {hasUpdatePermission && ( - <> - + + + + - - - + + + - - - - )} - - )} - {value.type !== TYPE_HEALTH_CARE && hasUpdatePermission && ( - <> - - - - - - - + /> + + + ) )} {value.type !== TYPE_HEALTH_CARE && ( <> @@ -1622,59 +1616,6 @@ function LocalUnitsForm(props: Props) { )} /> - {value.health?.health_facility_type === HOSPITAL_TYPE && ( - <> - {value.health?.is_in_patient_capacity && ( - - - - )} - {value.health?.is_isolation_rooms_wards && ( - - - - )} - - )} {value?.health?.health_facility_type === HOSPITAL_TYPE && ( @@ -1730,6 +1671,30 @@ function LocalUnitsForm(props: Props) { error={healthFormError?.is_in_patient_capacity} /> + {value.health?.is_in_patient_capacity && ( + + + + )} + {value.health?.is_isolation_rooms_wards && ( + + + + )} )} @@ -1925,16 +1917,25 @@ function LocalUnitsForm(props: Props) { )} /> - {!readOnly && ( - - )} + + + {value.health?.other_profiles?.map((profile, i) => ( ))} + {!readOnly && ( + + )} diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts index 23c72af56..d03b37637 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts @@ -162,6 +162,7 @@ const schema: LocalUnitsFormSchema = { ], }, focal_point_position: { + required: true, validations: [lengthSmallerThanCondition(50)], }, focal_point_phone_number: { @@ -250,6 +251,11 @@ const schema: LocalUnitsFormSchema = { positiveIntegerCondition, ], }, + pharmacists: { + validations: [ + positiveIntegerCondition, + ], + }, other_medical_heal: {}, other_profiles: { keySelector: (item) => item.client_id, diff --git a/go-api b/go-api index 2960f07e4..e3cf7dfe0 160000 --- a/go-api +++ b/go-api @@ -1 +1 @@ -Subproject commit 2960f07e433fd8cf6e1fbd7f1ffe4d2b543000f9 +Subproject commit e3cf7dfe0c2edad391bcca53056f92fae6135a5a From e7804e9c17aab8862c2205c2b01a77c3a280e95a Mon Sep 17 00:00:00 2001 From: Shreeyash Shrestha Date: Fri, 31 Oct 2025 19:36:39 +0545 Subject: [PATCH 2/2] fix(local-unit): update add and edit permission for local unit form --- app/src/hooks/domain/usePermissions.ts | 2 +- .../ConfirmationModal/index.tsx | 3 ++- .../ConfigureLocalUnitsModal/index.tsx | 25 ++++++------------- .../OtherProfilesDiffOutput/i18n.json | 1 - .../LocalUnitView/i18n.json | 1 + .../LocalUnitView/index.tsx | 12 +++++++++ .../LocalUnitsForm/index.tsx | 10 ++++++-- .../LocalUnitTableActions/index.tsx | 22 +++++++++------- .../LocalUnitsTable/index.tsx | 2 ++ go-api | 2 +- 10 files changed, 48 insertions(+), 32 deletions(-) diff --git a/app/src/hooks/domain/usePermissions.ts b/app/src/hooks/domain/usePermissions.ts index feff71b43..9c0e19523 100644 --- a/app/src/hooks/domain/usePermissions.ts +++ b/app/src/hooks/domain/usePermissions.ts @@ -20,7 +20,7 @@ function usePermissions() { && isDefined(countryId) && !!userMe?.is_admin_for_countries?.includes(countryId) ); - const isRegionAdmin = (regionId: number | undefined) => ( + const isRegionAdmin = (regionId: number | null | undefined) => ( !isGuestUser && isDefined(regionId) && !!userMe?.is_admin_for_regions?.includes(regionId) diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/ConfirmationModal/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/ConfirmationModal/index.tsx index 6d77015b4..e9993689d 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/ConfirmationModal/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/ConfirmationModal/index.tsx @@ -111,8 +111,9 @@ function ConfirmationModal(props: Props) { const handleConfirmButtonChange = useCallback(() => { if (isNewManageLocalUnit) { addManageLocalUnit(manageLocalUnitsValues); + } else { + updateManageLocalUnit(manageLocalUnitsValues); } - updateManageLocalUnit(manageLocalUnitsValues); }, [isNewManageLocalUnit, addManageLocalUnit, manageLocalUnitsValues, updateManageLocalUnit]); diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/index.tsx index f8e5d8425..6f19f6ab9 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/index.tsx @@ -67,22 +67,13 @@ function ConfigureLocalUnitsModal(props: Props) { const handleLocalUnitSwitchChange = useCallback((value: boolean, name: number) => { setLocalUnitType(name); - if (isNotDefined(manageResponse) - && isDefined(countryResponse) - ) { - setManageLocalUnitsValues({ - id: undefined, - country: countryResponse.id, - local_unit_type: name, - enabled: value, - }); - } - if (isDefined(manageResponse) - && isDefined(manageResponse[name]) - && isDefined(countryResponse) - ) { + + if (isDefined(countryResponse)) { + const isNew = isNotDefined(manageResponse) || isNotDefined(manageResponse[name]); + const manageId = isNew ? undefined : manageResponse[name]?.externallyManagedId; + setManageLocalUnitsValues({ - id: manageResponse[name].externallyManagedId, + id: manageId, country: countryResponse.id, local_unit_type: name, enabled: value, @@ -97,8 +88,8 @@ function ConfigureLocalUnitsModal(props: Props) { ]); const isNewManageLocalUnit = useMemo(() => { - if (isDefined(manageLocalUnitsValues) - && isDefined(manageLocalUnitsValues.id)) { + if (isNotDefined(manageLocalUnitsValues) + || isNotDefined(manageLocalUnitsValues?.id)) { return true; } return false; diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/OtherProfilesDiffOutput/i18n.json b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/OtherProfilesDiffOutput/i18n.json index 64eccbeff..60a53c366 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/OtherProfilesDiffOutput/i18n.json +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/OtherProfilesDiffOutput/i18n.json @@ -1,7 +1,6 @@ { "namespace": "countryNsOverviewContextAndStructure", "strings": { - "otherProfileOutputLabel": "Other Profiles", "otherProfilePositionOutputLabel": "Position", "otherProfileNumberOutputLabel": "Number" } diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/i18n.json b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/i18n.json index 257cb93a1..c170e0448 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/i18n.json +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/i18n.json @@ -55,6 +55,7 @@ "localUnitViewDentist": "Dentist", "localUnitViewNursingAid": "Nursing aid", "localUnitViewMidwife": "Midwife", + "localUnitViewPharmacists": "Pharmacists", "localUnitViewOtherProfiles": "Other profiles", "localUnitViewRemovedOtherProfiles": "Removed Other profiles", "localUnitViewOtherMedicalHeal": "Other medical heal", diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/index.tsx index 7d15bafc3..bfec9c8fd 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/index.tsx @@ -892,6 +892,18 @@ function LocalUnitView(props: Props) { value={newValue?.health?.midwife} /> + + + {isDefined(changedOtherProfiles) && changedOtherProfiles.length > 0 && ( <> diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx index ad0e95391..a72af3fd9 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx @@ -155,6 +155,7 @@ function LocalUnitsForm(props: Props) { const { isSuperUser, isCountryAdmin, + isRegionAdmin, isLocalUnitGlobalValidatorByType, isLocalUnitRegionValidatorByType, isLocalUnitCountryValidatorByType, @@ -388,7 +389,12 @@ function LocalUnitsForm(props: Props) { || isLocalUnitRegionValidatorByType(countryResponse?.region, value.type) ); - const hasUpdatePermission = isCountryAdmin(countryResponse?.id) || hasValidatePermission; + const hasUpdatePermission = isCountryAdmin(countryResponse?.id) + || isRegionAdmin(countryResponse?.region) + || hasValidatePermission; + + const hasDeletePermission = isCountryAdmin(countryResponse?.id) + || hasValidatePermission; const handleFormSubmit = useCallback( () => { @@ -537,7 +543,7 @@ function LocalUnitsForm(props: Props) { {isDefined(localUnitDetailsResponse) && ( <> - {hasUpdatePermission && ( + {hasDeletePermission && (