Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit f3b92ad

Browse files
Port input page item to formik
1 parent 5704fbb commit f3b92ad

File tree

1 file changed

+40
-34
lines changed
  • packages/builder/src/components/ComponentOptions/components/Content/Page/components/ItemOptions/components

1 file changed

+40
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from 'react'
22

3-
import { Control } from 'react-redux-form'
3+
import { Field, useFormikContext, getIn } from 'formik'
44
import { Row, Col,
5-
Input, InputGroup, InputGroupAddon, InputGroupText,
5+
InputGroup, InputGroupAddon, InputGroupText,
66
FormGroup, Label, FormText } from 'reactstrap'
77

88
import { CollapsingOptions } from './BaseOptions'
99
import Icon from '../../../../../../../Icon'
10+
import { Input } from '../../../../../../../Form'
1011

11-
export const ExtraOptions = ({ type }) => {
12+
export const ExtraOptions = ({ name, type }) => {
1213
switch (type) {
1314
case 'number':
1415
return <>
@@ -19,33 +20,33 @@ export const ExtraOptions = ({ type }) => {
1920
<Icon icon="arrow-to-bottom" fallback="arrow-down" />
2021
</InputGroupText>
2122
</InputGroupAddon>
22-
<Control
23-
model=".attributes.min"
23+
<Field
24+
name={ `${ name }.attributes.min` }
2425
placeholder="No lower limit"
2526
component={ Input }
26-
style={{ fontFamily: 'Fira Mono' }}
27+
className="text-monospace"
2728
/>
2829
<InputGroupAddon addonType="prepend">
2930
<InputGroupText>
3031
<Icon icon="arrow-to-top" fallback="arrow-up" />
3132
</InputGroupText>
3233
</InputGroupAddon>
33-
<Control
34-
model=".attributes.max"
34+
<Field
35+
name={ `${ name }.attributes.max` }
3536
placeholder="No upper limit"
3637
component={ Input }
37-
style={{ fontFamily: 'Fira Mono' }}
38+
className="text-monospace"
3839
/>
3940
<InputGroupAddon addonType="prepend">
4041
<InputGroupText>
4142
<Icon icon="shoe-prints" />
4243
</InputGroupText>
4344
</InputGroupAddon>
44-
<Control
45-
model=".attributes.step"
45+
<Field
46+
name={ `${ name }.attributes.step` }
4647
placeholder="Default step (1)"
4748
component={ Input }
48-
style={{ fontFamily: 'Fira Mono' }}
49+
className="text-monospace"
4950
/>
5051
</InputGroup>
5152
</FormGroup>
@@ -59,22 +60,22 @@ export const ExtraOptions = ({ type }) => {
5960
<Icon icon="arrow-to-bottom" fallback="arrow-down" />
6061
</InputGroupText>
6162
</InputGroupAddon>
62-
<Control
63-
model=".attributes.min"
63+
<Field
64+
name={ `${ name }.attributes.min` }
6465
placeholder="No earliest date (yyyy-mm-dd)"
6566
component={ Input }
66-
style={{ fontFamily: 'Fira Mono' }}
67+
className="text-monospace"
6768
/>
6869
<InputGroupAddon addonType="prepend">
6970
<InputGroupText>
7071
<Icon icon="arrow-to-top" fallback="arrow-up" />
7172
</InputGroupText>
7273
</InputGroupAddon>
73-
<Control
74-
model=".attributes.max"
74+
<Field
75+
name={ `${ name }.attributes.max` }
7576
placeholder="No latest date (yyyy-mm-dd)"
7677
component={ Input }
77-
style={{ fontFamily: 'Fira Mono' }}
78+
className="text-monospace"
7879
/>
7980
</InputGroup>
8081
</FormGroup>
@@ -84,46 +85,51 @@ export const ExtraOptions = ({ type }) => {
8485
}
8586
}
8687

87-
export default ({ rowIndex, type, data }) =>
88-
<>
88+
export default ({ name, index, type }) => {
89+
const { values } = useFormikContext()
90+
const attributes = getIn(values, `${ name }.attributes`)
91+
92+
return <>
8993
<Row form>
9094
<Col>
91-
<Control
92-
model=".label"
95+
<Field
96+
name={ `${ name }.label` }
9397
placeholder="Question"
9498
component={ Input }
95-
debounce={ 300 }
9699
/>
97100
</Col>
98101
</Row>
99102
<CollapsingOptions
100-
rowIndex={ rowIndex }
103+
name={ name }
104+
index={ index }
101105
>
102106
{
103107
type === 'input' && <>
104108
<FormGroup className="my-2">
105-
<Label for={ `page-item-${ rowIndex }-attrs-type` } className="mb-1">
109+
<Label for={ `page-item-${ index }-attrs-type` } className="mb-1">
106110
Data type
107111
</Label>
108112
<FormText color="muted" className="mb-2">
109113
Check input format, and restrict input
110114
</FormText>
111-
<Control.select
112-
model=".attributes.type"
113-
className="form-control custom-select"
114-
style={{ fontFamily: 'Fira Mono' }}
115-
controlProps={{
116-
id: `page-item-${ rowIndex }-attrs-type`,
117-
}}
115+
<Field
116+
name={ `${ name }.attributes.type` }
117+
index={ `page-item-${ index }-attrs-type` }
118+
as="select"
119+
className="form-control custom-select text-monospace"
118120
>
119121
<option value="text">Text</option>
120122
<option value="number">Number</option>
121123
<option value="email">Email</option>
122124
<option value="date">Date</option>
123-
</Control.select>
125+
</Field>
124126
</FormGroup>
125-
<ExtraOptions type={ data.attributes && data.attributes.type } />
127+
<ExtraOptions
128+
name={ name }
129+
type={ attributes && attributes.type }
130+
/>
126131
</>
127132
}
128133
</CollapsingOptions>
129134
</>
135+
}

0 commit comments

Comments
 (0)