-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserForm.js
More file actions
84 lines (76 loc) · 2.41 KB
/
Copy pathUserForm.js
File metadata and controls
84 lines (76 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { Component } from 'react';
import FormUserDetails from './FormUserDetails';
import FormPersonalDetails from './FormPersonalDetails';
import Confirm from './Confirm';
import Success from './Success';
export class UserForm extends Component {
// create state
state = {
step: 1,
firstName: '',
lastName: '',
email: '',
phone: '',
address: '',
city: '',
province: '',
postalCode: ''
}
// Method for going to next step
nextStep = () => {
// pull step out of state (destructure)
const { step } = this.state;
this.setState({
step: step + 1
});
}
// Method for going to previous step
prevStep = () => {
// pull step out of state (destructure)
const { step } = this.state;
this.setState({
step: step - 1
});
}
// Method to handle field change
handleChange = input => e => {
this.setState({[input]: e.target.value});
}
render() {
// Pull step out of state, pull fields out of state
const { step } = this.state;
const { firstName, lastName, email, phone, address, city, province, postalCode} = this.state;
// create variable 'values' for the inputs
const values = { firstName, lastName, email, phone, address, city, province, postalCode}
switch(step) {
case 1:
return (
<FormUserDetails
nextStep={this.nextStep}
handleChange={this.handleChange}
values={values}
/>
);
case 2:
return (
<FormPersonalDetails
nextStep={this.nextStep}
prevStep={this.prevStep}
handleChange={this.handleChange}
values={values}
/>
);
case 3:
return (
<Confirm
nextStep={this.nextStep}
prevStep={this.prevStep}
values={values}
/>
);
case 4:
return <Success />;
}
}
}
export default UserForm;