Skip to content

Commit 7178bdd

Browse files
committed
feat: refactor ERU readiness form
1 parent c253536 commit 7178bdd

File tree

7 files changed

+286
-207
lines changed

7 files changed

+286
-207
lines changed

Diff for: app/src/views/EruReadinessForm/EruInputItem/index.tsx

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { useMemo } from 'react';
12
import {
23
Checkbox,
3-
Container,
44
InputSection,
55
RadioInput,
66
TextArea,
@@ -10,15 +10,14 @@ import { randomString } from '@togglecorp/fujs';
1010
import {
1111
type ArrayError,
1212
getErrorObject,
13-
type PartialForm,
1413
type SetValueArg,
1514
useFormObject,
1615
} from '@togglecorp/toggle-form';
1716

1817
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
1918
import { type GoApiResponse } from '#utils/restRequest';
2019

21-
import { type EruType } from '../schema';
20+
import { type PartialEruItem } from '../schema';
2221

2322
import i18n from './i18n.json';
2423
import styles from './styles.module.css';
@@ -35,30 +34,29 @@ function readinessLabelSelector(option: ReadinessOption) {
3534
return option.value;
3635
}
3736

38-
const defaultCollectionValue: PartialForm<EruType> = {
37+
const defaultCollectionValue: PartialEruItem = {
3938
client_id: randomString(),
4039
};
4140

4241
interface Props {
4342
index: number;
44-
value: PartialForm<EruType>;
45-
onChange: (value: SetValueArg<PartialForm<EruType>>, index: number) => void;
46-
title: string | undefined;
47-
error: ArrayError<EruType> | undefined;
43+
value: PartialEruItem;
44+
onChange: (value: SetValueArg<PartialEruItem>, index: number) => void;
45+
error: ArrayError<PartialEruItem> | undefined;
4846
}
4947

5048
function EruInputItem(props: Props) {
5149
const {
5250
index,
5351
value,
5452
onChange,
55-
title,
5653
error: errorFromProps,
5754
} = props;
5855

5956
const strings = useTranslation(i18n);
6057

6158
const {
59+
deployments_eru_type: eruTypeOptions,
6260
deployments_eru_readiness_status,
6361
} = useGlobalEnums();
6462

@@ -72,17 +70,23 @@ function EruInputItem(props: Props) {
7270
? getErrorObject(errorFromProps?.[value.client_id])
7371
: undefined;
7472

73+
const title = useMemo(() => (
74+
eruTypeOptions?.find((eruType) => eruType.key === value.type)?.value
75+
), [eruTypeOptions, value.type]);
76+
7577
return (
76-
<Container
77-
childrenContainerClassName={styles.eruTypes}
78-
heading={title}
78+
<InputSection
79+
title={title}
80+
className={styles.eruInputItem}
81+
contentSectionClassName={styles.content}
7982
>
8083
<InputSection
81-
className={styles.readinessOptions}
8284
title={strings.eruEquipmentReadiness}
85+
className={styles.inputSection}
8386
>
8487
<RadioInput
85-
listContainerClassName={styles.readinessList}
88+
className={styles.readinessInput}
89+
listContainerClassName={styles.radioList}
8690
name="equipment_readiness"
8791
value={value.equipment_readiness}
8892
onChange={onFieldChange}
@@ -93,11 +97,12 @@ function EruInputItem(props: Props) {
9397
/>
9498
</InputSection>
9599
<InputSection
96-
className={styles.readinessOptions}
97100
title={strings.eruPeopleReadiness}
101+
className={styles.inputSection}
98102
>
99103
<RadioInput
100-
listContainerClassName={styles.readinessList}
104+
className={styles.readinessInput}
105+
listContainerClassName={styles.radioList}
101106
name="people_readiness"
102107
value={value.people_readiness}
103108
onChange={onFieldChange}
@@ -108,11 +113,12 @@ function EruInputItem(props: Props) {
108113
/>
109114
</InputSection>
110115
<InputSection
111-
className={styles.readinessOptions}
112116
title={strings.eruFundingReadiness}
117+
className={styles.inputSection}
113118
>
114119
<RadioInput
115-
listContainerClassName={styles.readinessList}
120+
className={styles.readinessInput}
121+
listContainerClassName={styles.radioList}
116122
name="funding_readiness"
117123
value={value.funding_readiness}
118124
onChange={onFieldChange}
@@ -123,8 +129,8 @@ function EruInputItem(props: Props) {
123129
/>
124130
</InputSection>
125131
<InputSection
126-
className={styles.readinessOptions}
127132
title={strings.eruComments}
133+
className={styles.inputSection}
128134
>
129135
<TextArea
130136
name="comment"
@@ -147,8 +153,7 @@ function EruInputItem(props: Props) {
147153
error={error?.has_capacity_to_support}
148154
/>
149155
</InputSection>
150-
</Container>
151-
156+
</InputSection>
152157
);
153158
}
154159

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
.eru-types {
1+
.eru-input-item {
22
display: flex;
3+
flex-direction: column;
34

4-
.readiness-options {
5+
.content {
56
display: flex;
6-
flex-direction: column;
7+
gap: var(--go-ui-spacing-sm);
8+
flex-wrap: wrap;
79

8-
.readiness-list {
10+
.input-section {
911
display: flex;
1012
flex-direction: column;
13+
flex-grow: 1;
14+
15+
.readiness-input {
16+
display: flex;
17+
18+
.radio-list {
19+
display: flex;
20+
flex-direction: column;
21+
}
22+
}
1123
}
1224
}
1325
}

Diff for: app/src/views/EruReadinessForm/i18n.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
"strings": {
44
"eruReadinessFormTitle": "Update ERU Readiness Form",
55
"eruReadinessFormHeading": "ERU Deployment Readiness",
6-
"eruReadinessFormDescription": "Complete the form with the ERU Readiness data of your National Society. In case of any questions.",
6+
"eruReadinessFormDescription": "Complete the form with the ERU readiness data of your National Society. In case of any questions, contact: {imContact} or {surgeContact}.",
7+
"imContact": "[email protected]",
8+
"surgeContact": "[email protected]",
79
"eruCancelButton": "Cancel",
810
"eruSaveAndCloseButton": "Save and Close",
9-
"eruNationalSociety": "National Society",
10-
"eruTypes": "Select ERU Type(s)",
11-
"eruFormCreatedSuccessfully": "ERU Readiness Created Successfully",
12-
"eruFormFailedToCreate": "Failed to create a ERU Readiness",
13-
"eruFormSuccessfullyUpdated": "Successfully Updated ERU Readiness Form",
14-
"eruFormFailedToUpdate": "Failed to Update ERU Readiness Form",
15-
"eruNoRecord": "No Existing Record"
11+
"eruSelectNationalSociety": "National Society",
12+
"eruSelectErus": "Select ERU Type(s)",
13+
"eruFormSuccessfullyUpdated": "Successfully updated ERU readiness",
14+
"eruFormFailedToUpdate": "Failed to update ERU readiness",
15+
"eruNoRecord": "No existing record",
16+
"eruOwnerFailedToFetch": "Failed to fetch ERU owners!",
17+
"eruReadinessFailedToFetch": "Failed to fetch ERU readiness information!",
18+
"eruFormSuccessfullyCreated": "Successfully created ERU readiness",
19+
"eruFormFailedToCreate": "Failed to create ERU readiness"
1620
}
1721
}

0 commit comments

Comments
 (0)