1
1
import React from 'react'
2
2
3
3
import { range } from 'lodash'
4
- import { Control , Field } from 'react-redux-form '
4
+ import { Field , FastField , useFormikContext , getIn } from 'formik '
5
5
import { Row , Col , FormGroup , Label , FormText ,
6
- Input , InputGroup , InputGroupAddon , InputGroupText } from 'reactstrap'
6
+ InputGroup , InputGroupAddon , InputGroupText } from 'reactstrap'
7
+
8
+ import { Input } from '../../../../../../../Form'
7
9
8
10
import { CodingGroup } from './Coding'
9
11
import { CollapsingOptions } from './BaseOptions'
10
12
11
- export default ( { data, rowIndex } ) =>
12
- < >
13
+ export default ( { name, index } ) => {
14
+ const { values } = useFormikContext ( )
15
+ const width = getIn ( values , `${ name } .width` )
16
+
17
+ return < >
13
18
< Row form >
14
19
< Col >
15
- < Control
16
- model = " .label"
20
+ < Field
21
+ name = { ` ${ name } .label` }
17
22
placeholder = "Question"
18
23
component = { Input }
19
- debounce = { 300 }
20
24
/>
21
25
</ Col >
22
26
</ Row >
23
27
< CodingGroup
24
- data = { data . items }
25
- model = ".items"
26
- itemModel = { `.rows[${ rowIndex } ][0]` }
28
+ name = { `${ name } .items` }
27
29
icon = "ellipsis-h-alt"
28
30
iconFallbackWeight = "s"
29
31
/>
30
32
< CollapsingOptions
31
- rowIndex = { rowIndex }
33
+ name = { name }
34
+ index = { index }
32
35
shuffle = { true }
33
36
>
34
37
< Row >
35
38
< Col >
36
39
< FormGroup className = "my-2" >
37
- < Label for = { `page-item-${ rowIndex } -width` } className = "mb-0" >
40
+ < Label for = { `page-item-${ index } -width` } className = "mb-0" >
38
41
Scale width
39
42
</ Label >
40
43
< FormText color = "muted" >
41
44
How many points to offer
42
45
</ FormText >
43
- < Field model = ".width" className = "mt-1" >
44
- < FormGroup >
45
- {
46
- [ 5 , 7 , 9 , 11 ] . map ( w =>
47
- < div
48
- key = { `page-item-${ rowIndex } -width-${ w } ` }
49
- className = "custom-radio custom-control"
46
+ < FormGroup >
47
+ {
48
+ [ 5 , 7 , 9 , 11 ] . map ( w =>
49
+ < div
50
+ key = { `page-item-${ index } -width-${ w } ` }
51
+ className = "custom-radio custom-control"
52
+ >
53
+ < Field
54
+ name = { `${ name } .width` }
55
+ type = "radio"
56
+ value = { `${ w } ` }
57
+ id = { `page-item-${ index } -width-${ w } ` }
58
+ className = "custom-control-input"
59
+ />
60
+ < label
61
+ htmlFor = { `page-item-${ index } -width-${ w } ` }
62
+ className = "custom-control-label"
50
63
>
51
- < input
52
- type = "radio" value = { `${ w } ` }
53
- id = { `page-item-${ rowIndex } -width-${ w } ` }
54
- className = "custom-control-input"
55
- />
56
- < label
57
- htmlFor = { `page-item-${ rowIndex } -width-${ w } ` }
58
- className = "custom-control-label"
59
- >
60
- { w }
61
- </ label >
62
- </ div >
63
- )
64
- }
65
- </ FormGroup >
66
- </ Field >
64
+ { w }
65
+ </ label >
66
+ </ div >
67
+ )
68
+ }
69
+ </ FormGroup >
67
70
</ FormGroup >
68
71
</ Col >
69
72
< Col >
70
73
< FormGroup className = "my-2" >
71
- < Label for = { `page-item-${ rowIndex } -anchors` } className = "mb-0" >
74
+ < Label for = { `page-item-${ index } -anchors` } className = "mb-0" >
72
75
Anchors
73
76
</ Label >
74
77
< FormText color = "muted" >
75
78
Scale anchors
76
79
</ FormText >
77
80
< div className = "mt-2" >
78
81
{
79
- range ( data . width ) . map ( i =>
82
+ range ( width ) . map ( i =>
80
83
< Row form
81
84
className = "my-1"
82
- key = { `page-item-${ rowIndex } -anchors-${ i } ` }
85
+ key = { `page-item-${ index } -anchors-${ i } ` }
83
86
>
84
87
< Col >
85
88
< InputGroup >
@@ -90,10 +93,9 @@ export default ({ data, rowIndex }) =>
90
93
</ small >
91
94
</ InputGroupText >
92
95
</ InputGroupAddon >
93
- < Control
94
- model = { `.anchors[${ i } ]` }
96
+ < FastField
97
+ name = { `${ name } .anchors[${ i } ]` }
95
98
component = { Input }
96
- debounce = { 300 }
97
99
/>
98
100
</ InputGroup >
99
101
</ Col >
@@ -106,3 +108,4 @@ export default ({ data, rowIndex }) =>
106
108
</ Row >
107
109
</ CollapsingOptions >
108
110
</ >
111
+ }
0 commit comments