Skip to content

Commit 884553f

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

File tree

4 files changed

+23
-26
lines changed
  • app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits

4 files changed

+23
-26
lines changed

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/LocalUnitsFormModal/LocalUnitsForm/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ function LocalUnitsForm(props: Props) {
393393
|| isRegionAdmin(countryResponse?.region)
394394
|| hasValidatePermission;
395395

396+
const hasDeletePermission = isCountryAdmin(countryResponse?.id)
397+
|| hasValidatePermission;
398+
396399
const handleFormSubmit = useCallback(
397400
() => {
398401
const result = validate();
@@ -540,7 +543,7 @@ function LocalUnitsForm(props: Props) {
540543
<Portal container={actionsContainerRef.current}>
541544
{isDefined(localUnitDetailsResponse) && (
542545
<>
543-
{hasUpdatePermission && (
546+
{hasDeletePermission && (
544547
<Button
545548
name={undefined}
546549
onClick={setShowDeleteLocalUnitModalTrue}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,25 @@ function LocalUnitsTableActions(props: Props) {
7070

7171
const isLocked = status !== VALIDATED;
7272

73+
const countryAdmin = isCountryAdmin(countryDetails?.id);
74+
const regionAdmin = isRegionAdmin(countryDetails?.region);
75+
7376
const isExternallyManaged = status === EXTERNALLY_MANAGED
7477
|| (isDefined(localUnitType)
7578
&& isDefined(manageResponse)
7679
&& !!manageResponse[localUnitType]?.enabled);
7780

78-
const hasAddEditLocalUnitPermission = isCountryAdmin(countryDetails?.id)
79-
|| isRegionAdmin(countryDetails?.region);
80-
8181
const hasValidatePermission = isAuthenticated
8282
&& !isExternallyManaged
8383
&& (isSuperUser
8484
|| isLocalUnitGlobalValidatorByType(localUnitType)
8585
|| isLocalUnitCountryValidatorByType(countryDetails?.id, localUnitType)
8686
|| isLocalUnitRegionValidatorByType(countryDetails?.region, localUnitType));
8787

88+
const hasAddEditLocalUnitPermission = !isLocked && (
89+
(hasValidatePermission || countryAdmin || regionAdmin)
90+
&& !isBulkUploadLocalUnit);
91+
8892
const [readOnlyLocalUnitModal, setReadOnlyLocalUnitModal] = useState(false);
8993

9094
const [
@@ -164,7 +168,7 @@ function LocalUnitsTableActions(props: Props) {
164168
>
165169
{strings.localUnitActionsView}
166170
</DropdownMenuItem>
167-
{((hasValidatePermission || hasAddEditLocalUnitPermission)
171+
{((hasValidatePermission || countryAdmin)
168172
&& !isBulkUploadLocalUnit) && (
169173
<DropdownMenuItem
170174
type="button"
@@ -174,9 +178,7 @@ function LocalUnitsTableActions(props: Props) {
174178
{strings.localUnitActionsDelete}
175179
</DropdownMenuItem>
176180
)}
177-
{!isLocked && ((
178-
hasValidatePermission || hasAddEditLocalUnitPermission
179-
) && !isBulkUploadLocalUnit) && (
181+
{hasAddEditLocalUnitPermission && (
180182
<DropdownMenuItem
181183
type="button"
182184
name={localUnitId}

0 commit comments

Comments
 (0)