Skip to content

Commit

Permalink
Merge pull request #1368 from IFRCGo/fix/disable-local-units-actions
Browse files Browse the repository at this point in the history
disable local units edit and validation in production environment
  • Loading branch information
frozenhelium authored Sep 13, 2024
2 parents a2444df + ea19966 commit 5013c17
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import BaseMapPointInput from '#components/domain/BaseMapPointInput';
import CountrySelectInput from '#components/domain/CountrySelectInput';
import NonFieldError from '#components/NonFieldError';
import { environment } from '#config';
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
import useAlert from '#hooks/useAlert';
import { getFirstTruthyString } from '#utils/common';
Expand Down Expand Up @@ -182,8 +183,6 @@ function LocalUnitsForm(props: Props) {
},
});

const isValidated = localUnitDetailsResponse?.validated;

const {
response: localUnitsOptions,
pending: localUnitsOptionsPending,
Expand Down Expand Up @@ -318,12 +317,14 @@ function LocalUnitsForm(props: Props) {
<div className={styles.localUnitsForm}>
{readOnly && isDefined(actionsContainerRef.current) && (
<Portal container={actionsContainerRef.current}>
<Button
name={undefined}
onClick={onEditButtonClick}
>
{strings.editButtonLabel}
</Button>
{(environment !== 'production') && (
<Button
name={undefined}
onClick={onEditButtonClick}
>
{strings.editButtonLabel}
</Button>
)}
</Portal>
)}
{!readOnly && isDefined(actionsContainerRef.current) && (
Expand Down Expand Up @@ -383,7 +384,8 @@ function LocalUnitsForm(props: Props) {
{isDefined(countryId)
&& isDefined(localUnitId)
&& isDefined(onSuccess)
&& isDefined(isValidated)
&& isDefined(localUnitDetailsResponse)
&& (environment !== 'production')
&& (
<div className={styles.actions}>
<LocalUnitDeleteButton
Expand All @@ -404,7 +406,7 @@ function LocalUnitsForm(props: Props) {
value.english_branch_name,
)}
onActionSuccess={onSuccess}
isValidated={isValidated}
isValidated={localUnitDetailsResponse.validated}
disabled={!pristine}
readOnly={!pristine}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import {
useCallback,
useState,
} from 'react';
import { TableActions } from '@ifrc-go/ui';
import {
Button,
TableActions,
} from '@ifrc-go/ui';
import {
useBooleanState,
useTranslation,
} from '@ifrc-go/ui/hooks';

import DropdownMenuItem from '#components/DropdownMenuItem';
import { environment } from '#config';
import usePermissions from '#hooks/domain/usePermissions';
import { type GoApiResponse } from '#utils/restRequest';

Expand Down Expand Up @@ -79,7 +83,7 @@ function LocalUnitsTableActions(props: Props) {
<>
<TableActions
persistent
extraActions={(
extraActions={environment !== 'production' && (
<>
<DropdownMenuItem
type="button"
Expand Down Expand Up @@ -107,13 +111,24 @@ function LocalUnitsTableActions(props: Props) {
</>
)}
>
<LocalUnitValidateButton
countryId={countryId}
localUnitName={localUnitName}
isValidated={isValidated}
onActionSuccess={onActionSuccess}
localUnitId={localUnitId}
/>
{environment !== 'production' ? (
<LocalUnitValidateButton
countryId={countryId}
localUnitName={localUnitName}
isValidated={isValidated}
onActionSuccess={onActionSuccess}
localUnitId={localUnitId}
/>
) : (
<Button
name={localUnitId}
variant="tertiary"
onClick={handleViewLocalUnitClick}
disabled={!hasValidatePermission}
>
{strings.localUnitsView}
</Button>
)}
</TableActions>
{showLocalUnitModal && (
<LocalUnitsFormModal
Expand Down

0 comments on commit 5013c17

Please sign in to comment.