Skip to content

Commit 5013c17

Browse files
authored
Merge pull request #1368 from IFRCGo/fix/disable-local-units-actions
disable local units edit and validation in production environment
2 parents a2444df + ea19966 commit 5013c17

File tree

2 files changed

+36
-19
lines changed
  • app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits

2 files changed

+36
-19
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
import BaseMapPointInput from '#components/domain/BaseMapPointInput';
4141
import CountrySelectInput from '#components/domain/CountrySelectInput';
4242
import NonFieldError from '#components/NonFieldError';
43+
import { environment } from '#config';
4344
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
4445
import useAlert from '#hooks/useAlert';
4546
import { getFirstTruthyString } from '#utils/common';
@@ -182,8 +183,6 @@ function LocalUnitsForm(props: Props) {
182183
},
183184
});
184185

185-
const isValidated = localUnitDetailsResponse?.validated;
186-
187186
const {
188187
response: localUnitsOptions,
189188
pending: localUnitsOptionsPending,
@@ -318,12 +317,14 @@ function LocalUnitsForm(props: Props) {
318317
<div className={styles.localUnitsForm}>
319318
{readOnly && isDefined(actionsContainerRef.current) && (
320319
<Portal container={actionsContainerRef.current}>
321-
<Button
322-
name={undefined}
323-
onClick={onEditButtonClick}
324-
>
325-
{strings.editButtonLabel}
326-
</Button>
320+
{(environment !== 'production') && (
321+
<Button
322+
name={undefined}
323+
onClick={onEditButtonClick}
324+
>
325+
{strings.editButtonLabel}
326+
</Button>
327+
)}
327328
</Portal>
328329
)}
329330
{!readOnly && isDefined(actionsContainerRef.current) && (
@@ -383,7 +384,8 @@ function LocalUnitsForm(props: Props) {
383384
{isDefined(countryId)
384385
&& isDefined(localUnitId)
385386
&& isDefined(onSuccess)
386-
&& isDefined(isValidated)
387+
&& isDefined(localUnitDetailsResponse)
388+
&& (environment !== 'production')
387389
&& (
388390
<div className={styles.actions}>
389391
<LocalUnitDeleteButton
@@ -404,7 +406,7 @@ function LocalUnitsForm(props: Props) {
404406
value.english_branch_name,
405407
)}
406408
onActionSuccess={onSuccess}
407-
isValidated={isValidated}
409+
isValidated={localUnitDetailsResponse.validated}
408410
disabled={!pristine}
409411
readOnly={!pristine}
410412
/>

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import {
22
useCallback,
33
useState,
44
} from 'react';
5-
import { TableActions } from '@ifrc-go/ui';
5+
import {
6+
Button,
7+
TableActions,
8+
} from '@ifrc-go/ui';
69
import {
710
useBooleanState,
811
useTranslation,
912
} from '@ifrc-go/ui/hooks';
1013

1114
import DropdownMenuItem from '#components/DropdownMenuItem';
15+
import { environment } from '#config';
1216
import usePermissions from '#hooks/domain/usePermissions';
1317
import { type GoApiResponse } from '#utils/restRequest';
1418

@@ -79,7 +83,7 @@ function LocalUnitsTableActions(props: Props) {
7983
<>
8084
<TableActions
8185
persistent
82-
extraActions={(
86+
extraActions={environment !== 'production' && (
8387
<>
8488
<DropdownMenuItem
8589
type="button"
@@ -107,13 +111,24 @@ function LocalUnitsTableActions(props: Props) {
107111
</>
108112
)}
109113
>
110-
<LocalUnitValidateButton
111-
countryId={countryId}
112-
localUnitName={localUnitName}
113-
isValidated={isValidated}
114-
onActionSuccess={onActionSuccess}
115-
localUnitId={localUnitId}
116-
/>
114+
{environment !== 'production' ? (
115+
<LocalUnitValidateButton
116+
countryId={countryId}
117+
localUnitName={localUnitName}
118+
isValidated={isValidated}
119+
onActionSuccess={onActionSuccess}
120+
localUnitId={localUnitId}
121+
/>
122+
) : (
123+
<Button
124+
name={localUnitId}
125+
variant="tertiary"
126+
onClick={handleViewLocalUnitClick}
127+
disabled={!hasValidatePermission}
128+
>
129+
{strings.localUnitsView}
130+
</Button>
131+
)}
117132
</TableActions>
118133
{showLocalUnitModal && (
119134
<LocalUnitsFormModal

0 commit comments

Comments
 (0)