Skip to content

Commit 6dd41cb

Browse files
committed
Add a confirmation popup before creating ops. update from imminent dref
1 parent a4029ca commit 6dd41cb

File tree

6 files changed

+70
-16
lines changed

6 files changed

+70
-16
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ function ActiveDrefTable(props: Props) {
219219
applicationType,
220220
canAddOpsUpdate: false,
221221
canCreateFinalReport: false,
222+
unpublishedOpsUpdateCount: 0,
222223
};
223224
}
224225

225226
const {
226-
// unpublished_final_report_count,
227227
unpublished_op_update_count,
228228
is_published,
229229
has_ops_update,
@@ -260,6 +260,7 @@ function ActiveDrefTable(props: Props) {
260260
hasPermissionToApprove: isRegionCoordinator || userMe?.is_superuser,
261261
onPublishSuccess: refetchActiveDref,
262262
drefType: item.type_of_dref,
263+
unpublishedOpsUpdateCount: unpublished_op_update_count,
263264
};
264265
},
265266
{ columnClassName: styles.actions },

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"drefApprovalInProgressTitle": "Approval in progress...",
1414
"drefAccountCouldNotCreate": "Could not create new operational update",
1515
"drefAccountCouldNotCreateFinalReport": "Could not create final report",
16-
"drefAccountConfirmMessage": "You're about to Approve this DREF. Once approved, it can no longer be edited. Are you sure, you want to Approve?"
16+
"drefAccountConfirmMessage": "You're about to Approve this DREF. Once approved, it can no longer be edited. Are you sure, you want to Approve?",
17+
"dropdownActionImminentNewOpsUpdateConfirmationHeading": "Confirm addition of Operational Update",
18+
"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?"
1719
}
1820
}

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

+30-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export interface Props {
5353
canCreateFinalReport: boolean;
5454
hasPermissionToApprove?: boolean;
5555

56+
unpublishedOpsUpdateCount: number;
57+
5658
onPublishSuccess?: () => void;
5759
drefType?: TypeOfDrefEnum | null | undefined;
5860
}
@@ -68,6 +70,7 @@ function DrefTableActions(props: Props) {
6870
hasPermissionToApprove,
6971
onPublishSuccess,
7072
drefType,
73+
unpublishedOpsUpdateCount,
7174
} = props;
7275

7376
const { navigate } = useRouting();
@@ -128,15 +131,15 @@ function DrefTableActions(props: Props) {
128131
),
129132
onSuccess: (response) => {
130133
const exportData = {
131-
allocationFor: response?.type_of_dref_display === 'Loan' ? 'Emergency Appeal' : 'DREF Operation',
134+
allocationFor: response?.type_of_dref === DREF_TYPE_LOAN ? 'Emergency Appeal' : 'DREF Operation',
132135
appealManager: response?.ifrc_appeal_manager_name,
133136
projectManager: response?.ifrc_project_manager_name,
134137
affectedCountry: response?.country_details?.name,
135138
name: response?.title,
136139
disasterType: response?.disaster_type_details?.name,
137140
responseType:
138-
response?.type_of_dref_display === 'Imminent'
139-
// FIXME: can't compare imminent with Imminent Crisis directly
141+
response?.type_of_dref === DREF_TYPE_IMMINENT
142+
// FIXME: add translations
140143
? 'Imminent Crisis'
141144
: response?.type_of_onset_display,
142145
noOfPeopleTargeted: response?.number_of_people_targeted,
@@ -147,8 +150,8 @@ function DrefTableActions(props: Props) {
147150
previousAllocation: response?.dref_allocated_so_far ?? 0,
148151
totalDREFAllocation: response?.total_dref_allocation,
149152
toBeAllocatedFrom:
150-
response?.type_of_dref_display === 'Imminent'
151-
// FIXME: can't compare imminent with Anticipatory Pillar
153+
response?.type_of_dref === DREF_TYPE_IMMINENT
154+
// FIXME: add translations
152155
? 'Anticipatory Pillar'
153156
: 'Response Pillar',
154157
focalPointName: response?.regional_focal_point_name,
@@ -380,6 +383,9 @@ function DrefTableActions(props: Props) {
380383

381384
const canApprove = status === DREF_STATUS_IN_PROGRESS && hasPermissionToApprove;
382385

386+
const shouldConfirmImminentAddOpsUpdate = drefType === DREF_TYPE_IMMINENT
387+
&& unpublishedOpsUpdateCount === 0;
388+
383389
const disabled = fetchingDref
384390
|| fetchingOpsUpdate
385391
|| publishDrefPending
@@ -418,7 +424,25 @@ function DrefTableActions(props: Props) {
418424
{strings.dropdownActionAllocationFormLabel}
419425
</DropdownMenuItem>
420426
)}
421-
{canAddOpsUpdate && (
427+
{canAddOpsUpdate && shouldConfirmImminentAddOpsUpdate && (
428+
<DropdownMenuItem
429+
name={undefined}
430+
type="confirm-button"
431+
icons={<AddLineIcon className={styles.icon} />}
432+
confirmHeading={
433+
strings.dropdownActionImminentNewOpsUpdateConfirmationHeading
434+
}
435+
confirmMessage={
436+
strings.dropdownActionImminentNewOpsUpdateConfirmationMessage
437+
}
438+
onConfirm={handleAddOpsUpdate}
439+
disabled={disabled}
440+
persist
441+
>
442+
{strings.dropdownActionAddOpsUpdateLabel}
443+
</DropdownMenuItem>
444+
)}
445+
{canAddOpsUpdate && !shouldConfirmImminentAddOpsUpdate && (
422446
<DropdownMenuItem
423447
name={undefined}
424448
type="button"

app/src/views/DrefFinalReportForm/Overview/index.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type Dispatch,
33
type SetStateAction,
44
useCallback,
5+
useMemo,
56
} from 'react';
67
import { WikiHelpSectionLineIcon } from '@ifrc-go/icons';
78
import {
@@ -34,6 +35,7 @@ import Link from '#components/Link';
3435
import useCountry from '#hooks/domain/useCountry';
3536
import useDisasterType from '#hooks/domain/useDisasterType';
3637
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
38+
import { DREF_TYPE_IMMINENT } from '#utils/constants';
3739
import { type GoApiResponse } from '#utils/restRequest';
3840

3941
import {
@@ -133,9 +135,11 @@ function Overview(props: Props) {
133135
user,
134136
}), []);
135137

136-
const filteredTypeOfDrefOptions = (typeOfDrefOptions ?? []).filter(
137-
(option) => option.key !== TYPE_LOAN,
138-
);
138+
const filteredTypeOfDrefOptions = useMemo(() => (
139+
typeOfDrefOptions?.filter(
140+
(option) => option.key !== TYPE_LOAN && option.key !== DREF_TYPE_IMMINENT,
141+
)
142+
), [typeOfDrefOptions]);
139143

140144
const error = getErrorObject(formError);
141145

app/src/views/DrefOperationalUpdateForm/Overview/i18n.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"isDrefChangingToResponse": "Is this DREF changing to Response?",
3636
"yesLabel": "Yes, change it to Response",
3737
"noLabel": "No",
38-
"changeToResponseHeading": "Change DREF Type"
38+
"changeToResponseHeading": "Change DREF Type",
39+
"overviewChangeTypeHeading": "Update type of DREF",
40+
"overviewChangeTypeMessage": "Please note that the type of DREF needs to be changed from Imminent before you can edit it.",
41+
"overviewChangeTypeButtonLabel": "Change to Response"
3942
}
4043
}

app/src/views/DrefOperationalUpdateForm/Overview/index.tsx

+24-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type Dispatch,
33
type SetStateAction,
44
useCallback,
5+
useMemo,
56
} from 'react';
67
import { useLocation } from 'react-router-dom';
78
import { WikiHelpSectionLineIcon } from '@ifrc-go/icons';
@@ -40,6 +41,7 @@ import Link from '#components/Link';
4041
import useCountry from '#hooks/domain/useCountry';
4142
import useDisasterType from '#hooks/domain/useDisasterType';
4243
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
44+
import { DREF_TYPE_IMMINENT } from '#utils/constants';
4345
import { type GoApiResponse } from '#utils/restRequest';
4446

4547
import {
@@ -109,6 +111,10 @@ function Overview(props: Props) {
109111
dref_dref_onset_type: drefOnsetTypeOptions,
110112
} = useGlobalEnums();
111113

114+
const typeOfDrefOptionsWithoutImminent = useMemo(() => (
115+
typeOfDrefOptions?.filter((option) => option.key !== DREF_TYPE_IMMINENT)
116+
), [typeOfDrefOptions]);
117+
112118
const countryOptions = useCountry();
113119

114120
const disasterTypes = useDisasterType();
@@ -184,8 +190,7 @@ function Overview(props: Props) {
184190
<div className={styles.operationOverview}>
185191
{state?.isNewOpsUpdate
186192
&& showChangeDrefTypeModal
187-
&& (value?.type_of_dref === TYPE_IMMINENT
188-
|| value?.type_of_dref === TYPE_ASSESSMENT) && (
193+
&& value?.type_of_dref === TYPE_ASSESSMENT && (
189194
<Modal
190195
size="sm"
191196
heading={strings.changeToResponseHeading}
@@ -207,11 +212,26 @@ function Overview(props: Props) {
207212
</Button>
208213
</>
209214
)}
210-
className={styles.flashUpdateShareModal}
211215
>
212216
{strings.isDrefChangingToResponse}
213217
</Modal>
214218
)}
219+
{value.type_of_dref === TYPE_IMMINENT && (
220+
<Modal
221+
size="sm"
222+
heading={strings.overviewChangeTypeHeading}
223+
footerActions={(
224+
<Button
225+
name={undefined}
226+
onClick={handleChangeToResponse}
227+
>
228+
{strings.overviewChangeTypeButtonLabel}
229+
</Button>
230+
)}
231+
>
232+
{strings.overviewChangeTypeMessage}
233+
</Modal>
234+
)}
215235
<Container
216236
heading={strings.drefFormSharingHeading}
217237
childrenContainerClassName={styles.content}
@@ -260,7 +280,7 @@ function Overview(props: Props) {
260280
<SelectInput
261281
name="type_of_dref"
262282
label={strings.drefFormTypeOfDref}
263-
options={typeOfDrefOptions}
283+
options={typeOfDrefOptionsWithoutImminent}
264284
keySelector={typeOfDrefKeySelector}
265285
labelSelector={stringValueSelector}
266286
onChange={setFieldValue}

0 commit comments

Comments
 (0)