Skip to content

Commit 97a5803

Browse files
committed
feat(eap): update schema for save, submit functionality
1 parent ff1e2bf commit 97a5803

File tree

5 files changed

+172
-73
lines changed

5 files changed

+172
-73
lines changed

app/src/views/AccountMyFormsEap/EapStatus/i18n.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"confirmStatusButtonLabel": "Confirm",
88
"updateStatusDescription": "Are you sure you want to update the status?",
99
"reviewChecklistDescription": "Upload the Review Checklist for the National Society to download and review. Make sure to keep a proper labeling of the file to avoid duplications.",
10+
"editSimplifiedEapFormLinkLabel": "Edit sEAP",
11+
"editFullEapFormLinkLabel": "Edit Full EAP",
1012
"reviewChecklistInputLabel": "Select review checklist file",
13+
"submitFormErrorMessage": "Please make sure you've filled in all the required details before proceeding!",
1114
"noBudgetAlertTitle": "Please attach the validated budget file before proceeding!"
1215
}
1316
}

app/src/views/AccountMyFormsEap/EapStatus/index.tsx

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '@togglecorp/fujs';
2626

2727
import DropdownMenuItem from '#components/DropdownMenuItem';
28+
import Link from '#components/Link';
2829
import { type components } from '#generated/types';
2930
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
3031
import useAlert from '#hooks/useAlert';
@@ -36,11 +37,16 @@ import {
3637
EAP_STATUS_TECHNICALLY_VALIDATED,
3738
EAP_STATUS_UNDER_DEVELOPMENT,
3839
EAP_STATUS_UNDER_REVIEW,
40+
EAP_TYPE_FULL,
41+
EAP_TYPE_SIMPLIFIED,
3942
} from '#utils/constants';
4043
import {
4144
type GoApiBody,
4245
useLazyRequest,
4346
} from '#utils/restRequest';
47+
import { type ResponseObjectError } from '#utils/restRequest/error';
48+
49+
import { type EapListItem } from '../utils';
4450

4551
import i18n from './i18n.json';
4652

@@ -70,6 +76,7 @@ export interface Props {
7076
status: EapStatus;
7177
onStatusUpdate?: () => void;
7278
hasValidatedBudgetFile?: boolean;
79+
details: EapListItem;
7380
}
7481

7582
function EapStatus(props: Props) {
@@ -78,13 +85,18 @@ function EapStatus(props: Props) {
7885
status,
7986
onStatusUpdate,
8087
hasValidatedBudgetFile,
88+
details,
8189
} = props;
8290

91+
const simplifiedEapDetails = details.simplified_eap_details;
92+
const fullEapDetails = details.full_eap_details;
93+
8394
const alert = useAlert();
8495

8596
const { eap_eap_status: eapStatusOptions } = useGlobalEnums();
8697
const [newStatus, setNewStatus] = useState<EapStatus | undefined>();
8798
const [checklistFile, setChecklistFile] = useState<File | undefined>();
99+
const [hasFormErrors, setHasFormErrors] = useState<ResponseObjectError>();
88100

89101
const strings = useTranslation(i18n);
90102

@@ -114,11 +126,19 @@ function EapStatus(props: Props) {
114126
},
115127
formData: true,
116128
onFailure: (error) => {
129+
const {
130+
value: { formErrors, messageForNotification },
131+
} = error;
132+
133+
if (isDefined(formErrors)) {
134+
setHasFormErrors(formErrors);
135+
}
136+
117137
alert.show(
118138
strings.statusUpdateFailedAlert,
119139
{
120140
variant: 'danger',
121-
description: error.value.messageForNotification,
141+
description: messageForNotification,
122142
},
123143
);
124144
},
@@ -140,6 +160,7 @@ function EapStatus(props: Props) {
140160
const confirmDisabled = (
141161
(newStatus === EAP_STATUS_NS_ADDRESSING_COMMENTS && isNotDefined(checklistFile))
142162
|| (newStatus === EAP_STATUS_PENDING_PFA && !hasValidatedBudgetFile)
163+
|| isDefined(hasFormErrors)
143164
);
144165

145166
return (
@@ -166,13 +187,45 @@ function EapStatus(props: Props) {
166187
heading={strings.updateStatusHeading}
167188
onClose={handleStatusUpdateCancel}
168189
footerActions={(
169-
<Button
170-
name={requestBody}
171-
onClick={triggerStatusUpdate}
172-
disabled={confirmDisabled}
173-
>
174-
{strings.confirmStatusButtonLabel}
175-
</Button>
190+
<ListView>
191+
{details.eap_type === EAP_TYPE_SIMPLIFIED && hasFormErrors && (
192+
<Link
193+
to="simplifiedEapForm"
194+
urlParams={{ eapId }}
195+
urlSearch={isDefined(simplifiedEapDetails[0]?.version)
196+
? `version=${simplifiedEapDetails[0].version}`
197+
: undefined}
198+
title={strings.editSimplifiedEapFormLinkLabel}
199+
state={{ error: hasFormErrors }}
200+
styleVariant="outline"
201+
colorVariant="primary"
202+
>
203+
{strings.editSimplifiedEapFormLinkLabel}
204+
</Link>
205+
)}
206+
{details.eap_type === EAP_TYPE_FULL && hasFormErrors && (
207+
<Link
208+
to="eapFullExport"
209+
urlParams={{ eapId }}
210+
urlSearch={isDefined(fullEapDetails[0]?.version)
211+
? `version=${fullEapDetails[0].version}`
212+
: undefined}
213+
title={strings.editFullEapFormLinkLabel}
214+
state={{ error: hasFormErrors }}
215+
styleVariant="outline"
216+
colorVariant="primary"
217+
>
218+
{strings.editFullEapFormLinkLabel}
219+
</Link>
220+
)}
221+
<Button
222+
name={requestBody}
223+
onClick={triggerStatusUpdate}
224+
disabled={confirmDisabled}
225+
>
226+
{strings.confirmStatusButtonLabel}
227+
</Button>
228+
</ListView>
176229
)}
177230
>
178231
<ListView
@@ -211,6 +264,15 @@ function EapStatus(props: Props) {
211264
</Label>
212265
</ListView>
213266
)}
267+
{isDefined(hasFormErrors) && (
268+
<Alert
269+
name="form-error-warning"
270+
type="warning"
271+
title={strings.submitFormErrorMessage}
272+
withLightBackground
273+
withoutShadow
274+
/>
275+
)}
214276
{newStatus === EAP_STATUS_PENDING_PFA && !hasValidatedBudgetFile && (
215277
<Alert
216278
name="no-budget-file-warning"

app/src/views/AccountMyFormsEap/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export function Component() {
138138
status: row.status,
139139
hasValidatedBudgetFile: isTruthyString(row.validated_budget_file),
140140
onStatusUpdate: reloadEapList,
141+
eapType: row.eap_type,
142+
details: row,
141143
}),
142144
{ columnClassName: styles.status },
143145
),

0 commit comments

Comments
 (0)