Skip to content

Commit 8cd10b2

Browse files
authored
Merge pull request #1333 from IFRCGo/fix/local-unit-pop-up-heading
Local Unit Design Audit Fixes
2 parents a38912d + 4192da1 commit 8cd10b2

File tree

8 files changed

+133
-33
lines changed

8 files changed

+133
-33
lines changed

.changeset/six-hounds-film.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"go-web-app": patch
3+
---
4+
5+
- Local Units popup, view/edit mode improvements in [#1178](https://github.com/IFRCGo/go-web-app/issues/1178)
6+
- Remove ellipsize heading option in local units map popup
7+
- Local units title on popup are now clickable that opens up a modal to show details
8+
- Added an Edit button to the View Mode for users with edit permissions
9+
- Users will now see a **disabled grey button** when the content is already validated

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+
border: none;
9+
background-color: var(--go-ui-color-gray-40);
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: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ function FormColumnContainer(props: FormColumnContainerProps) {
108108
interface Props {
109109
readOnly?: boolean;
110110
onSuccess?: () => void;
111+
onEditButtonClick?: () => void;
111112
localUnitId?: number;
112-
actionsContainerRef?: RefObject<HTMLDivElement>;
113+
actionsContainerRef: RefObject<HTMLDivElement>;
113114
headingDescriptionRef?: RefObject<HTMLDivElement>;
114115
headerDescriptionRef: RefObject<HTMLDivElement>;
115116
}
@@ -118,6 +119,7 @@ function LocalUnitsForm(props: Props) {
118119
const {
119120
readOnly = false,
120121
onSuccess,
122+
onEditButtonClick,
121123
localUnitId,
122124
actionsContainerRef,
123125
headingDescriptionRef,
@@ -314,14 +316,21 @@ function LocalUnitsForm(props: Props) {
314316

315317
return (
316318
<div className={styles.localUnitsForm}>
317-
{!readOnly
318-
&& isDefined(actionsContainerRef)
319-
&& isDefined(actionsContainerRef.current)
320-
&& (
321-
<Portal container={actionsContainerRef.current}>
322-
{submitButton}
323-
</Portal>
324-
)}
319+
{readOnly && isDefined(actionsContainerRef.current) && (
320+
<Portal container={actionsContainerRef.current}>
321+
<Button
322+
name={undefined}
323+
onClick={onEditButtonClick}
324+
>
325+
{strings.editButtonLabel}
326+
</Button>
327+
</Portal>
328+
)}
329+
{!readOnly && isDefined(actionsContainerRef.current) && (
330+
<Portal container={actionsContainerRef.current}>
331+
{submitButton}
332+
</Portal>
333+
)}
325334
{isDefined(headingDescriptionRef) && isDefined(headingDescriptionRef.current) && (
326335
<Portal container={headingDescriptionRef.current}>
327336
<div className={styles.lastUpdateLabel}>

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from 'react';
55
import { Modal } from '@ifrc-go/ui';
66
import { useTranslation } from '@ifrc-go/ui/hooks';
7+
import { isDefined } from '@togglecorp/fujs';
78

89
import LocalUnitsForm from './LocalUnitsForm';
910

@@ -13,6 +14,7 @@ import styles from './styles.module.css';
1314
interface Props {
1415
localUnitId?: number;
1516
readOnly?: boolean;
17+
setReadOnly?: React.Dispatch<React.SetStateAction<boolean>>;
1618
onClose: (requestDone?: boolean) => void;
1719
}
1820

@@ -21,6 +23,7 @@ function LocalUnitsFormModal(props: Props) {
2123
onClose,
2224
localUnitId,
2325
readOnly,
26+
setReadOnly,
2427
} = props;
2528

2629
const strings = useTranslation(i18n);
@@ -29,10 +32,21 @@ function LocalUnitsFormModal(props: Props) {
2932
const headerDescriptionRef = useRef<HTMLDivElement>(null);
3033

3134
const handleSuccess = useCallback(
32-
() => { onClose(true); },
35+
() => {
36+
onClose(true);
37+
},
3338
[onClose],
3439
);
3540

41+
const handleEditButtonClick = useCallback(
42+
() => {
43+
if (isDefined(setReadOnly)) {
44+
setReadOnly(false);
45+
}
46+
},
47+
[setReadOnly],
48+
);
49+
3650
return (
3751
<Modal
3852
className={styles.localUnitsFormModal}
@@ -41,9 +55,7 @@ function LocalUnitsFormModal(props: Props) {
4155
size="pageWidth"
4256
withHeaderBorder
4357
headingLevel={2}
44-
actions={!readOnly && (
45-
<div ref={actionsContainerRef} />
46-
)}
58+
actions={<div ref={actionsContainerRef} />}
4759
headingContainerClassName={styles.headingContainer}
4860
headingDescription={
4961
<div ref={headingDescriptionRef} />
@@ -58,6 +70,7 @@ function LocalUnitsFormModal(props: Props) {
5870
localUnitId={localUnitId}
5971
onSuccess={handleSuccess}
6072
readOnly={readOnly}
73+
onEditButtonClick={handleEditButtonClick}
6174
actionsContainerRef={actionsContainerRef}
6275
headingDescriptionRef={headingDescriptionRef}
6376
headerDescriptionRef={headerDescriptionRef}

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

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
List,
1717
TextOutput,
1818
} from '@ifrc-go/ui';
19-
import { useTranslation } from '@ifrc-go/ui/hooks';
19+
import {
20+
useBooleanState,
21+
useTranslation,
22+
} from '@ifrc-go/ui/hooks';
2023
import {
2124
numericIdSelector,
2225
stringNameSelector,
@@ -65,6 +68,7 @@ import {
6568
VALIDATED,
6669
} from '../common';
6770
import type { FilterValue } from '../Filters';
71+
import LocalUnitsFormModal from '../LocalUnitsFormModal';
6872
import { TYPE_HEALTH_CARE } from '../LocalUnitsFormModal/LocalUnitsForm/schema';
6973

7074
import i18n from './i18n.json';
@@ -132,6 +136,12 @@ function LocalUnitsMap(props: Props) {
132136
} = props;
133137
const { countryResponse } = useOutletContext<CountryOutletContext>();
134138

139+
const [showLocalUnitModal, {
140+
setTrue: setShowLocalUnitViewModalTrue,
141+
setFalse: setShowLocalUnitViewModalFalse,
142+
}] = useBooleanState(false);
143+
const [readOnlyLocalUnitModal, setReadOnlyLocalUnitModal] = useState(true);
144+
135145
const urlQuery = useMemo<GoApiUrlQuery<'/api/v2/public-local-units/'>>(
136146
() => ({
137147
limit: MAX_PAGE_LIMIT,
@@ -305,6 +315,22 @@ function LocalUnitsMap(props: Props) {
305315
[setClickedPointProperties],
306316
);
307317

318+
const handleLocalUnitHeadingClick = useCallback(
319+
() => {
320+
setReadOnlyLocalUnitModal(true);
321+
setShowLocalUnitViewModalTrue();
322+
},
323+
[setShowLocalUnitViewModalTrue],
324+
);
325+
326+
const handleLocalUnitsFormModalClose = useCallback(
327+
() => {
328+
setShowLocalUnitViewModalFalse();
329+
setReadOnlyLocalUnitModal(true);
330+
},
331+
[setShowLocalUnitViewModalFalse],
332+
);
333+
308334
const emailRendererParams = useCallback(
309335
(_: string, email: string): LinkProps => ({
310336
className: styles.email,
@@ -417,13 +443,20 @@ function LocalUnitsMap(props: Props) {
417443
popupClassName={styles.mapPopup}
418444
coordinates={clickedPointProperties.lngLat}
419445
onCloseButtonClick={handlePointClose}
420-
heading={localUnitName}
446+
heading={(
447+
<Button
448+
name=""
449+
variant="tertiary"
450+
onClick={handleLocalUnitHeadingClick}
451+
>
452+
{localUnitName}
453+
</Button>
454+
)}
421455
contentViewType="vertical"
422456
pending={localUnitDetailPending}
423457
errored={isDefined(localUnitDetailError)}
424458
errorMessage={localUnitDetailError?.value.messageForNotification}
425459
compactMessage
426-
ellipsizeHeading
427460
>
428461
<TextOutput
429462
label={strings.localUnitDetailLastUpdate}
@@ -544,6 +577,14 @@ function LocalUnitsMap(props: Props) {
544577
iconElementClassName={styles.legendIcon}
545578
/>
546579
)}
580+
{(showLocalUnitModal && (
581+
<LocalUnitsFormModal
582+
onClose={handleLocalUnitsFormModalClose}
583+
localUnitId={clickedPointProperties?.localUnitId}
584+
readOnly={readOnlyLocalUnitModal}
585+
setReadOnly={setReadOnlyLocalUnitModal}
586+
/>
587+
))}
547588
</Container>
548589
);
549590
}

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { useCallback } from 'react';
1+
import {
2+
useCallback,
3+
useState,
4+
} from 'react';
25
import { TableActions } from '@ifrc-go/ui';
36
import {
47
useBooleanState,
@@ -39,26 +42,37 @@ function LocalUnitsTableActions(props: Props) {
3942

4043
const hasValidatePermission = !isGuestUser && (isSuperUser || isCountryAdmin(countryId));
4144

42-
const [showLocalUnitViewModal, {
43-
setTrue: setShowLocalUnitViewModalTrue,
44-
setFalse: setShowLocalUnitViewModalFalse,
45-
}] = useBooleanState(false);
45+
const [readOnlyLocalUnitModal, setReadOnlyLocalUnitModal] = useState(false);
4646

47-
const [showLocalUnitEditModal, {
48-
setTrue: setShowLocalUnitEditModalTrue,
49-
setFalse: setShowLocalUnitEditModalFalse,
47+
const [showLocalUnitModal, {
48+
setTrue: setShowLocalUnitModalTrue,
49+
setFalse: setShowLocalUnitModalFalse,
5050
}] = useBooleanState(false);
5151

5252
const handleLocalUnitsFormModalClose = useCallback(
5353
(shouldUpdate?: boolean) => {
54-
setShowLocalUnitEditModalFalse();
55-
setShowLocalUnitViewModalFalse();
54+
setShowLocalUnitModalFalse();
5655

5756
if (shouldUpdate) {
5857
onActionSuccess();
5958
}
6059
},
61-
[setShowLocalUnitViewModalFalse, setShowLocalUnitEditModalFalse, onActionSuccess],
60+
[setShowLocalUnitModalFalse, onActionSuccess],
61+
);
62+
63+
const handleViewLocalUnitClick = useCallback(
64+
() => {
65+
setReadOnlyLocalUnitModal(true);
66+
setShowLocalUnitModalTrue();
67+
},
68+
[setShowLocalUnitModalTrue],
69+
);
70+
const handleEditLocalUnitClick = useCallback(
71+
() => {
72+
setReadOnlyLocalUnitModal(false);
73+
setShowLocalUnitModalTrue();
74+
},
75+
[setShowLocalUnitModalTrue],
6276
);
6377

6478
return (
@@ -70,15 +84,15 @@ function LocalUnitsTableActions(props: Props) {
7084
<DropdownMenuItem
7185
type="button"
7286
name={localUnitId}
73-
onClick={setShowLocalUnitViewModalTrue}
87+
onClick={handleViewLocalUnitClick}
7488
disabled={!hasValidatePermission}
7589
>
7690
{strings.localUnitsView}
7791
</DropdownMenuItem>
7892
<DropdownMenuItem
7993
type="button"
8094
name={localUnitId}
81-
onClick={setShowLocalUnitEditModalTrue}
95+
onClick={handleEditLocalUnitClick}
8296
disabled={!hasValidatePermission}
8397
>
8498
{strings.localUnitsEdit}
@@ -101,11 +115,12 @@ function LocalUnitsTableActions(props: Props) {
101115
localUnitId={localUnitId}
102116
/>
103117
</TableActions>
104-
{(showLocalUnitViewModal || showLocalUnitEditModal) && (
118+
{showLocalUnitModal && (
105119
<LocalUnitsFormModal
106120
onClose={handleLocalUnitsFormModalClose}
107121
localUnitId={localUnitId}
108-
readOnly={showLocalUnitViewModal}
122+
readOnly={readOnlyLocalUnitModal}
123+
setReadOnly={setReadOnlyLocalUnitModal}
109124
/>
110125
)}
111126
</>

0 commit comments

Comments
 (0)