Skip to content

Commit 7cb6d04

Browse files
committed
fix(local-unit): update add and edit permission for local unit form
1 parent 2154678 commit 7cb6d04

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
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/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.localUnitViewMidwife}
904+
value={newValue?.health?.pharmacists}
905+
/>
906+
</DiffWrapper>
895907
{isDefined(changedOtherProfiles) && changedOtherProfiles.length > 0 && (
896908
<>
897909
<span>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ function LocalUnitsForm(props: Props) {
155155
const {
156156
isSuperUser,
157157
isCountryAdmin,
158+
isRegionAdmin,
158159
isLocalUnitGlobalValidatorByType,
159160
isLocalUnitRegionValidatorByType,
160161
isLocalUnitCountryValidatorByType,
@@ -388,7 +389,9 @@ function LocalUnitsForm(props: Props) {
388389
|| isLocalUnitRegionValidatorByType(countryResponse?.region, value.type)
389390
);
390391

391-
const hasUpdatePermission = isCountryAdmin(countryResponse?.id) || hasValidatePermission;
392+
const hasUpdatePermission = isCountryAdmin(countryResponse?.id)
393+
|| isRegionAdmin(countryResponse?.region)
394+
|| hasValidatePermission;
392395

393396
const handleFormSubmit = useCallback(
394397
() => {

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

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

6971
const isLocked = status !== VALIDATED;
@@ -73,14 +75,11 @@ function LocalUnitsTableActions(props: Props) {
7375
&& isDefined(manageResponse)
7476
&& !!manageResponse[localUnitType]?.enabled);
7577

76-
const hasPermission = isAuthenticated
77-
&& !isExternallyManaged
78-
&& (isSuperUser
79-
|| isLocalUnitGlobalValidatorByType(localUnitType)
80-
|| isLocalUnitCountryValidatorByType(countryDetails?.id, localUnitType)
81-
|| isLocalUnitRegionValidatorByType(countryDetails?.region, localUnitType));
78+
const hasAddEditLocalUnitPermission = isCountryAdmin(countryDetails?.id)
79+
|| isRegionAdmin(countryDetails?.region);
8280

8381
const hasValidatePermission = isAuthenticated
82+
&& !isExternallyManaged
8483
&& (isSuperUser
8584
|| isLocalUnitGlobalValidatorByType(localUnitType)
8685
|| isLocalUnitCountryValidatorByType(countryDetails?.id, localUnitType)
@@ -165,7 +164,8 @@ function LocalUnitsTableActions(props: Props) {
165164
>
166165
{strings.localUnitActionsView}
167166
</DropdownMenuItem>
168-
{(hasPermission && !isBulkUploadLocalUnit) && (
167+
{((hasValidatePermission || hasAddEditLocalUnitPermission)
168+
&& !isBulkUploadLocalUnit) && (
169169
<DropdownMenuItem
170170
type="button"
171171
name={undefined}
@@ -174,7 +174,9 @@ function LocalUnitsTableActions(props: Props) {
174174
{strings.localUnitActionsDelete}
175175
</DropdownMenuItem>
176176
)}
177-
{!isLocked && (hasPermission && !isBulkUploadLocalUnit) && (
177+
{!isLocked && ((
178+
hasValidatePermission || hasAddEditLocalUnitPermission
179+
) && !isBulkUploadLocalUnit) && (
178180
<DropdownMenuItem
179181
type="button"
180182
name={localUnitId}
@@ -190,7 +192,7 @@ function LocalUnitsTableActions(props: Props) {
190192
<LocalUnitValidateButton
191193
onClick={handleValidateLocalUnitClick}
192194
status={status}
193-
hasValidatePermission={hasPermission}
195+
hasValidatePermission={hasValidatePermission}
194196
/>
195197
)}
196198
</TableActions>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function LocalUnitsTable(props: Props) {
5858
const {
5959
isSuperUser,
6060
isCountryAdmin,
61+
isRegionAdmin,
6162
isLocalUnitGlobalValidator,
6263
isLocalUnitRegionValidator,
6364
isLocalUnitCountryValidator,
@@ -71,6 +72,7 @@ function LocalUnitsTable(props: Props) {
7172
|| isLocalUnitRegionValidator(countryResponse?.region ?? undefined);
7273

7374
const hasAddEditLocalUnitPermission = isCountryAdmin(countryResponse?.id)
75+
|| isRegionAdmin(countryResponse?.region)
7476
|| hasPermission;
7577

7678
const {

0 commit comments

Comments
 (0)