Skip to content

Commit 533f1f8

Browse files
authored
Merge pull request #2071 from IFRCGo/fix/local-unit-fields
Pharmacist form field in local unit form
2 parents 5b3fec8 + e7804e9 commit 533f1f8

File tree

12 files changed

+232
-198
lines changed

12 files changed

+232
-198
lines changed

app/src/hooks/domain/usePermissions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function usePermissions() {
2020
&& isDefined(countryId)
2121
&& !!userMe?.is_admin_for_countries?.includes(countryId)
2222
);
23-
const isRegionAdmin = (regionId: number | undefined) => (
23+
const isRegionAdmin = (regionId: number | null | undefined) => (
2424
!isGuestUser
2525
&& isDefined(regionId)
2626
&& !!userMe?.is_admin_for_regions?.includes(regionId)

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/ConfirmationModal/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ function ConfirmationModal(props: Props) {
111111
const handleConfirmButtonChange = useCallback(() => {
112112
if (isNewManageLocalUnit) {
113113
addManageLocalUnit(manageLocalUnitsValues);
114+
} else {
115+
updateManageLocalUnit(manageLocalUnitsValues);
114116
}
115-
updateManageLocalUnit(manageLocalUnitsValues);
116117
}, [isNewManageLocalUnit,
117118
addManageLocalUnit, manageLocalUnitsValues, updateManageLocalUnit]);
118119

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/ConfigureLocalUnitsModal/index.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,13 @@ function ConfigureLocalUnitsModal(props: Props) {
6767

6868
const handleLocalUnitSwitchChange = useCallback((value: boolean, name: number) => {
6969
setLocalUnitType(name);
70-
if (isNotDefined(manageResponse)
71-
&& isDefined(countryResponse)
72-
) {
73-
setManageLocalUnitsValues({
74-
id: undefined,
75-
country: countryResponse.id,
76-
local_unit_type: name,
77-
enabled: value,
78-
});
79-
}
80-
if (isDefined(manageResponse)
81-
&& isDefined(manageResponse[name])
82-
&& isDefined(countryResponse)
83-
) {
70+
71+
if (isDefined(countryResponse)) {
72+
const isNew = isNotDefined(manageResponse) || isNotDefined(manageResponse[name]);
73+
const manageId = isNew ? undefined : manageResponse[name]?.externallyManagedId;
74+
8475
setManageLocalUnitsValues({
85-
id: manageResponse[name].externallyManagedId,
76+
id: manageId,
8677
country: countryResponse.id,
8778
local_unit_type: name,
8879
enabled: value,
@@ -97,8 +88,8 @@ function ConfigureLocalUnitsModal(props: Props) {
9788
]);
9889

9990
const isNewManageLocalUnit = useMemo(() => {
100-
if (isDefined(manageLocalUnitsValues)
101-
&& isDefined(manageLocalUnitsValues.id)) {
91+
if (isNotDefined(manageLocalUnitsValues)
92+
|| isNotDefined(manageLocalUnitsValues?.id)) {
10293
return true;
10394
}
10495
return false;

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/OtherProfilesDiffOutput/i18n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"namespace": "countryNsOverviewContextAndStructure",
33
"strings": {
4-
"otherProfileOutputLabel": "Other Profiles",
54
"otherProfilePositionOutputLabel": "Position",
65
"otherProfileNumberOutputLabel": "Number"
76
}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/i18n.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"localUnitViewDentist": "Dentist",
5656
"localUnitViewNursingAid": "Nursing aid",
5757
"localUnitViewMidwife": "Midwife",
58+
"localUnitViewPharmacists": "Pharmacists",
5859
"localUnitViewOtherProfiles": "Other profiles",
5960
"localUnitViewRemovedOtherProfiles": "Removed Other profiles",
6061
"localUnitViewOtherMedicalHeal": "Other medical heal",

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitView/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,18 @@ function LocalUnitView(props: Props) {
892892
value={newValue?.health?.midwife}
893893
/>
894894
</DiffWrapper>
895+
<DiffWrapper
896+
hideOnPristine
897+
value={newValue?.health?.pharmacists}
898+
previousValue={oldValue?.health?.pharmacists}
899+
diffViewEnabled
900+
>
901+
<TextOutput
902+
strongValue
903+
label={strings.localUnitViewPharmacists}
904+
value={newValue?.health?.pharmacists}
905+
/>
906+
</DiffWrapper>
895907
{isDefined(changedOtherProfiles) && changedOtherProfiles.length > 0 && (
896908
<>
897909
<span>

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/i18n.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"dentist": "Dentist",
6868
"nursingAid": "Nursing aid",
6969
"midwife": "Midwife",
70+
"pharmacists": "Pharmacists",
7071
"otherMedicalHeal": "Other medical heal",
7172
"commentsNS": "Comments by the NS",
7273
"addOtherProfilesButtonLabel": "Add Other Profiles",

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

Lines changed: 185 additions & 168 deletions
Large diffs are not rendered by default.

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ const schema: LocalUnitsFormSchema = {
162162
],
163163
},
164164
focal_point_position: {
165+
required: true,
165166
validations: [lengthSmallerThanCondition(50)],
166167
},
167168
focal_point_phone_number: {
@@ -250,6 +251,11 @@ const schema: LocalUnitsFormSchema = {
250251
positiveIntegerCondition,
251252
],
252253
},
254+
pharmacists: {
255+
validations: [
256+
positiveIntegerCondition,
257+
],
258+
},
253259
other_medical_heal: {},
254260
other_profiles: {
255261
keySelector: (item) => item.client_id,

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/LocalUnitTableActions/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,30 @@ function LocalUnitsTableActions(props: Props) {
6464
isLocalUnitRegionValidatorByType,
6565
isSuperUser,
6666
isGuestUser,
67+
isCountryAdmin,
68+
isRegionAdmin,
6769
} = usePermissions();
6870

6971
const isLocked = status !== VALIDATED;
7072

73+
const countryAdmin = isCountryAdmin(countryDetails?.id);
74+
const regionAdmin = isRegionAdmin(countryDetails?.region);
75+
7176
const isExternallyManaged = status === EXTERNALLY_MANAGED
7277
|| (isDefined(localUnitType)
7378
&& isDefined(manageResponse)
7479
&& !!manageResponse[localUnitType]?.enabled);
7580

76-
const hasPermission = isAuthenticated
81+
const hasValidatePermission = isAuthenticated
7782
&& !isExternallyManaged
7883
&& (isSuperUser
7984
|| isLocalUnitGlobalValidatorByType(localUnitType)
8085
|| isLocalUnitCountryValidatorByType(countryDetails?.id, localUnitType)
8186
|| isLocalUnitRegionValidatorByType(countryDetails?.region, localUnitType));
8287

83-
const hasValidatePermission = isAuthenticated
84-
&& (isSuperUser
85-
|| isLocalUnitGlobalValidatorByType(localUnitType)
86-
|| isLocalUnitCountryValidatorByType(countryDetails?.id, localUnitType)
87-
|| isLocalUnitRegionValidatorByType(countryDetails?.region, localUnitType));
88+
const hasAddEditLocalUnitPermission = !isLocked && (
89+
(hasValidatePermission || countryAdmin || regionAdmin)
90+
&& !isBulkUploadLocalUnit);
8891

8992
const [readOnlyLocalUnitModal, setReadOnlyLocalUnitModal] = useState(false);
9093

@@ -165,7 +168,8 @@ function LocalUnitsTableActions(props: Props) {
165168
>
166169
{strings.localUnitActionsView}
167170
</DropdownMenuItem>
168-
{(hasPermission && !isBulkUploadLocalUnit) && (
171+
{((hasValidatePermission || countryAdmin)
172+
&& !isBulkUploadLocalUnit) && (
169173
<DropdownMenuItem
170174
type="button"
171175
name={undefined}
@@ -174,7 +178,7 @@ function LocalUnitsTableActions(props: Props) {
174178
{strings.localUnitActionsDelete}
175179
</DropdownMenuItem>
176180
)}
177-
{!isLocked && (hasPermission && !isBulkUploadLocalUnit) && (
181+
{hasAddEditLocalUnitPermission && (
178182
<DropdownMenuItem
179183
type="button"
180184
name={localUnitId}
@@ -190,7 +194,7 @@ function LocalUnitsTableActions(props: Props) {
190194
<LocalUnitValidateButton
191195
onClick={handleValidateLocalUnitClick}
192196
status={status}
193-
hasValidatePermission={hasPermission}
197+
hasValidatePermission={hasValidatePermission}
194198
/>
195199
)}
196200
</TableActions>

0 commit comments

Comments
 (0)