Skip to content

Commit bfcaecf

Browse files
samsharafrozenhelium
authored andcommitted
Updates in DREF imminent Application
* Revert commit 44623a7. * Change summary information in dref export when type is imminent * Hide and unhide the form fields in eventdetails section in dref when type is imminent * Update names of the submission form field section * Add Activity input in proposed action for the dref type imminent * Integrate feedback for DREF imminent changes * Add proposed actions icons * Show proposed actions for existing imminent dref applications * Hide unused sections for dref imminent export and preserve proposed actions order * Prevent selection of past dates for the `hazard_date` in dref imminent * Add a confirmation popup before creating ops. update from imminent dref * Add auto total population calculation in dref * Add imminent flag for active dref table * Update operational end date label * Update allocation form for dref imminent * Update logic for creation of dref final report for imminent * Disable ops update in old imminent drefs
1 parent 2de417a commit bfcaecf

File tree

60 files changed

+4238
-1191
lines changed

Some content is hidden

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

60 files changed

+4238
-1191
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 & 7 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,46 @@ 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,
61104
is_pga: false,
62105
};
63106
},
64-
[id, applicationType],
107+
[
108+
id,
109+
isPga,
110+
applicationType,
111+
],
65112
);
66113

114+
const {
115+
pending: pendingDrefImminentExportTrigger,
116+
error: drefImminentExportError,
117+
trigger: drefImminentExportTrigger,
118+
} = useLazyRequest({
119+
method: 'POST',
120+
useCurrentLanguageForMutation: true,
121+
url: '/api/v2/pdf-export/',
122+
body: drefExportTriggerBody,
123+
onSuccess: (response) => {
124+
if (isDefined(response.id)) {
125+
setExportId(response.id);
126+
}
127+
},
128+
onFailure: () => {
129+
alert.show(
130+
strings.drefFailureToExportMessage,
131+
{ variant: 'danger' },
132+
);
133+
},
134+
});
135+
67136
const {
68137
pending: pendingExportTrigger,
69138
error: exportTriggerError,
70139
} = useRequest({
71-
skip: isDefined(exportId) || isNotDefined(id),
140+
skip: isDefined(exportId) || isNotDefined(id) || drefType === DREF_TYPE_IMMINENT,
72141
method: 'POST',
73142
useCurrentLanguageForMutation: true,
74143
url: '/api/v2/pdf-export/',
@@ -78,6 +147,12 @@ function DrefExportModal(props: Props) {
78147
setExportId(response.id);
79148
}
80149
},
150+
onFailure: () => {
151+
alert.show(
152+
strings.drefFailureToExportMessage,
153+
{ variant: 'danger' },
154+
);
155+
},
81156
});
82157

83158
const {
@@ -98,18 +173,40 @@ function DrefExportModal(props: Props) {
98173
},
99174
});
100175

176+
const handleDrefImminent = useCallback(() => {
177+
setIsPgaCheckboxVisible(false);
178+
drefImminentExportTrigger(drefExportTriggerBody);
179+
}, [
180+
drefExportTriggerBody,
181+
drefImminentExportTrigger,
182+
]);
183+
101184
return (
102185
<Modal
103186
heading={strings.drefExportTitle}
104187
onClose={onCancel}
105188
>
106-
{pendingExportTrigger && (
189+
{drefType === DREF_TYPE_IMMINENT
190+
&& isPgaCheckboxVisible
191+
&& !(pendingExportTrigger
192+
|| pendingExportStatus
193+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
194+
&& (
195+
<Checkbox
196+
name={undefined}
197+
value={isPga}
198+
onChange={setIsPga}
199+
label={strings.drefDownloadPDFWithPGA}
200+
/>
201+
)}
202+
{pendingExportTrigger && pendingDrefImminentExportTrigger && (
107203
<Message
108204
pending
109205
title={strings.drefPreparingExport}
110206
/>
111207
)}
112-
{(pendingExportStatus || exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
208+
{(pendingExportStatus
209+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
113210
<Message
114211
pending
115212
title={strings.drefWaitingExport}
@@ -118,16 +215,52 @@ function DrefExportModal(props: Props) {
118215
{(exportStatusResponse?.status === EXPORT_STATUS_ERRORED
119216
|| isDefined(exportTriggerError)
120217
|| isDefined(exportStatusError)
218+
|| isDefined(drefImminentExportError)
121219
) && (
122220
<Message
123221
title={strings.drefExportFailed}
124222
description={exportTriggerError?.value.messageForNotification
125-
?? exportStatusError?.value.messageForNotification}
223+
?? exportStatusError?.value.messageForNotification
224+
?? drefImminentExportError?.value.messageForNotification}
126225
/>
127226
)}
227+
{!(pendingExportTrigger
228+
|| pendingExportStatus
229+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
230+
&& drefType === DREF_TYPE_IMMINENT
231+
&& !drefImminentExportError && (
232+
exportStatusResponse?.pdf_file ? (
233+
<Message
234+
title={strings.drefExportSuccessfully}
235+
description={strings.drefClickDownloadLink}
236+
actions={(
237+
<Link
238+
variant="secondary"
239+
href={exportStatusResponse?.pdf_file}
240+
external
241+
>
242+
{strings.drefDownloadPDF}
243+
</Link>
244+
)}
245+
/>
246+
) : (!exportStatusResponse && (
247+
<div className={styles.downloadButton}>
248+
<Button
249+
variant="secondary"
250+
name={undefined}
251+
onClick={handleDrefImminent}
252+
>
253+
{isPga
254+
? strings.drefDownloadPDFWithPGA
255+
: strings.drefDownloadPDFwithoutPGA}
256+
</Button>
257+
</div>
258+
))
259+
)}
128260
{isDefined(exportStatusResponse)
129261
&& exportStatusResponse.status === EXPORT_STATUS_COMPLETED
130-
&& isDefined(exportStatusResponse.pdf_file) && (
262+
&& isDefined(exportStatusResponse.pdf_file)
263+
&& drefType !== DREF_TYPE_IMMINENT && (
131264
<Message
132265
title={strings.drefExportSuccessfully}
133266
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/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
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,7 @@ function RiskSeasonalMap(props: Props) {
980980
{dataPending && <BlockLoading />}
981981
{!dataPending && (isNotDefined(filteredData) || filteredData?.length === 0) && (
982982
<Message
983-
// FIXME: add translations
984-
title="Data not available for selected filters"
983+
title={strings.riskDataNotAvailable}
985984
/>
986985
)}
987986
{/* FIXME: use List */}

0 commit comments

Comments
 (0)