Skip to content

Commit 64644ae

Browse files
authored
Merge pull request #1674 from IFRCGo/project/dref-imminent
project: DREF Imminent Changes
2 parents 2de417a + 615e383 commit 64644ae

File tree

63 files changed

+4267
-1201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4267
-1201
lines changed

.changeset/modern-hats-fry.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"go-web-app": minor
3+
---
4+
5+
Address [Dref imminent Application](https://github.com/IFRCGo/go-web-app/issues/1455)
6+
- Update logic for creation of dref final report for imminent
7+
- Update allocatioon form for dref imminent
8+
- Add Activity input in proposed action for dref type imminent
9+
- Add proposed actions icons
10+
- Show proposed actions for existing imminent dref applications
11+
- Hide unused sections for dref imminent export and preserve proposed actions order
12+
- Prevent selection of past dates for the `hazard_date` in dref imminent
13+
- Add auto total population calculation in dref
14+
- Add a confirmation popup before creating ops. update from imminent dref

.changeset/short-otters-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ifrc-go/ui": patch
3+
---
4+
5+
Add `addNumDaysToDate` and `ceilToEndOfMonth` date helper functions
Lines changed: 16 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Loading

app/src/components/Navbar/i18n.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"userMenuSurge":"The section displays the summary of deployments within current and ongoing emergencies. Login to see available details",
5757
"userMenuSurgeGlobalOverview":"Surge Global Overview",
5858
"userMenuOperationalToolbox":"Operational Toolbox",
59-
"userMenuCatalogueSurgeServices":"Catalogue of Surge services",
59+
"userMenuCatalogueSurgeServices":"Catalogue of Surge Services",
6060
"userMenuLearnLabel":"Learn",
6161
"userMenuTools":"Tools",
6262
"userMenuResources":"Resources",
@@ -65,8 +65,8 @@
6565
"userMenuOperationalLearningDescription":"Operational learning in emergencies is the lesson learned from managing and dealing with crises, refining protocols for resource allocation, decision-making, communication strategies, and others.",
6666
"userMenuOperationalToolboxItem":"Operational Toolbox",
6767
"userMenuOperationalToolboxItemDescription":"This operational toolbox is a central repository with key operational document helpful for your mission like templates, checklists, guidance and examples.",
68-
"userMenuCatalogueSurgeServicesItem": "Catalogue of Surge services",
69-
"userMenuCatalogueSurgeServicesItemDescription":"Catalogue of Surge services contains all relevant content and materials related to Surge.",
68+
"userMenuCatalogueSurgeServicesItem": "Catalogue of Surge Services",
69+
"userMenuCatalogueSurgeServicesItemDescription":"Catalogue of Surge Services contains all relevant content and materials related to Surge.",
7070
"userMenuPERCatalogueItem":"PER Catalogue of Resources",
7171
"userMenuPERCatalogueItemDescription":"PER Catalogue of Resources contains resource relevant to strengthening resource and capacity.",
7272
"userMenuGoResourcesItem":"GO Resources",

app/src/components/domain/DrefExportModal/i18n.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"drefExportFailed": "Export failed",
88
"drefExportSuccessfully": "Export completed successfully",
99
"drefClickDownloadLink": "Click on the download link below!",
10-
"drefDownloadPDF": "Download PDF"
10+
"drefDownloadPDF": "Download PDF",
11+
"drefDownloadPDFWithPGA": "Download PDF with PGA",
12+
"drefDownloadPDFwithoutPGA": "Download PDF without PGA",
13+
"drefFailureToExportMessage":"Failed to export PDF."
1114
}
1215
}

app/src/components/domain/DrefExportModal/index.tsx

Lines changed: 140 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import {
2+
useCallback,
23
useMemo,
34
useState,
45
} from 'react';
56
import {
7+
Button,
8+
Checkbox,
69
Message,
710
Modal,
811
} from '@ifrc-go/ui';
@@ -14,9 +17,18 @@ import {
1417

1518
import Link from '#components/Link';
1619
import { type components } from '#generated/types';
17-
import { useRequest } from '#utils/restRequest';
20+
import useAlert from '#hooks/useAlert';
21+
import {
22+
DREF_TYPE_IMMINENT,
23+
type TypeOfDrefEnum,
24+
} from '#utils/constants';
25+
import {
26+
useLazyRequest,
27+
useRequest,
28+
} from '#utils/restRequest';
1829

1930
import i18n from './i18n.json';
31+
import styles from './styles.module.css';
2032

2133
type ExportTypeEnum = components<'read'>['schemas']['ExportTypeEnum'];
2234
type ExportStatusEnum = components<'read'>['schemas']['ExportStatusEnum'];
@@ -29,18 +41,48 @@ interface Props {
2941
id: number;
3042
onCancel: () => void;
3143
applicationType: 'DREF' | 'OPS_UPDATE' | 'FINAL_REPORT';
44+
drefType?: TypeOfDrefEnum | null;
3245
}
3346

3447
function DrefExportModal(props: Props) {
3548
const {
3649
id,
3750
onCancel,
3851
applicationType,
52+
drefType,
3953
} = props;
4054

4155
const strings = useTranslation(i18n);
56+
const alert = useAlert();
4257

4358
const [exportId, setExportId] = useState<number | undefined>();
59+
const [isPga, setIsPga] = useState<boolean>(false);
60+
const [isPgaCheckboxVisible, setIsPgaCheckboxVisible] = useState(true);
61+
62+
const drefExportTriggerBody = useMemo(
63+
() => {
64+
let type: ExportTypeEnum;
65+
if (applicationType === 'OPS_UPDATE') {
66+
type = 'dref-operational-updates';
67+
} else if (applicationType === 'FINAL_REPORT') {
68+
type = 'dref-final-reports';
69+
} else {
70+
type = 'dref-applications';
71+
}
72+
return {
73+
export_id: id,
74+
export_type: type,
75+
is_pga: isPga,
76+
selector: '#pdf-preview-ready',
77+
per_country: undefined,
78+
};
79+
},
80+
[
81+
id,
82+
isPga,
83+
applicationType,
84+
],
85+
);
4486

4587
const exportTriggerBody = useMemo(
4688
() => {
@@ -56,19 +98,45 @@ function DrefExportModal(props: Props) {
5698
return {
5799
export_id: id,
58100
export_type: type,
101+
is_pga: isPga,
59102
selector: '#pdf-preview-ready',
60103
per_country: undefined,
61-
is_pga: false,
62104
};
63105
},
64-
[id, applicationType],
106+
[
107+
id,
108+
isPga,
109+
applicationType,
110+
],
65111
);
66112

113+
const {
114+
pending: pendingDrefImminentExportTrigger,
115+
error: drefImminentExportError,
116+
trigger: drefImminentExportTrigger,
117+
} = useLazyRequest({
118+
method: 'POST',
119+
useCurrentLanguageForMutation: true,
120+
url: '/api/v2/pdf-export/',
121+
body: drefExportTriggerBody,
122+
onSuccess: (response) => {
123+
if (isDefined(response.id)) {
124+
setExportId(response.id);
125+
}
126+
},
127+
onFailure: () => {
128+
alert.show(
129+
strings.drefFailureToExportMessage,
130+
{ variant: 'danger' },
131+
);
132+
},
133+
});
134+
67135
const {
68136
pending: pendingExportTrigger,
69137
error: exportTriggerError,
70138
} = useRequest({
71-
skip: isDefined(exportId) || isNotDefined(id),
139+
skip: isDefined(exportId) || isNotDefined(id) || drefType === DREF_TYPE_IMMINENT,
72140
method: 'POST',
73141
useCurrentLanguageForMutation: true,
74142
url: '/api/v2/pdf-export/',
@@ -78,6 +146,12 @@ function DrefExportModal(props: Props) {
78146
setExportId(response.id);
79147
}
80148
},
149+
onFailure: () => {
150+
alert.show(
151+
strings.drefFailureToExportMessage,
152+
{ variant: 'danger' },
153+
);
154+
},
81155
});
82156

83157
const {
@@ -98,18 +172,40 @@ function DrefExportModal(props: Props) {
98172
},
99173
});
100174

175+
const handleDrefImminent = useCallback(() => {
176+
setIsPgaCheckboxVisible(false);
177+
drefImminentExportTrigger(drefExportTriggerBody);
178+
}, [
179+
drefExportTriggerBody,
180+
drefImminentExportTrigger,
181+
]);
182+
101183
return (
102184
<Modal
103185
heading={strings.drefExportTitle}
104186
onClose={onCancel}
105187
>
106-
{pendingExportTrigger && (
188+
{drefType === DREF_TYPE_IMMINENT
189+
&& isPgaCheckboxVisible
190+
&& !(pendingExportTrigger
191+
|| pendingExportStatus
192+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
193+
&& (
194+
<Checkbox
195+
name={undefined}
196+
value={isPga}
197+
onChange={setIsPga}
198+
label={strings.drefDownloadPDFWithPGA}
199+
/>
200+
)}
201+
{pendingExportTrigger && pendingDrefImminentExportTrigger && (
107202
<Message
108203
pending
109204
title={strings.drefPreparingExport}
110205
/>
111206
)}
112-
{(pendingExportStatus || exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
207+
{(pendingExportStatus
208+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
113209
<Message
114210
pending
115211
title={strings.drefWaitingExport}
@@ -118,16 +214,52 @@ function DrefExportModal(props: Props) {
118214
{(exportStatusResponse?.status === EXPORT_STATUS_ERRORED
119215
|| isDefined(exportTriggerError)
120216
|| isDefined(exportStatusError)
217+
|| isDefined(drefImminentExportError)
121218
) && (
122219
<Message
123220
title={strings.drefExportFailed}
124221
description={exportTriggerError?.value.messageForNotification
125-
?? exportStatusError?.value.messageForNotification}
222+
?? exportStatusError?.value.messageForNotification
223+
?? drefImminentExportError?.value.messageForNotification}
126224
/>
127225
)}
226+
{!(pendingExportTrigger
227+
|| pendingExportStatus
228+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
229+
&& drefType === DREF_TYPE_IMMINENT
230+
&& !drefImminentExportError && (
231+
exportStatusResponse?.pdf_file ? (
232+
<Message
233+
title={strings.drefExportSuccessfully}
234+
description={strings.drefClickDownloadLink}
235+
actions={(
236+
<Link
237+
variant="secondary"
238+
href={exportStatusResponse?.pdf_file}
239+
external
240+
>
241+
{strings.drefDownloadPDF}
242+
</Link>
243+
)}
244+
/>
245+
) : (!exportStatusResponse && (
246+
<div className={styles.downloadButton}>
247+
<Button
248+
variant="secondary"
249+
name={undefined}
250+
onClick={handleDrefImminent}
251+
>
252+
{isPga
253+
? strings.drefDownloadPDFWithPGA
254+
: strings.drefDownloadPDFwithoutPGA}
255+
</Button>
256+
</div>
257+
))
258+
)}
128259
{isDefined(exportStatusResponse)
129260
&& exportStatusResponse.status === EXPORT_STATUS_COMPLETED
130-
&& isDefined(exportStatusResponse.pdf_file) && (
261+
&& isDefined(exportStatusResponse.pdf_file)
262+
&& drefType !== DREF_TYPE_IMMINENT && (
131263
<Message
132264
title={strings.drefExportSuccessfully}
133265
description={strings.drefClickDownloadLink}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.download-button {
2+
display: flex;
3+
align-items: center;
4+
flex-direction: column;
5+
padding: var(--go-ui-spacing-md);
6+
}

app/src/components/domain/GoSingleFileInput/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function GoSingleFileInput<T extends NameType>(props: Props<T>) {
9696
onSuccess();
9797
}
9898

99-
if (isDefined(file) && setFileIdToUrlMap) {
99+
if (isDefined(file) && isDefined(id) && setFileIdToUrlMap) {
100100
setFileIdToUrlMap((oldMap) => {
101101
const newMap = {
102102
...oldMap,

app/src/components/domain/RiskSeasonalMap/i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"riskCategoryVeryHigh": "Very High",
1818
"riskSeasonalMapHeading": "Risk Map",
1919
"riskSeasonalCountriesByRiskHeading": "Countries by Risk",
20-
"riskPopupLabel": "Risk"
20+
"riskPopupLabel": "Risk",
21+
"riskDataNotAvailable": "Data not available for selected filters"
2122
}
2223
}

0 commit comments

Comments
 (0)