Skip to content

Commit 41022e6

Browse files
shreeyash07samshara
authored andcommitted
Add edit button in local unit view modal
1 parent b9e469a commit 41022e6

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CheckboxCircleLineIcon } from '@ifrc-go/icons';
33
import { ConfirmButton } from '@ifrc-go/ui';
44
import { useTranslation } from '@ifrc-go/ui/hooks';
55
import { resolveToString } from '@ifrc-go/ui/utils';
6+
import { _cs } from '@togglecorp/fujs';
67

78
import usePermissions from '#hooks/domain/usePermissions';
89
import useAlert from '#hooks/useAlert';
@@ -95,7 +96,9 @@ function LocalUnitValidateButton(props: Props) {
9596

9697
return (
9798
<ConfirmButton
98-
className={styles.localUnitValidateButton}
99+
className={_cs(isValidated
100+
? styles.localUnitValidatedButton
101+
: styles.localUnitValidateButton)}
99102
// NOTE sending an empty post request to validate the local unit
100103
name={null}
101104
spacing="compact"

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitValidateButton/styles.module.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
font-size: var(--go-ui-height-icon-multiplier);
44
}
55
}
6+
7+
.local-unit-validated-button {
8+
background-color: var(--go-ui-color-gray-40);
9+
border: none;
10+
11+
.icon {
12+
font-size: var(--go-ui-height-icon-multiplier);
13+
}
14+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"otherMedicalHeal": "Other medical heal",
7373
"otherProfiles": "Other profiles",
7474
"commentsNS": "Comments by the NS",
75-
"submitButtonLabel": "Submit"
75+
"submitButtonLabel": "Submit",
76+
"editButtonLabel": "Edit"
7677
}
7778
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function FormColumnContainer(props: FormColumnContainerProps) {
108108
interface Props {
109109
readOnly?: boolean;
110110
onSuccess?: () => void;
111+
onEditButtonClick?: () => void;
111112
localUnitId?: number;
112113
actionsContainerRef?: RefObject<HTMLDivElement>;
113114
headingDescriptionRef?: RefObject<HTMLDivElement>;
@@ -118,6 +119,7 @@ function LocalUnitsForm(props: Props) {
118119
const {
119120
readOnly = false,
120121
onSuccess,
122+
onEditButtonClick,
121123
localUnitId,
122124
actionsContainerRef,
123125
headingDescriptionRef,
@@ -387,6 +389,14 @@ function LocalUnitsForm(props: Props) {
387389
onActionSuccess={onSuccess}
388390
disabled={!pristine}
389391
/>
392+
{readOnly && (
393+
<Button
394+
name=""
395+
onClick={onEditButtonClick}
396+
>
397+
{strings.editButtonLabel}
398+
</Button>
399+
)}
390400
<LocalUnitValidateButton
391401
countryId={Number(countryId)}
392402
localUnitId={localUnitId}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
useCallback,
33
useRef,
4+
useState,
45
} from 'react';
56
import { Modal } from '@ifrc-go/ui';
67
import { useTranslation } from '@ifrc-go/ui/hooks';
@@ -12,27 +13,34 @@ import styles from './styles.module.css';
1213

1314
interface Props {
1415
localUnitId?: number;
15-
readOnly?: boolean;
16+
viewMode?: boolean;
1617
onClose: (requestDone?: boolean) => void;
1718
}
1819

1920
function LocalUnitsFormModal(props: Props) {
2021
const {
2122
onClose,
2223
localUnitId,
23-
readOnly,
24+
viewMode = false,
2425
} = props;
2526

2627
const strings = useTranslation(i18n);
2728
const actionsContainerRef = useRef<HTMLDivElement>(null);
2829
const headingDescriptionRef = useRef<HTMLDivElement>(null);
2930
const headerDescriptionRef = useRef<HTMLDivElement>(null);
3031

32+
const [readOnly, setReadOnly] = useState<boolean>(viewMode);
33+
3134
const handleSuccess = useCallback(
3235
() => { onClose(true); },
3336
[onClose],
3437
);
3538

39+
const handleEditButtonClick = useCallback(
40+
() => { setReadOnly(false); },
41+
[],
42+
);
43+
3644
return (
3745
<Modal
3846
className={styles.localUnitsFormModal}
@@ -58,6 +66,7 @@ function LocalUnitsFormModal(props: Props) {
5866
localUnitId={localUnitId}
5967
onSuccess={handleSuccess}
6068
readOnly={readOnly}
69+
onEditButtonClick={handleEditButtonClick}
6170
actionsContainerRef={actionsContainerRef}
6271
headingDescriptionRef={headingDescriptionRef}
6372
headerDescriptionRef={headerDescriptionRef}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function LocalUnitsTableActions(props: Props) {
105105
<LocalUnitsFormModal
106106
onClose={handleLocalUnitsFormModalClose}
107107
localUnitId={localUnitId}
108-
readOnly={showLocalUnitViewModal}
108+
viewMode={showLocalUnitViewModal}
109109
/>
110110
)}
111111
</>

0 commit comments

Comments
 (0)