1
+ import { useMemo } from 'react' ;
1
2
import {
2
3
Checkbox ,
3
- Container ,
4
4
InputSection ,
5
5
RadioInput ,
6
6
TextArea ,
@@ -10,15 +10,14 @@ import { randomString } from '@togglecorp/fujs';
10
10
import {
11
11
type ArrayError ,
12
12
getErrorObject ,
13
- type PartialForm ,
14
13
type SetValueArg ,
15
14
useFormObject ,
16
15
} from '@togglecorp/toggle-form' ;
17
16
18
17
import useGlobalEnums from '#hooks/domain/useGlobalEnums' ;
19
18
import { type GoApiResponse } from '#utils/restRequest' ;
20
19
21
- import { type EruType } from '../schema' ;
20
+ import { type PartialEruItem } from '../schema' ;
22
21
23
22
import i18n from './i18n.json' ;
24
23
import styles from './styles.module.css' ;
@@ -35,30 +34,29 @@ function readinessLabelSelector(option: ReadinessOption) {
35
34
return option . value ;
36
35
}
37
36
38
- const defaultCollectionValue : PartialForm < EruType > = {
37
+ const defaultCollectionValue : PartialEruItem = {
39
38
client_id : randomString ( ) ,
40
39
} ;
41
40
42
41
interface Props {
43
42
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 ;
48
46
}
49
47
50
48
function EruInputItem ( props : Props ) {
51
49
const {
52
50
index,
53
51
value,
54
52
onChange,
55
- title,
56
53
error : errorFromProps ,
57
54
} = props ;
58
55
59
56
const strings = useTranslation ( i18n ) ;
60
57
61
58
const {
59
+ deployments_eru_type : eruTypeOptions ,
62
60
deployments_eru_readiness_status,
63
61
} = useGlobalEnums ( ) ;
64
62
@@ -72,17 +70,23 @@ function EruInputItem(props: Props) {
72
70
? getErrorObject ( errorFromProps ?. [ value . client_id ] )
73
71
: undefined ;
74
72
73
+ const title = useMemo ( ( ) => (
74
+ eruTypeOptions ?. find ( ( eruType ) => eruType . key === value . type ) ?. value
75
+ ) , [ eruTypeOptions , value . type ] ) ;
76
+
75
77
return (
76
- < Container
77
- childrenContainerClassName = { styles . eruTypes }
78
- heading = { title }
78
+ < InputSection
79
+ title = { title }
80
+ className = { styles . eruInputItem }
81
+ contentSectionClassName = { styles . content }
79
82
>
80
83
< InputSection
81
- className = { styles . readinessOptions }
82
84
title = { strings . eruEquipmentReadiness }
85
+ className = { styles . inputSection }
83
86
>
84
87
< RadioInput
85
- listContainerClassName = { styles . readinessList }
88
+ className = { styles . readinessInput }
89
+ listContainerClassName = { styles . radioList }
86
90
name = "equipment_readiness"
87
91
value = { value . equipment_readiness }
88
92
onChange = { onFieldChange }
@@ -93,11 +97,12 @@ function EruInputItem(props: Props) {
93
97
/>
94
98
</ InputSection >
95
99
< InputSection
96
- className = { styles . readinessOptions }
97
100
title = { strings . eruPeopleReadiness }
101
+ className = { styles . inputSection }
98
102
>
99
103
< RadioInput
100
- listContainerClassName = { styles . readinessList }
104
+ className = { styles . readinessInput }
105
+ listContainerClassName = { styles . radioList }
101
106
name = "people_readiness"
102
107
value = { value . people_readiness }
103
108
onChange = { onFieldChange }
@@ -108,11 +113,12 @@ function EruInputItem(props: Props) {
108
113
/>
109
114
</ InputSection >
110
115
< InputSection
111
- className = { styles . readinessOptions }
112
116
title = { strings . eruFundingReadiness }
117
+ className = { styles . inputSection }
113
118
>
114
119
< RadioInput
115
- listContainerClassName = { styles . readinessList }
120
+ className = { styles . readinessInput }
121
+ listContainerClassName = { styles . radioList }
116
122
name = "funding_readiness"
117
123
value = { value . funding_readiness }
118
124
onChange = { onFieldChange }
@@ -123,8 +129,8 @@ function EruInputItem(props: Props) {
123
129
/>
124
130
</ InputSection >
125
131
< InputSection
126
- className = { styles . readinessOptions }
127
132
title = { strings . eruComments }
133
+ className = { styles . inputSection }
128
134
>
129
135
< TextArea
130
136
name = "comment"
@@ -147,8 +153,7 @@ function EruInputItem(props: Props) {
147
153
error = { error ?. has_capacity_to_support }
148
154
/>
149
155
</ InputSection >
150
- </ Container >
151
-
156
+ </ InputSection >
152
157
) ;
153
158
}
154
159
0 commit comments