forked from vtex/profile-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
102 lines (95 loc) · 3.24 KB
/
App.js
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
91
92
93
94
95
96
97
98
99
100
101
102
import React, { Component } from 'react'
import { IntlProvider, addLocaleData } from 'react-intl'
import ptLocaleData from 'react-intl/locale-data/pt'
import Button from '@vtex/styleguide/lib/Button'
import ptTranslations from '../../messages/pt'
import ProfileContainer from '../../react/ProfileContainer'
import ProfileRules from '../../react/ProfileRules'
import ProfileSummary from '../../react/ProfileSummary'
import DisplaySlice from './DisplaySlice'
import emptyProfile from '../../react/modules/emptyProfile'
import 'vtex-tachyons'
class App extends Component {
constructor(props) {
super(props)
addLocaleData(ptLocaleData)
this.state = {
profile: emptyProfile,
profileCountry: 'BRA',
submitted: false,
}
}
toggleLocale = () => {
this.setState(prevState => ({
profileCountry: prevState.profileCountry === 'BRA' ? 'USA' : 'BRA',
}))
}
handleSubmit = ({ valid, profile }) => {
if (!valid) return
this.setState({ profile, submitted: true })
}
render() {
const { profile, profileCountry, submitted } = this.state
return (
<div className="pa4">
<h2 className="dark-gray">ProfileForm demo:</h2>
{!submitted && (
<div className="mb6">
<Button
size="small"
variation="secondary"
onClick={this.toggleLocale}
>
Set rules to {profileCountry === 'BRA' ? 'USA' : 'BRA'}
</Button>
</div>
)}
<IntlProvider locale={'pt-BR'} messages={ptTranslations}>
<div>
<ProfileRules
key={profileCountry}
country={profileCountry}
fetch={country => import('../../src/rules/' + country)}
>
{submitted ? (
<ProfileSummary profile={profile}>
{({ personalData, businessData, isCorporate }) => (
<div>
<h3 className="heavy-rebel-pink">Personal Data:</h3>
{Object.keys(personalData).map(fieldName => (
<DisplaySlice
key={fieldName}
slice={personalData[fieldName]}
/>
))}
<h3 className="heavy-rebel-pink">Business Data:</h3>
{Object.keys(businessData).map(fieldName => (
<DisplaySlice
key={fieldName}
slice={businessData[fieldName]}
/>
))}
<h3 className="heavy-rebel-pink">
Is corporate?
<span className="near-black ml3">
{isCorporate ? 'yes' : 'no'}
</span>
</h3>
</div>
)}
</ProfileSummary>
) : (
<ProfileContainer
defaultProfile={profile}
onSubmit={this.handleSubmit}
shouldShowExtendedGenders={true}
/>
)}
</ProfileRules>
</div>
</IntlProvider>
</div>
)
}
}
export default App