Skip to content

Commit c8ffb35

Browse files
committed
feat(dref-translation): add final report confirmation modal
1 parent 4ba4569 commit c8ffb35

File tree

7 files changed

+95
-41
lines changed

7 files changed

+95
-41
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function ActiveDrefTable(props: Props) {
237237
has_final_report,
238238
country_details,
239239
is_dref_imminent_v2,
240-
original_language,
240+
starting_language,
241241
} = originalDref;
242242

243243
const is_published = status === DREF_STATUS_APPROVED;
@@ -272,7 +272,7 @@ function ActiveDrefTable(props: Props) {
272272
canCreateFinalReport,
273273
hasPermissionToApprove: isRegionCoordinator || userMe?.is_superuser,
274274
onPublishSuccess: refetchActiveDref,
275-
originalLanguage: original_language as Language,
275+
startingLanguage: starting_language as Language,
276276
};
277277
},
278278
{ columnClassName: styles.actions },

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function CompletedDrefTable(props: Props) {
201201
dref: datum.dref,
202202
glide_code: datum.glide_code,
203203
date_of_publication: datum.date_of_publication,
204-
original_language: datum.original_language,
204+
starting_language: datum.starting_language,
205205
}),
206206
),
207207
{

app/src/views/AccountMyFormsDref/DrefTableActions/i18n.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dropdownActionFinalizeLabel": "Finalize",
66
"dropdownActionAllocationFormLabel": "Allocation Form",
77
"dropdownActionAddOpsUpdateLabel": "Add Operational Update",
8+
"dropdownActionAddFinalReportLabel": "Add Final Report",
89
"dropdownActionCreateFinalReportLabel": "Create Final Report",
910
"dropdownActionShareLabel": "Share",
1011
"dropdownActionExportLabel": "Export",
@@ -18,9 +19,13 @@
1819
"drefAccountCouldNotCreateFinalReport": "Could not create final report",
1920
"drefAccountConfirmMessage": "You're about to approve this DREF. Once approved, it can no longer be edited. Are you sure you want to approve?",
2021
"drefAccountFinalizeConfirmMessage": "You are about to finalize this DREF. Once finalized, the original language will change to English, and it will no longer be editable in the {selectedLanguage} language. Are you sure you want to proceed?",
21-
"drefOpsUpdateOriginalLanguageLabel": "Original Language",
22-
"dropdownActionNewOpsUpdateLanguageConfirmationMessage": "Please select the language to create the DREF Operation Updates.",
22+
"drefOpsUpdateStartingLanguageLabel": "DREF Starting Language",
23+
"dropdownActionNewOpsUpdateConfirmationMessage": "You are about to create a new DREF Operational Update.",
24+
"dropdownActionNewOpsUpdateLanguageSelectLanguageMessage": "Please select the language to create the DREF Operation Update.",
25+
"dropdownActionNewFinalReportConfirmationMessage": "You are about to create a new DREF Final Report.",
26+
"dropdownActionNewFinalReportLanguageSelectLanguageMessage": "Please select the language to create the DREF Final Report.",
2327
"dropdownActionImminentNewOpsUpdateConfirmationHeading": "Confirm addition of Operational Update",
28+
"dropdownActionNewFinalReportConfirmationHeading": "Confirm addition of Final Report",
2429
"dropdownActionImminentNewOpsUpdateConfirmationMessage": "The DREF type will be changed to Response (from Imminent) for the Operational Update. Once created, you'll be able to change it to other types except Imminent. Are you sure you want to add an Operational Update?"
2530
}
2631
}

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

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface Props {
7878
canCreateFinalReport: boolean;
7979
hasPermissionToApprove?: boolean;
8080
isDrefImminentV2?: boolean;
81-
originalLanguage?: Language;
81+
startingLanguage?: Language;
8282

8383
onPublishSuccess?: () => void;
8484
drefType?: TypeOfDrefEnum | null | undefined;
@@ -96,29 +96,31 @@ function DrefTableActions(props: Props) {
9696
isDrefImminentV2,
9797
onPublishSuccess,
9898
drefType,
99-
originalLanguage,
99+
startingLanguage,
100100
} = props;
101101

102102
const [selectOpsLanguage, setSelectOpsLanguage] = useState<Language | undefined>();
103103

104+
const [selectFinalLanguage, setSelectFinalLanguage] = useState<Language | undefined>();
105+
104106
const { navigate } = useRouting();
105107

106108
const alert = useAlert();
107109

108110
const strings = useTranslation(i18n);
109111

110112
const selectLanguageOptions: SelectLanguageOption[] | undefined = useMemo(() => {
111-
if (isNotDefined(originalLanguage)) {
113+
if (isNotDefined(startingLanguage)) {
112114
return undefined;
113115
}
114116
return [
115117
{
116-
key: originalLanguage,
117-
label: `${languageNameMap[originalLanguage]} (${strings.drefOpsUpdateOriginalLanguageLabel})`,
118+
key: startingLanguage,
119+
label: `${languageNameMap[startingLanguage]} (${strings.drefOpsUpdateStartingLanguageLabel})`,
118120
},
119121
{ key: 'en', label: languageNameMap.en },
120122
];
121-
}, [originalLanguage, strings.drefOpsUpdateOriginalLanguageLabel]);
123+
}, [startingLanguage, strings.drefOpsUpdateStartingLanguageLabel]);
122124

123125
const [showExportModal, {
124126
setTrue: setShowExportModalTrue,
@@ -401,8 +403,9 @@ function DrefTableActions(props: Props) {
401403
drefId: number,
402404
) => ({
403405
dref: drefId,
404-
original_language: originalLanguage === 'en' ? originalLanguage : selectOpsLanguage,
406+
starting_language: startingLanguage === 'en' ? startingLanguage : selectOpsLanguage,
405407
} as unknown as OpsUpdateRequestBody),
408+
useCurrentLanguageForMutation: true,
406409
onSuccess: (response) => {
407410
navigate(
408411
'drefOperationalUpdateForm',
@@ -432,7 +435,13 @@ function DrefTableActions(props: Props) {
432435
method: 'POST',
433436
url: '/api/v2/dref-final-report/',
434437
// FIXME: the type should be fixed on the server
435-
body: (drefId: number) => ({ dref: drefId } as FinalReportRequestBody),
438+
useCurrentLanguageForMutation: true,
439+
body: (
440+
drefId: number,
441+
) => ({
442+
dref: drefId,
443+
starting_language: startingLanguage === 'en' ? startingLanguage : selectFinalLanguage,
444+
} as FinalReportRequestBody),
436445
onSuccess: (response) => {
437446
navigate(
438447
isDrefImminentV2 ? 'drefFinalReportForm' : 'oldDrefFinalReportForm',
@@ -476,6 +485,11 @@ function DrefTableActions(props: Props) {
476485
setFalse: setShowOperationConfirmModalFalse,
477486
}] = useBooleanState(false);
478487

488+
const [showFinalReportConfirmModal, {
489+
setTrue: setShowFinalReportConfirmModalTrue,
490+
setFalse: setShowFinalReportConfirmModalFalse,
491+
}] = useBooleanState(false);
492+
479493
const handleExportClick: NonNullable<ButtonProps<undefined>['onClick']> = useCallback(
480494
() => {
481495
setShowExportModalTrue();
@@ -578,7 +592,7 @@ function DrefTableActions(props: Props) {
578592
resolveToString(
579593
strings.drefAccountFinalizeConfirmMessage,
580594
{
581-
selectedLanguage: originalLanguage,
595+
selectedLanguage: startingLanguage ? languageNameMap[startingLanguage] : '--',
582596
},
583597
)
584598
}
@@ -614,19 +628,7 @@ function DrefTableActions(props: Props) {
614628
{strings.dropdownActionAllocationFormLabel}
615629
</DropdownMenuItem>
616630
)}
617-
{(canAddOpsUpdate && originalLanguage === 'en') && (
618-
<DropdownMenuItem
619-
name={undefined}
620-
type="button"
621-
icons={<AddLineIcon className={styles.icon} />}
622-
onClick={handleAddOpsUpdate}
623-
disabled={disabled}
624-
persist
625-
>
626-
{strings.dropdownActionAddOpsUpdateLabel}
627-
</DropdownMenuItem>
628-
)}
629-
{(canAddOpsUpdate && originalLanguage !== 'en') && (
631+
{canAddOpsUpdate && (
630632
<DropdownMenuItem
631633
name={undefined}
632634
type="button"
@@ -642,7 +644,7 @@ function DrefTableActions(props: Props) {
642644
<DropdownMenuItem
643645
name={undefined}
644646
type="button"
645-
onClick={handleAddFinalReport}
647+
onClick={setShowFinalReportConfirmModalTrue}
646648
icons={<CaseManagementIcon className={styles.icon} />}
647649
disabled={disabled}
648650
persist
@@ -741,23 +743,67 @@ function DrefTableActions(props: Props) {
741743
<Button
742744
name={undefined}
743745
onClick={handleAddOpsUpdate}
744-
disabled={!selectOpsLanguage}
746+
disabled={(startingLanguage !== 'en' && !selectOpsLanguage)}
745747
>
746748
{strings.dropdownActionAddOpsUpdateLabel}
747749
</Button>
748750
)}
749751
>
752+
<p>{strings.dropdownActionNewOpsUpdateConfirmationMessage}</p>
750753
{shouldConfirmImminentAddOpsUpdate
751754
&& strings.dropdownActionImminentNewOpsUpdateConfirmationMessage}
752-
<p>{strings.dropdownActionNewOpsUpdateLanguageConfirmationMessage}</p>
753-
<RadioInput
754-
name={undefined}
755-
value={selectOpsLanguage}
756-
options={selectLanguageOptions}
757-
onChange={setSelectOpsLanguage}
758-
keySelector={selectLanguageKeySelector}
759-
labelSelector={stringLabelSelector}
760-
/>
755+
{startingLanguage !== 'en' && (
756+
<>
757+
<p>
758+
{strings
759+
.dropdownActionNewOpsUpdateLanguageSelectLanguageMessage}
760+
</p>
761+
<RadioInput
762+
name={undefined}
763+
value={selectOpsLanguage}
764+
options={selectLanguageOptions}
765+
onChange={setSelectOpsLanguage}
766+
keySelector={selectLanguageKeySelector}
767+
labelSelector={stringLabelSelector}
768+
/>
769+
</>
770+
)}
771+
</Modal>
772+
)
773+
}
774+
{
775+
showFinalReportConfirmModal && (
776+
<Modal
777+
heading={strings.dropdownActionNewFinalReportConfirmationHeading}
778+
onClose={setShowFinalReportConfirmModalFalse}
779+
childrenContainerClassName={styles.addOpsUpdateModal}
780+
footerActions={(
781+
<Button
782+
name={undefined}
783+
onClick={handleAddFinalReport}
784+
disabled={(startingLanguage !== 'en' && !selectFinalLanguage)}
785+
>
786+
{strings.dropdownActionAddFinalReportLabel}
787+
</Button>
788+
)}
789+
>
790+
<p>{strings.dropdownActionNewFinalReportConfirmationMessage}</p>
791+
{startingLanguage !== 'en' && (
792+
<>
793+
<p>
794+
{strings
795+
.dropdownActionNewFinalReportLanguageSelectLanguageMessage}
796+
</p>
797+
<RadioInput
798+
name={undefined}
799+
value={selectFinalLanguage}
800+
options={selectLanguageOptions}
801+
onChange={setSelectFinalLanguage}
802+
keySelector={selectLanguageKeySelector}
803+
labelSelector={stringLabelSelector}
804+
/>
805+
</>
806+
)}
761807
</Modal>
762808
)
763809
}

app/src/views/DrefApplicationForm/i18n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"formLoadErrorTitle": "Failed to load DREF Application!",
1919
"formBackButtonLabel": "Back",
2020
"formLoadingMessage": "Loading DREF Application...",
21-
"formNotAvailableInNonEnglishMessage": "DREF Application is not available in the selected language!",
2221
"formEditNotAvailableInSelectedLanguageMessage": "DREF Application is currently in view-only mode.",
2322
"drefFeedbackForm": "Provide feedback on IFRC DREF"
2423
}

app/src/views/OldDrefFinalReportForm/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ import NonFieldError from '#components/NonFieldError';
3838
import Page from '#components/Page';
3939
import useCurrentLanguage from '#hooks/domain/useCurrentLanguage';
4040
import useAlert from '#hooks/useAlert';
41-
import { DREF_STATUS_DRAFT, DREF_STATUS_FINALIZED, DREF_TYPE_IMMINENT } from '#utils/constants';
41+
import {
42+
DREF_STATUS_DRAFT,
43+
DREF_STATUS_FINALIZED,
44+
DREF_TYPE_IMMINENT,
45+
} from '#utils/constants';
4246
import {
4347
type GoApiResponse,
4448
useLazyRequest,

0 commit comments

Comments
 (0)