Skip to content

Commit 4c98587

Browse files
samsharafrozenhelium
authored andcommitted
Resurrect DREF imminent changes
This reverts commit 44623a7.
1 parent 1db2bda commit 4c98587

File tree

31 files changed

+2112
-1133
lines changed

31 files changed

+2112
-1133
lines changed

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

+4-1
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

+138-7
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
() => {
@@ -60,14 +102,39 @@ function DrefExportModal(props: Props) {
60102
per_country: undefined, // FIXME: typing is altered by the useRequest function
61103
};
62104
},
63-
[id, applicationType],
105+
[
106+
id,
107+
applicationType,
108+
],
64109
);
65110

111+
const {
112+
pending: pendingDrefImminentExportTrigger,
113+
error: drefImminentExportError,
114+
trigger: drefImminentExportTrigger,
115+
} = useLazyRequest({
116+
method: 'POST',
117+
useCurrentLanguageForMutation: true,
118+
url: '/api/v2/pdf-export/',
119+
body: drefExportTriggerBody,
120+
onSuccess: (response) => {
121+
if (isDefined(response.id)) {
122+
setExportId(response.id);
123+
}
124+
},
125+
onFailure: () => {
126+
alert.show(
127+
strings.drefFailureToExportMessage,
128+
{ variant: 'danger' },
129+
);
130+
},
131+
});
132+
66133
const {
67134
pending: pendingExportTrigger,
68135
error: exportTriggerError,
69136
} = useRequest({
70-
skip: isDefined(exportId) || isNotDefined(id),
137+
skip: isDefined(exportId) || isNotDefined(id) || drefType === DREF_TYPE_IMMINENT,
71138
method: 'POST',
72139
useCurrentLanguageForMutation: true,
73140
url: '/api/v2/pdf-export/',
@@ -77,6 +144,12 @@ function DrefExportModal(props: Props) {
77144
setExportId(response.id);
78145
}
79146
},
147+
onFailure: () => {
148+
alert.show(
149+
strings.drefFailureToExportMessage,
150+
{ variant: 'danger' },
151+
);
152+
},
80153
});
81154

82155
const {
@@ -97,18 +170,40 @@ function DrefExportModal(props: Props) {
97170
},
98171
});
99172

173+
const handleDrefImminent = useCallback(() => {
174+
setIsPgaCheckboxVisible(false);
175+
drefImminentExportTrigger(drefExportTriggerBody);
176+
}, [
177+
drefExportTriggerBody,
178+
drefImminentExportTrigger,
179+
]);
180+
100181
return (
101182
<Modal
102183
heading={strings.drefExportTitle}
103184
onClose={onCancel}
104185
>
105-
{pendingExportTrigger && (
186+
{drefType === DREF_TYPE_IMMINENT
187+
&& isPgaCheckboxVisible
188+
&& !(pendingExportTrigger
189+
|| pendingExportStatus
190+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
191+
&& (
192+
<Checkbox
193+
name={undefined}
194+
value={isPga}
195+
onChange={setIsPga}
196+
label={strings.drefDownloadPDFWithPGA}
197+
/>
198+
)}
199+
{pendingExportTrigger && pendingDrefImminentExportTrigger && (
106200
<Message
107201
pending
108202
title={strings.drefPreparingExport}
109203
/>
110204
)}
111-
{(pendingExportStatus || exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
205+
{(pendingExportStatus
206+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
112207
<Message
113208
pending
114209
title={strings.drefWaitingExport}
@@ -117,16 +212,52 @@ function DrefExportModal(props: Props) {
117212
{(exportStatusResponse?.status === EXPORT_STATUS_ERRORED
118213
|| isDefined(exportTriggerError)
119214
|| isDefined(exportStatusError)
215+
|| isDefined(drefImminentExportError)
120216
) && (
121217
<Message
122218
title={strings.drefExportFailed}
123219
description={exportTriggerError?.value.messageForNotification
124-
?? exportStatusError?.value.messageForNotification}
220+
?? exportStatusError?.value.messageForNotification
221+
?? drefImminentExportError?.value.messageForNotification}
125222
/>
126223
)}
224+
{!(pendingExportTrigger
225+
|| pendingExportStatus
226+
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
227+
&& drefType === DREF_TYPE_IMMINENT
228+
&& !drefImminentExportError && (
229+
exportStatusResponse?.pdf_file ? (
230+
<Message
231+
title={strings.drefExportSuccessfully}
232+
description={strings.drefClickDownloadLink}
233+
actions={(
234+
<Link
235+
variant="secondary"
236+
href={exportStatusResponse?.pdf_file}
237+
external
238+
>
239+
{strings.drefDownloadPDF}
240+
</Link>
241+
)}
242+
/>
243+
) : (!exportStatusResponse && (
244+
<div className={styles.downloadButton}>
245+
<Button
246+
variant="secondary"
247+
name={undefined}
248+
onClick={handleDrefImminent}
249+
>
250+
{isPga
251+
? strings.drefDownloadPDFWithPGA
252+
: strings.drefDownloadPDFwithoutPGA}
253+
</Button>
254+
</div>
255+
))
256+
)}
127257
{isDefined(exportStatusResponse)
128258
&& exportStatusResponse.status === EXPORT_STATUS_COMPLETED
129-
&& isDefined(exportStatusResponse.pdf_file) && (
259+
&& isDefined(exportStatusResponse.pdf_file)
260+
&& drefType !== DREF_TYPE_IMMINENT && (
130261
<Message
131262
title={strings.drefExportSuccessfully}
132263
description={strings.drefClickDownloadLink}
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

+2-1
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

+1-2
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 */}

app/src/views/AccountMyFormsDref/ActiveDrefTable/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ function ActiveDrefTable(props: Props) {
259259
canCreateFinalReport,
260260
hasPermissionToApprove: isRegionCoordinator || userMe?.is_superuser,
261261
onPublishSuccess: refetchActiveDref,
262+
drefType: item.type_of_dref,
262263
};
263264
},
264265
{ columnClassName: styles.actions },

app/src/views/AccountMyFormsDref/DrefTableActions/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
DREF_TYPE_IMMINENT,
3232
DREF_TYPE_LOAN,
3333
type DrefStatus,
34+
type TypeOfDrefEnum,
3435
} from '#utils/constants';
3536
import {
3637
type GoApiBody,
@@ -53,6 +54,7 @@ export interface Props {
5354
hasPermissionToApprove?: boolean;
5455

5556
onPublishSuccess?: () => void;
57+
drefType: TypeOfDrefEnum | null | undefined;
5658
}
5759

5860
function DrefTableActions(props: Props) {
@@ -65,6 +67,7 @@ function DrefTableActions(props: Props) {
6567
canCreateFinalReport,
6668
hasPermissionToApprove,
6769
onPublishSuccess,
70+
drefType,
6871
} = props;
6972

7073
const { navigate } = useRouting();
@@ -497,6 +500,7 @@ function DrefTableActions(props: Props) {
497500
onCancel={setShowExportModalFalse}
498501
id={id}
499502
applicationType={applicationType}
503+
drefType={drefType}
500504
/>
501505
)}
502506
{showShareModal && (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"namespace": "drefApplicationExport",
3+
"strings": {
4+
"imminentDREFRequestHeading": "Imminent DREF Request and Obligations",
5+
"requestHeading": "Request:",
6+
"requestDescription": "The National Society hereby requests an Imminent DREF funding of CHF 75,000 to implement anticipatory actions to mitigate the risk of the foreseen disaster and possibly a few immediate response activities should the disaster materialize.",
7+
"nationalSocietyHeading": "National Society Obligations:",
8+
"nationalSocietyDescriptionOne": "The National Society commits to use the Imminent DREF funding solely for the proposed activities as per the budget indicated on page 1 and in accordance with the DREF Guidelines.",
9+
"nationalSocietyDescriptionTwo": "The maximum timeframe for implementing the proposed activities shall be 45 days after the date of approval of the Imminent DREF request, with no possibility of extension.",
10+
"nationalSocietyDescriptionThree": "In the event the foreseen disaster materializes, and the National Society requires additional funding from the DREF,",
11+
"nationalSocietyDescriptionFour": "The National Society shall promptly but no later than 14 days from the date of the disaster occurrence, submit a DREF application for the next operation (using the Operations Update form via GO). Upon approval of the response DREF application, the National Society shall promptly but no later than 15 days from receiving the Project Funding Agreement from the IFRC, sign such Project Funding Agreement.",
12+
"nationalSocietyDescriptionFive": "The Project Funding Agreement shall indicate the amount already paid out as Imminent DREF funding which shall be included in the total DREF cap allocation.",
13+
"nationalSocietyDescriptionSix": "The DREF application budget shall reflect the full funding needed for the operation, including the activities carried out using the Imminent DREF funding.",
14+
"nationalSocietyDescriptionSeven": "The National Society shall provide the following reports:",
15+
"nationalSocietyDescriptionEight": "two narrative reports:",
16+
"nationalSocietyDescriptionNine": "Operations Update to scale up through response DREF request and update on Imminent DREF implemented activities",
17+
"nationalSocietyDescriptionTen": "Imminent DREF and response DREF report in one common final report",
18+
"nationalSocietyDescriptionEleven": "One financial report of the final Imminent DREF and the response DREF operations.",
19+
"nationalSocietyDescriptionTwelve": "In the event the disaster materializes, however the National Society does not wish to request international support, the National Society shall:",
20+
"nationalSocietyDescriptionThirteen": "Provide a final financial and narrative report on the use of the Imminent DREF request within 30 days after the 45 days implementation period set out in paragraph 4 above,",
21+
"nationalSocietyDescriptionFourteen": "In the event the disaster does not materialize, the National Society shall:",
22+
"nationalSocietyDescriptionFifteen": "Refund the amount dedicated to immediate response activities of the Imminent DREF request within 30 days after the implementation period set out in paragraph 4 above.",
23+
"nationalSocietyDescriptionSixteen": "By signing this Imminent DREF request, the National Society commits to zero tolerance for, and shall take appropriate measures against, fraud, corruption, and any form of abuse against any person, in particular children, including without limitation sexual exploitation, abuse and harassment. The IFRC reserves the right to perform audits, financial reviews, checks and verifications and/or investigations to ensure the proper use of the Imminent DREF and compliance with the above-mentioned obligations. In order to facilitate such audits, financial reviews, checks and verifications and/or investigations, the National Society shall grant the IFRC access to its documents, records, and premises as well as its staff, agents, volunteers, beneficiaries, sub-grantees and contractors. Any breach of the above obligations shall entitle the IFRC to request a full refund of this Imminent DREF request.",
24+
"nationalSocietyBankDetails": "Bank details of the National Society",
25+
"nationalSocietyBankDescription": "to which the IFRC shall transfer the funds will be transferred.",
26+
"nationalSocietyBankName": "Bank Name and Address",
27+
"nationalSocietyBankAccountNumber": "Bank Account Number and Currency",
28+
"nationalSocietySwiftCode": "IBAN / SWIFT Code",
29+
"nationalSocietyAmount": "Amount(CHF)",
30+
"nationalSocietyAmountCHF": "CHF 75,000/CHF 90800",
31+
"nationalSocietyAdvancePayment": "For the Purpose of Advance Payment",
32+
"nationalSocietyBankFooter": "Please find attached letter from the Bank confirming banking relationship details.",
33+
"imminentDrefRequest": "This Imminent DREF request is signed on behalf of:",
34+
"imminentDrefSigned": "SIGNED by the authorised representative of the National Society",
35+
"imminentIFRCSigned": "SIGNED by the authorised representative of the IFRC",
36+
"imminentSignature": "Signature",
37+
"imminentPrintedSignatory": "Printed Signatory's Name",
38+
"imminentTitle": "Title",
39+
"imminentDate": "Date"
40+
}
41+
}

0 commit comments

Comments
 (0)