Skip to content

Commit 2f64187

Browse files
committed
fix(eap-full): update full eap form schema and total budget
1 parent 90b2261 commit 2f64187

4 files changed

Lines changed: 205 additions & 88 deletions

File tree

app/src/views/EapFullForm/FinanceLogistics/index.tsx

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useCallback } from 'react';
12
import { CheckboxMultipleBlankFillIcon } from '@ifrc-go/icons';
23
import {
34
Button,
@@ -14,11 +15,13 @@ import {
1415
useBooleanState,
1516
useTranslation,
1617
} from '@ifrc-go/ui/hooks';
18+
import { sumSafe } from '@ifrc-go/ui/utils';
1719
import {
1820
type EntriesAsList,
1921
type Error,
2022
getErrorObject,
2123
getErrorString,
24+
type SetBaseValueArg,
2225
} from '@togglecorp/toggle-form';
2326

2427
import GoSingleFileInput from '#components/domain/GoSingleFileInput';
@@ -33,6 +36,7 @@ import i18n from './i18n.json';
3336
interface Props {
3437
value: PartialEapFullFormType;
3538
setFieldValue: (...entries: EntriesAsList<PartialEapFullFormType>) => void;
39+
setValue: (value: SetBaseValueArg<PartialEapFullFormType>) => void;
3640
error: Error<PartialEapFullFormType> | undefined;
3741
disabled?: boolean;
3842
fileIdToUrlMap: Record<number, string>;
@@ -47,6 +51,7 @@ function FinanceLogistics(props: Props) {
4751
const {
4852
value,
4953
setFieldValue,
54+
setValue,
5055
error: formError,
5156
disabled,
5257
fileIdToUrlMap,
@@ -73,23 +78,50 @@ function FinanceLogistics(props: Props) {
7378
},
7479
});
7580

81+
const setBudgetValue = useCallback(
82+
(
83+
budgetValue: number | undefined,
84+
name:
85+
| 'readiness_budget'
86+
| 'pre_positioning_budget'
87+
| 'early_action_budget',
88+
) => {
89+
setValue((prevValue) => {
90+
const newBudgetValue = {
91+
readiness_budget: prevValue.readiness_budget,
92+
pre_positioning_budget: prevValue.pre_positioning_budget,
93+
early_action_budget: prevValue.early_action_budget,
94+
[name]: budgetValue,
95+
};
96+
97+
return {
98+
...prevValue,
99+
[name]: budgetValue,
100+
total_budget: sumSafe([
101+
newBudgetValue.readiness_budget,
102+
newBudgetValue.pre_positioning_budget,
103+
newBudgetValue.early_action_budget,
104+
]),
105+
};
106+
});
107+
},
108+
[setValue],
109+
);
110+
76111
return (
77112
<TabPage spacingOffset={-6}>
78113
<InlineLayout
79114
after={(
80115
<Button
81116
name={undefined}
82117
onClick={setShowQualityCriteriaTrue}
83-
after={(<CheckboxMultipleBlankFillIcon />)}
118+
after={<CheckboxMultipleBlankFillIcon />}
84119
>
85120
{strings.financeCriteriaButtonLabel}
86121
</Button>
87122
)}
88123
/>
89-
<ListView
90-
layout="block"
91-
spacing="xs"
92-
>
124+
<ListView layout="block" spacing="xs">
93125
<Heading variant="form">{strings.financeHeading}</Heading>
94126
<InputSection
95127
title={strings.financeBudgetTitle}
@@ -117,7 +149,8 @@ function FinanceLogistics(props: Props) {
117149
error={error?.total_budget}
118150
onChange={setFieldValue}
119151
disabled={disabled}
120-
readOnly={readOnly}
152+
readOnly
153+
required
121154
/>
122155
<TextArea
123156
label={strings.financeDescriptionLabel}
@@ -131,12 +164,7 @@ function FinanceLogistics(props: Props) {
131164
</InputSection>
132165
<InputSection
133166
description={(
134-
<Link
135-
external
136-
href={templateUrl?.url}
137-
withUnderline
138-
withLinkIcon
139-
>
167+
<Link external href={templateUrl?.url} withUnderline withLinkIcon>
140168
{strings.financeDownloadDescription}
141169
</Link>
142170
)}
@@ -194,9 +222,10 @@ function FinanceLogistics(props: Props) {
194222
name="readiness_budget"
195223
value={value?.readiness_budget}
196224
error={error?.readiness_budget}
197-
onChange={setFieldValue}
225+
onChange={setBudgetValue}
198226
disabled={disabled}
199227
readOnly={readOnly}
228+
required
200229
/>
201230
<TextArea
202231
label={strings.financeDescriptionLabel}
@@ -244,9 +273,10 @@ function FinanceLogistics(props: Props) {
244273
name="pre_positioning_budget"
245274
value={value?.pre_positioning_budget}
246275
error={error?.pre_positioning_budget}
247-
onChange={setFieldValue}
276+
onChange={setBudgetValue}
248277
disabled={disabled}
249278
readOnly={readOnly}
279+
required
250280
/>
251281
<TextArea
252282
label={strings.financeDescriptionLabel}
@@ -296,9 +326,10 @@ function FinanceLogistics(props: Props) {
296326
name="early_action_budget"
297327
value={value?.early_action_budget}
298328
error={error?.early_action_budget}
299-
onChange={setFieldValue}
329+
onChange={setBudgetValue}
300330
disabled={disabled}
301331
readOnly={readOnly}
332+
required
302333
/>
303334
<TextArea
304335
label={strings.financeDescriptionLabel}
@@ -311,10 +342,7 @@ function FinanceLogistics(props: Props) {
311342
/>
312343
</InputSection>
313344
</ListView>
314-
<ListView
315-
layout="block"
316-
spacing="xs"
317-
>
345+
<ListView layout="block" spacing="xs">
318346
<Heading variant="form">{strings.financeEapEndorsementHeading}</Heading>
319347
<InputSection
320348
title={strings.financeEapEndorsementTitle}

app/src/views/EapFullForm/SelectionActions/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ function SelectionActions(props: Props) {
484484
<InputSection
485485
title={strings.plannedOperationTitle}
486486
description={strings.plannedOperationDescription}
487+
withAsteriskOnTitle
487488
>
488489
<NonFieldError error={getErrorObject(error?.planned_operations)} />
489490
<Checklist
@@ -515,6 +516,7 @@ function SelectionActions(props: Props) {
515516
<InputSection
516517
title={strings.enablingApproachesTitle}
517518
description={strings.enablingApproachesDescription}
519+
withAsteriskOnTitle
518520
>
519521
<NonFieldError error={getErrorObject(error?.planned_operations)} />
520522
<Checklist

app/src/views/EapFullForm/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ export function Component() {
942942
<FinanceLogistics
943943
value={value}
944944
setFieldValue={setFieldValue}
945+
setValue={setValue}
945946
error={formError}
946947
disabled={disabled}
947948
fileIdToUrlMap={fileIdToUrlMap}

0 commit comments

Comments
 (0)