Skip to content

Commit 5ccc1bc

Browse files
committed
feat(eap): clean-up simplied form schema
1 parent ffa38b9 commit 5ccc1bc

File tree

19 files changed

+191
-204
lines changed

19 files changed

+191
-204
lines changed

app/src/components/domain/Admin2Input/i18n.json

Whitespace-only changes.

app/src/components/domain/ImageWithCaptionInput/index.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,25 @@ import NonFieldError from '#components/NonFieldError';
2121

2222
import i18n from './i18n.json';
2323

24-
type Value = {
25-
id?: number | undefined;
24+
type InputValue = {
25+
id?: number;
2626
client_id: string;
27-
caption?: string | undefined | null;
27+
caption?: string | null;
2828
};
2929

30-
interface Props<N> {
30+
type OutputValue = {
31+
id?: number;
32+
client_id: string;
33+
caption?: string;
34+
}
35+
36+
interface Props<NAME> {
3137
className?: string;
32-
name: N;
38+
name: NAME;
3339
url: SupportedPaths;
34-
value: Value | null | undefined;
35-
onChange: (value: SetValueArg<Value> | undefined, name: N) => void;
36-
error: ObjectError<Value> | undefined;
40+
value: InputValue | null | undefined;
41+
onChange: (value: SetValueArg<OutputValue> | undefined, name: NAME) => void;
42+
error: ObjectError<InputValue> | undefined;
3743
fileIdToUrlMap: Record<number, string>;
3844
setFileIdToUrlMap?: React.Dispatch<React.SetStateAction<Record<number, string>>>;
3945
label: React.ReactNode;

app/src/components/domain/MultiImageWithCaptionInput/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@ import NonFieldError from '#components/NonFieldError';
2929
import i18n from './i18n.json';
3030
import styles from './styles.module.css';
3131

32-
type Value = {
33-
client_id: string;
32+
type InputValue = {
3433
id?: number;
34+
client_id: string;
3535
caption?: string | null;
3636
};
3737

38+
type OutputValue = {
39+
id?: number;
40+
client_id: string;
41+
caption?: string;
42+
}
43+
3844
interface Props<N> {
3945
className?: string;
4046
name: N;
4147
url: SupportedPaths;
42-
value: Value[] | null | undefined;
43-
onChange: (value: SetValueArg<Value[] | undefined>, name: N) => void;
44-
error: ArrayError<Value> | undefined;
48+
value: InputValue[] | null | undefined;
49+
onChange: (value: SetValueArg<OutputValue[] | undefined>, name: N) => void;
50+
error: ArrayError<InputValue> | undefined;
4551
fileIdToUrlMap: Record<number, string>;
4652
setFileIdToUrlMap?: React.Dispatch<React.SetStateAction<Record<number, string>>>;
4753
label: React.ReactNode;

app/src/components/domain/OperationActivityInput/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { stringValueSelector } from '@ifrc-go/ui/utils';
1313
import {
1414
type ArrayError,
1515
getErrorObject,
16+
getErrorString,
1617
type SetValueArg,
1718
useFormObject,
1819
} from '@togglecorp/toggle-form';
@@ -125,6 +126,7 @@ function OperationActivityInput(props: Props) {
125126
label={strings.operationPriorityActionLabel}
126127
name="activity"
127128
value={value.activity}
129+
error={error?.activity}
128130
onChange={onFieldChange}
129131
disabled={disabled}
130132
withAsterisk
@@ -154,6 +156,7 @@ function OperationActivityInput(props: Props) {
154156
disabled={disabled}
155157
renderer={TimeSpanCheck}
156158
withoutOpticalSpacingCorrection
159+
error={getErrorString(error?.time_value)}
157160
/>
158161
)}
159162
</ListView>

app/src/components/printable/PrintableContainer/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ function PrintableContainer(props: Props) {
2929
<>
3030
{breakBefore && <div className={styles.pageBreak} />}
3131
{heading && (
32-
<Heading level={headingLevel}>
32+
<Heading
33+
level={headingLevel}
34+
className={styles.heading}
35+
>
3336
{heading}
3437
</Heading>
3538
)}
3639
{children}
37-
<div style={{ marginBlockEnd: spacing }} />
40+
<div
41+
className={styles.blockSpacing}
42+
style={{ marginBlockEnd: spacing }}
43+
/>
3844
{breakAfter && <div className={styles.pageBreak} />}
3945
</>
4046
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
.page-break {
22
break-before: page;
3+
4+
@media screen {
5+
margin: var(--go-ui-spacing-lg) 0;
6+
border: var(--go-ui-width-separator-thin) dashed var(--go-ui-color-separator);
7+
}
8+
}
9+
10+
.heading:has(+ :empty) {
11+
display: none;
12+
}
13+
14+
.block-spacing:has(+ :empty) {
15+
display: none;
316
}

app/src/components/printable/PrintableDataDisplay/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface NodeProps {
5555
value?: React.ReactNode;
5656
}
5757

58-
export type Props = BaseProps & (
58+
type Props = BaseProps & (
5959
NodeProps | TextProps | DateProps | NumberProps | BooleanProps
6060
);
6161

app/src/utils/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,6 @@ export const EAP_TYPE_FULL = 10;
209209

210210
// FIXME these need to satisfy some enum
211211
export const TIMEFRAME_YEAR = 10;
212-
export const TIMEFRAME_MONTHS = 20;
212+
// export const TIMEFRAME_MONTHS = 20;
213213
// export const TIMEFRAME_DAYS = 30;
214214
// export const TIMEFRAME_HOURS = 40;

app/src/views/SimplifiedEapExport/index.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ export function Component() {
8181
);
8282

8383
const {
84-
cover_image_details,
84+
disaster_type_details,
85+
country_details,
86+
} = eapRegistrationResponse ?? {};
87+
88+
const {
89+
cover_image_file,
90+
admin2_details,
8591

8692
total_budget,
8793
readiness_budget,
@@ -113,6 +119,12 @@ export function Component() {
113119
national_society_contact_phone_number,
114120
} = simplifiedEapResponse ?? {};
115121

122+
const eapTitle = [
123+
country_details?.name,
124+
admin2_details?.map(({ name }) => name).join(', '),
125+
disaster_type_details?.name,
126+
].filter(isTruthyString).join(' | ');
127+
116128
return (
117129
<PrintablePage
118130
heading={(
@@ -122,14 +134,14 @@ export function Component() {
122134
Early Action Protocol
123135
</>
124136
)}
125-
description="Nepal, Western Terai | Flood"
137+
description={eapTitle ?? '--'}
126138
>
127-
{isDefined(cover_image_details?.file) && (
139+
{isDefined(cover_image_file?.file) && (
128140
<PrintableContainer>
129141
<Image
130-
src={cover_image_details.file}
142+
src={cover_image_file.file}
131143
alt=""
132-
caption={cover_image_details.caption}
144+
caption={cover_image_file.caption}
133145
/>
134146
</PrintableContainer>
135147
)}
@@ -531,7 +543,7 @@ export function Component() {
531543
national_society_contact_title,
532544
national_society_contact_email,
533545
national_society_contact_phone_number,
534-
].join(', ')}
546+
].filter(isTruthyString).join(', ')}
535547
variant="block"
536548
strongLabel
537549
/>

app/src/views/SimplifiedEapForm/EnablingApproaches/ApproachesInput/index.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from '@ifrc-go/ui';
1313
import { useTranslation } from '@ifrc-go/ui/hooks';
1414
import {
15-
isDefined,
1615
isNotDefined,
1716
randomString,
1817
} from '@togglecorp/fujs';
@@ -37,7 +36,7 @@ type PrepositioningFormFields = NonNullable<EnableApproachesFormFields['preposit
3736
type ReadinessFormFields = NonNullable<EnableApproachesFormFields['readiness_activities']>[number];
3837

3938
const defaultApproachValue: EnableApproachesFormFields = {
40-
client_id: '-1',
39+
approach: 10,
4140
};
4241

4342
interface Props {
@@ -47,7 +46,7 @@ interface Props {
4746
onRemove: (index: number) => void;
4847
index: number;
4948
disabled?: boolean;
50-
titleMap: Record<string, string> | undefined;
49+
approachTitle?: React.ReactNode;
5150
}
5251

5352
function OperationsBySectorInput(props: Props) {
@@ -58,18 +57,14 @@ function OperationsBySectorInput(props: Props) {
5857
index,
5958
onRemove,
6059
disabled,
61-
titleMap,
60+
approachTitle,
6261
} = props;
6362

6463
const strings = useTranslation(i18n);
6564
const onFieldChange = useFormObject(index, onChange, defaultApproachValue);
6665

67-
const approachLabel = isDefined(value.title)
68-
? titleMap?.[value.title]
69-
: undefined;
70-
71-
const error = (value && value.client_id && errorFromProps)
72-
? getErrorObject(errorFromProps?.[value.client_id])
66+
const error = (value && value.approach && errorFromProps)
67+
? getErrorObject(errorFromProps?.[value.approach])
7368
: undefined;
7469

7570
const {
@@ -144,7 +139,7 @@ function OperationsBySectorInput(props: Props) {
144139

145140
return (
146141
<ExpandableContainer
147-
heading={approachLabel ?? '--'}
142+
heading={approachTitle ?? '--'}
148143
headerActions={(
149144
<Button
150145
name={index}

0 commit comments

Comments
 (0)