-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateProfile.jsx
318 lines (290 loc) · 8.91 KB
/
CreateProfile.jsx
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// @flow
import React, { Component } from 'react';
import { View, ScrollView } from 'react-native';
import Geocoder from 'react-native-geocoder';
import { observer, inject } from 'mobx-react/native';
import ImagePicker from 'react-native-image-crop-picker';
import moment from 'moment';
import DatePicker from './components/datePicker';
import AccountPhoto from './components/accountPhoto/AccountPhoto';
import TextInputFiled from './components/textInputField/TextInputFiled';
import TextField from './components/textField';
import BonusCardNumber from './components/bonusCardNumber/BonusCardNumber';
import Button from './components/buttons/Button';
import RowChooseOneOfThird from './components/rowChooseOnOfThird/RowChooseOneOfThird';
import styles from './styles';
import { getFileFormat } from './common/file.functions';
import { showActionSheet } from './components/actionSheet';
import type { _t_props, _t_state } from './flow.types';
import type { _t_sdk_instance } from './common/flow.types';
@inject((allStores) => ({
auth: allStores.auth,
store: allStores.createYourProfile
}))
@observer
export default class CreateProfile extends Component {
state: _t_state;
instance: _t_sdk_instance;
constructor(props: _t_props) {
super(props);
this.state = {
activeGender: 0,
valid: true
};
this.instance = props.screenProps.sdk;
}
componentWillUnmount() {
this.props.store.clearStore();
}
_imagePathChanged(imagePath) {
this.props.store.setValue({ imagePath });
}
_firstChanged(event: string) {
this.props.store.setValue({ first: event });
}
_lastChanged(event: string) {
this.props.store.setValue({ last: event });
}
_genderChanged(gender: string, index: number) {
this.setState({ activeGender: index }, () => {
this.props.store.setValue({ gender });
});
}
_birthdayChanged(birthday, date) {
this.props.store.setValue({ birthday: moment(birthday, 'DD. MMM YYYY') });
}
_zipChanged(zip: string) {
this.props.store.setValue({ zip });
}
_cityChanged(city: string) {
this.props.store.setValue({ city });
}
_countryChanged(country: string) {
this.props.store.setValue({ country });
}
_bonusCardChanged(bonusCard: string) {
this.props.store.setValue({ bonusCard });
}
_autoPopulateCity() {
if (this.props.store.zip) {
// test zipcode - 12201 - Rhodel
Geocoder.geocodeAddress(this.props.store.zip)
.then(res => {
if (res.length) {
this.props.store.setValue({ city: res[0].locality });
this.props.store.setValue({ country: res[0].country });
}
})
.catch(err => { });
}
}
_setImage(image) {
this.props.store.setValue({
image: {
...image,
format: getFileFormat(image.mime),
}
});
}
_openCamera() {
ImagePicker.openCamera({
width: 300,
height: 300,
cropping: true
}).then(this._setImage.bind(this));
}
_openGallery() {
ImagePicker.openPicker({
width: 300,
height: 300,
cropping: true
}).then(this._setImage.bind(this));
}
_callPhotoModule() {
let options = [
{
label: 'Take a Photo',
onPress: this._openCamera.bind(this)
},
{
label: 'Choose Photo from gallery',
onPress: this._openGallery.bind(this)
},
{
label: 'Close',
onPress: () => { console.log('Cancel'); },
isCancel: true
}
];
showActionSheet(options);
}
_submit(toDashboard) {
const { first, last, birthday, zip, city, country } = this.props.store,
isValid = (first && last && birthday && zip && city && country) ? true : false;
this.setState({
valid: isValid
});
if (isValid) {
this._sendRequest()
.then((user) => {
if (toDashboard) {
}
else {
this.props.navigation.navigate("CreateEntity");
}
})
.catch((err) => {
});
}
}
_sendRequest() {
const { email, uid } = this.props.auth;
const { image, first, last, gender, birthday, zip, city, country } = this.props.store;
let source = {
authSource: uid,
avatar: image ? image : null,
createdAt: moment().format('YYYY-MM-DD'),
lastLoginAt: moment().format('YYYY-MM-DD'),
profile: {
personalData: {
email: email,
birthday: birthday.format('YYYY-MM-DD'),
firstName: first,
lastName: last,
gender: gender,
zip: zip,
city: city,
country: country
}
}
};
return this.instance.user.create(source, uid);
}
_renderDatePicker(value: null | Date) {
return (
<DatePicker
ref="birthday"
style={styles.datePicker}
date={value}
mode="date"
format="DD. MMM YYYY"
confirmBtnText={'Confirm'}
cancelBtnText={'Cancel'}
minDate={moment('1900', 'YYYY')}
showIcon={false}
onPressConfirm={this._birthdayChanged.bind(this)}
onDateChange={this._birthdayChanged.bind(this)}
/>
);
}
render() {
const { image, first, last, gender, birthday, zip, city, country, bonusCard } = this.props.store;
const optionsSex = [
{
label: "FEMALE",
value: 'F',
onPress: this._genderChanged.bind(this),
isActive: gender === 'F',
btnNumber: "first",
},
{
label: "MALE",
value: 'M',
onPress: this._genderChanged.bind(this),
isActive: gender === 'M',
btnNumber: "second",
},
{
label: "OTHER",
value: 'other',
onPress: this._genderChanged.bind(this),
isActive: gender === 'other',
btnNumber: "third",
},
];
const imageSource = image ? { uri: image.path } : null;
const datePicker = this._renderDatePicker(birthday);
return (
<View style={styles.mainConteiner}>
<ScrollView>
<View style={styles.pageBody}>
<AccountPhoto
onPress={this._callPhotoModule.bind(this)}
imgUrl={imageSource}
/>
<TextInputFiled
isShowAlert={!first && !this.state.valid}
textInputLabel={"First Name"}
textInputAlert="Check your First Name format"
secureTextEntry={false}
onChangeText={this._firstChanged.bind(this)}
value={first}
isShowCheckbox={false}
/>
<TextInputFiled
isShowAlert={!last && !this.state.valid}
textInputLabel={"Last Name"}
textInputAlert="Check your Last Name format"
secureTextEntry={false}
onChangeText={this._lastChanged.bind(this)}
value={last}
isShowCheckbox={false}
/>
<RowChooseOneOfThird
options={optionsSex}
/>
<TextField
isShowAlert={!birthday && !this.state.valid}
textInputLabel={"Birthday"}
textInputAlert="Check your Birthday format"
onPressBlock={() => { this.refs.birthday.onPressDate(); }}
value={birthday ? birthday.format('DD-MM-YYYY') : ''}
isShowCheckbox={false}
isShowTextInputIcon={true}
imgUrl={require('../../../assets/img/calendar.png')}
/>
<TextInputFiled
isShowAlert={!zip && !this.state.valid}
textInputLabel={"ZIP / Postal code"}
onBlur={this._autoPopulateCity.bind(this)}
textInputAlert="Check your ZIP / Postal code format"
secureTextEntry={false}
onChangeText={this._zipChanged.bind(this)}
value={zip}
isShowCheckbox={false}
/>
<TextInputFiled
isShowAlert={!city && !this.state.valid}
textInputLabel={"City"}
textInputAlert="Check your City code format"
secureTextEntry={false}
onChangeText={this._cityChanged.bind(this)}
value={city}
isShowCheckbox={false}
/>
<TextInputFiled
isShowAlert={!country && !this.state.valid}
textInputLabel={"Country"}
textInputAlert="Check your Country code format"
secureTextEntry={false}
onChangeText={this._countryChanged.bind(this)}
value={country}
isShowCheckbox={false}
/>
<Button
label={"NEXT - ADD YOUR ENTITY"}
color={"green"}
onPress={() => { this._submit(); }}
/>
<Button
label={"SKIP ADD ENTITY AND GO TO HOMEPAGE"}
color={"transparent"}
onPress={() => { this._submit(true); }}
/>
</View>
</ScrollView>
{datePicker}
</View>
);
}
}