-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathRegistration.jsx
More file actions
90 lines (79 loc) · 2.29 KB
/
Copy pathRegistration.jsx
File metadata and controls
90 lines (79 loc) · 2.29 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
85
86
87
88
89
90
/**
* @jsx React.DOM
*/
var React = require('react')
var AccountFields = require('./AccountFields')
var Confirmation = require('./Confirmation')
var Success = require('./Success')
var SurveyFields = require('./SurveyFields')
var assign = require('object-assign')
// Idealy, these form values would be saved in another
// sort of persistence, like a Store via Flux pattern
var fieldValues = {
name : null,
email : null,
password : null,
age : null,
colors : []
}
var Registration = React.createClass({
getInitialState: function() {
return {
step : 1
}
},
saveValues: function(field_value) {
return function() {
fieldValues = assign({}, fieldValues, field_value)
}.bind(this)()
},
nextStep: function() {
this.setState({
step : this.state.step + 1
})
},
previousStep: function() {
this.setState({
step : this.state.step - 1
})
},
submitRegistration: function() {
// Handle via ajax submitting the user data, upon
// success return this.nextStop(). If it fails,
// show the user the error but don't advance
this.nextStep()
},
showStep: function() {
switch (this.state.step) {
case 1:
return <AccountFields fieldValues={fieldValues}
nextStep={this.nextStep}
previousStep={this.previousStep}
saveValues={this.saveValues} />
case 2:
return <SurveyFields fieldValues={fieldValues}
nextStep={this.nextStep}
previousStep={this.previousStep}
saveValues={this.saveValues} />
case 3:
return <Confirmation fieldValues={fieldValues}
previousStep={this.previousStep}
submitRegistration={this.submitRegistration} />
case 4:
return <Success fieldValues={fieldValues} />
}
},
render: function() {
var style = {
width : (this.state.step / 4 * 100) + '%'
}
return (
<main>
<span className="progress-step">Step {this.state.step}</span>
<progress className="progress" style={style}></progress>
{this.showStep()}
</main>
)
}
})
module.exports = Registration