Skip to content

Commit

Permalink
Revert DREF Imminent Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samshara committed Feb 10, 2025
1 parent a936e0b commit 5a3aa6a
Show file tree
Hide file tree
Showing 30 changed files with 618 additions and 2,112 deletions.
5 changes: 1 addition & 4 deletions app/src/components/domain/DrefExportModal/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"drefExportFailed": "Export failed",
"drefExportSuccessfully": "Export completed successfully",
"drefClickDownloadLink": "Click on the download link below!",
"drefDownloadPDF": "Download PDF",
"drefDownloadPDFWithPGA": "Download PDF with PGA",
"drefDownloadPDFwithoutPGA": "Download PDF without PGA",
"drefFailureToExportMessage":"Failed to export PDF."
"drefDownloadPDF": "Download PDF"
}
}
145 changes: 7 additions & 138 deletions app/src/components/domain/DrefExportModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {
useCallback,
useMemo,
useState,
} from 'react';
import {
Button,
Checkbox,
Message,
Modal,
} from '@ifrc-go/ui';
Expand All @@ -17,18 +14,9 @@ import {

import Link from '#components/Link';
import { type components } from '#generated/types';
import useAlert from '#hooks/useAlert';
import {
DREF_TYPE_IMMINENT,
type TypeOfDrefEnum,
} from '#utils/constants';
import {
useLazyRequest,
useRequest,
} from '#utils/restRequest';
import { useRequest } from '#utils/restRequest';

import i18n from './i18n.json';
import styles from './styles.module.css';

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

function DrefExportModal(props: Props) {
const {
id,
onCancel,
applicationType,
drefType,
} = props;

const strings = useTranslation(i18n);
const alert = useAlert();

const [exportId, setExportId] = useState<number | undefined>();
const [isPga, setIsPga] = useState<boolean>(false);
const [isPgaCheckboxVisible, setIsPgaCheckboxVisible] = useState(true);

const drefExportTriggerBody = useMemo(
() => {
let type: ExportTypeEnum;
if (applicationType === 'OPS_UPDATE') {
type = 'dref-operational-updates';
} else if (applicationType === 'FINAL_REPORT') {
type = 'dref-final-reports';
} else {
type = 'dref-applications';
}
return {
export_id: id,
export_type: type,
is_pga: isPga,
selector: '#pdf-preview-ready',
per_country: undefined,
};
},
[
id,
isPga,
applicationType,
],
);

const exportTriggerBody = useMemo(
() => {
Expand All @@ -102,39 +60,14 @@ function DrefExportModal(props: Props) {
per_country: undefined, // FIXME: typing is altered by the useRequest function
};
},
[
id,
applicationType,
],
[id, applicationType],
);

const {
pending: pendingDrefImminentExportTrigger,
error: drefImminentExportError,
trigger: drefImminentExportTrigger,
} = useLazyRequest({
method: 'POST',
useCurrentLanguageForMutation: true,
url: '/api/v2/pdf-export/',
body: drefExportTriggerBody,
onSuccess: (response) => {
if (isDefined(response.id)) {
setExportId(response.id);
}
},
onFailure: () => {
alert.show(
strings.drefFailureToExportMessage,
{ variant: 'danger' },
);
},
});

const {
pending: pendingExportTrigger,
error: exportTriggerError,
} = useRequest({
skip: isDefined(exportId) || isNotDefined(id) || drefType === DREF_TYPE_IMMINENT,
skip: isDefined(exportId) || isNotDefined(id),
method: 'POST',
useCurrentLanguageForMutation: true,
url: '/api/v2/pdf-export/',
Expand All @@ -144,12 +77,6 @@ function DrefExportModal(props: Props) {
setExportId(response.id);
}
},
onFailure: () => {
alert.show(
strings.drefFailureToExportMessage,
{ variant: 'danger' },
);
},
});

const {
Expand All @@ -170,40 +97,18 @@ function DrefExportModal(props: Props) {
},
});

const handleDrefImminent = useCallback(() => {
setIsPgaCheckboxVisible(false);
drefImminentExportTrigger(drefExportTriggerBody);
}, [
drefExportTriggerBody,
drefImminentExportTrigger,
]);

return (
<Modal
heading={strings.drefExportTitle}
onClose={onCancel}
>
{drefType === DREF_TYPE_IMMINENT
&& isPgaCheckboxVisible
&& !(pendingExportTrigger
|| pendingExportStatus
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
&& (
<Checkbox
name={undefined}
value={isPga}
onChange={setIsPga}
label={strings.drefDownloadPDFWithPGA}
/>
)}
{pendingExportTrigger && pendingDrefImminentExportTrigger && (
{pendingExportTrigger && (
<Message
pending
title={strings.drefPreparingExport}
/>
)}
{(pendingExportStatus
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
{(pendingExportStatus || exportStatusResponse?.status === EXPORT_STATUS_PENDING) && (
<Message
pending
title={strings.drefWaitingExport}
Expand All @@ -212,52 +117,16 @@ function DrefExportModal(props: Props) {
{(exportStatusResponse?.status === EXPORT_STATUS_ERRORED
|| isDefined(exportTriggerError)
|| isDefined(exportStatusError)
|| isDefined(drefImminentExportError)
) && (
<Message
title={strings.drefExportFailed}
description={exportTriggerError?.value.messageForNotification
?? exportStatusError?.value.messageForNotification
?? drefImminentExportError?.value.messageForNotification}
?? exportStatusError?.value.messageForNotification}
/>
)}
{!(pendingExportTrigger
|| pendingExportStatus
|| exportStatusResponse?.status === EXPORT_STATUS_PENDING)
&& drefType === DREF_TYPE_IMMINENT
&& !drefImminentExportError && (
exportStatusResponse?.pdf_file ? (
<Message
title={strings.drefExportSuccessfully}
description={strings.drefClickDownloadLink}
actions={(
<Link
variant="secondary"
href={exportStatusResponse?.pdf_file}
external
>
{strings.drefDownloadPDF}
</Link>
)}
/>
) : (!exportStatusResponse && (
<div className={styles.downloadButton}>
<Button
variant="secondary"
name={undefined}
onClick={handleDrefImminent}
>
{isPga
? strings.drefDownloadPDFWithPGA
: strings.drefDownloadPDFwithoutPGA}
</Button>
</div>
))
)}
{isDefined(exportStatusResponse)
&& exportStatusResponse.status === EXPORT_STATUS_COMPLETED
&& isDefined(exportStatusResponse.pdf_file)
&& drefType !== DREF_TYPE_IMMINENT && (
&& isDefined(exportStatusResponse.pdf_file) && (
<Message
title={strings.drefExportSuccessfully}
description={strings.drefClickDownloadLink}
Expand Down
6 changes: 0 additions & 6 deletions app/src/components/domain/DrefExportModal/styles.module.css

This file was deleted.

3 changes: 1 addition & 2 deletions app/src/components/domain/RiskSeasonalMap/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"riskCategoryVeryHigh": "Very High",
"riskSeasonalMapHeading": "Risk Map",
"riskSeasonalCountriesByRiskHeading": "Countries by Risk",
"riskPopupLabel": "Risk",
"riskDataNotAvailable": "Data not available for selected filters"
"riskPopupLabel": "Risk"
}
}
3 changes: 2 additions & 1 deletion app/src/components/domain/RiskSeasonalMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,8 @@ function RiskSeasonalMap(props: Props) {
{dataPending && <BlockLoading />}
{!dataPending && (isNotDefined(filteredData) || filteredData?.length === 0) && (
<Message
title={strings.riskDataNotAvailable}
// FIXME: add translations
title="Data not available for selected filters"
/>
)}
{/* FIXME: use List */}
Expand Down
1 change: 0 additions & 1 deletion app/src/views/AccountMyFormsDref/ActiveDrefTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ function ActiveDrefTable(props: Props) {
canCreateFinalReport,
hasPermissionToApprove: isRegionCoordinator || userMe?.is_superuser,
onPublishSuccess: refetchActiveDref,
drefType: item.type_of_dref,
};
},
{ columnClassName: styles.actions },
Expand Down
4 changes: 0 additions & 4 deletions app/src/views/AccountMyFormsDref/DrefTableActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
DREF_TYPE_IMMINENT,
DREF_TYPE_LOAN,
type DrefStatus,
type TypeOfDrefEnum,
} from '#utils/constants';
import {
type GoApiBody,
Expand All @@ -54,7 +53,6 @@ export interface Props {
hasPermissionToApprove?: boolean;

onPublishSuccess?: () => void;
drefType: TypeOfDrefEnum | null | undefined;
}

function DrefTableActions(props: Props) {
Expand All @@ -67,7 +65,6 @@ function DrefTableActions(props: Props) {
canCreateFinalReport,
hasPermissionToApprove,
onPublishSuccess,
drefType,
} = props;

const { navigate } = useRouting();
Expand Down Expand Up @@ -500,7 +497,6 @@ function DrefTableActions(props: Props) {
onCancel={setShowExportModalFalse}
id={id}
applicationType={applicationType}
drefType={drefType}
/>
)}
{showShareModal && (
Expand Down
41 changes: 0 additions & 41 deletions app/src/views/DrefApplicationExport/PgaExport/i18n.json

This file was deleted.

Loading

0 comments on commit 5a3aa6a

Please sign in to comment.