1
1
import * as React from 'react'
2
2
import { Formik , Form } from 'formik'
3
3
4
+ import { Wizard } from 'src/Components/Wizard'
4
5
import { Stepper } from 'src/Components/Stepper'
5
6
import { Button } from 'src/Components/Button'
6
7
import { BasicInfoForm } from '../BasicInfoForm'
@@ -22,81 +23,63 @@ interface FieldValues {
22
23
lng : number
23
24
}
24
25
25
- interface State {
26
- step : number
27
- }
28
-
29
26
// tslint:disable-next-line:jsx-key
30
27
const pages = [ < BasicInfoForm /> , < RoomInfoForm /> , < LocationForm /> ]
31
28
32
- export class CreateListingForm extends React . Component < { } , State > {
33
- public readonly state = {
34
- step : 0
35
- }
36
-
37
- private nextStep = ( ) => this . setState ( ( { step } ) => ( { step : step + 1 } ) )
38
-
39
- private prevStep = ( ) => {
40
- if ( this . state . step === 0 ) {
41
- return
42
- }
43
-
44
- this . setState ( ( { step } ) => ( { step : step - 1 } ) )
45
- }
46
-
47
- public render ( ) {
48
- const { step } = this . state
49
-
50
- return (
51
- < Formik < FieldValues >
52
- initialValues = { {
53
- name : '' ,
54
- category : '' ,
55
- picture : '' ,
56
- description : '' ,
57
- price : 0 ,
58
- guests : 0 ,
59
- beds : 0 ,
60
- amenities : '' ,
61
- lat : 0 ,
62
- lng : 0
63
- } }
64
- onSubmit = { ( values : FieldValues ) => {
65
- console . log ( values )
66
- } }
67
- >
68
- { ( { submitForm } ) => (
69
- < Form >
70
- < Stepper
71
- currentStep = { step + 1 }
72
- maxSteps = { pages . length }
73
- />
74
- < Container >
75
- < Wrapper >
76
- { pages [ step ] }
77
- < Buttons >
78
- < Button
79
- disabled = { step === 0 }
80
- onClick = { this . prevStep }
81
- >
82
- Wstecz
83
- </ Button >
84
-
85
- { step === pages . length - 1 ? (
86
- < Button onClick = { submitForm } >
87
- Submit
88
- </ Button >
89
- ) : (
90
- < Button onClick = { ( ) => this . nextStep ( ) } >
91
- Dalej
29
+ export const CreateListingForm : React . SFC = ( ) => (
30
+ < Formik < FieldValues >
31
+ initialValues = { {
32
+ name : '' ,
33
+ category : '' ,
34
+ picture : '' ,
35
+ description : '' ,
36
+ price : 0 ,
37
+ guests : 0 ,
38
+ beds : 0 ,
39
+ amenities : '' ,
40
+ lat : 0 ,
41
+ lng : 0
42
+ } }
43
+ onSubmit = { ( values : FieldValues ) => {
44
+ console . log ( values )
45
+ } }
46
+ >
47
+ { ( { submitForm } ) => (
48
+ < Form >
49
+ < Wizard >
50
+ { ( { nextStep, prevStep, step } ) => (
51
+ < >
52
+ < Stepper
53
+ currentStep = { step + 1 }
54
+ maxSteps = { pages . length }
55
+ />
56
+ < Container >
57
+ < Wrapper >
58
+ { pages [ step ] }
59
+ < Buttons >
60
+ < Button
61
+ disabled = { step === 0 }
62
+ onClick = { prevStep }
63
+ >
64
+ Wstecz
92
65
</ Button >
93
- ) }
94
- </ Buttons >
95
- </ Wrapper >
96
- </ Container >
97
- </ Form >
98
- ) }
99
- </ Formik >
100
- )
101
- }
102
- }
66
+
67
+ { step === pages . length - 1 ? (
68
+ < Button onClick = { submitForm } >
69
+ Submit
70
+ </ Button >
71
+ ) : (
72
+ < Button onClick = { nextStep } >
73
+ Dalej
74
+ </ Button >
75
+ ) }
76
+ </ Buttons >
77
+ </ Wrapper >
78
+ </ Container >
79
+ </ >
80
+ ) }
81
+ </ Wizard >
82
+ </ Form >
83
+ ) }
84
+ </ Formik >
85
+ )
0 commit comments