import React, { Component } from 'react';
import { StyleSheet, Text, View, Image, ScrollView } from 'react-native';
import PropTypes from 'prop-types';
import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';
import Icon from 'react-native-vector-icons/MaterialIcons';
import { responsiveHeight, responsiveWidth, responsiveFontSize } from 'react-native-responsive-dimensions';
import { Fumi, Kaede } from 'react-native-textinput-effects'
import * as Animatable from 'react-native-animatable'
import Button from 'apsl-react-native-button'
import { categoryChild } from './../../webservice/AuthApi'
let theme = require('./../../utils/theme.json')
let route = require('./../../route.json')
import I18n from 'react-native-i18n';
export default class CreateAccount extends Component {
static navigatorStyle = {
drawUnderNavBar: true,
navBarHidden: true,
drawUnderStatusBar: false,
statusBarHidden: true,
statusBarTextColorScheme: 'light',
};
static options(passProps) {
return {
topBar: {
visible: false,
enabled: false,
drawBehind: true,
},
statusBar: {
drawBehind: true,
enabled: false,
}
}
}
constructor(props) {
super(props);
this.state = this.initState();
const { navigation } = this.props;
this.type = navigation.getParam('type', 0);
}
initState() {
return {
password: null,
enterPhone: null,
nameanim: null,
surnameanim: null,
passwordanim: null,
confirmpassanim: null,
isLoging: false,
snackVisible: false,
snackText: '',
user: { category: this.type === 0 ? 'user' : 'geolocated' }
}
}
render() {
return this.type === 1 ? this.renderUserGeoAccount() : this.renderUserAccount()
}
renderUserGeoAccount() {
return (
this.props.navigation.pop()}
/>
{I18n.t('TEXT_BIG_CREATE_AGENT_1')}
{I18n.t('TEXT_SUBTITLE_CREATE_1')}
{ this.nameanim = comp }}>
{
let use = this.state.user;
use.lastname = text;
this.setState({ user: use })
}}
style={styles.input}
>
{ this.surnameanim = comp }}>
{
let use = this.state.user;
use.address = text;
this.setState({ user: use })
}}
>
{ this.mailanim = comp }}>
{
let use = this.state.user;
use.email = text;
this.setState({ user: use })
}}
style={styles.input}
>
{ this.memberanim = comp }}>
{
let use = this.state.user;
use.member = text;
this.setState({ user: use })
}}
iconSize={20}
style={styles.input}
>
{ this.passanim = comp }}>
{
let use = this.state.user;
use.password = text;
this.setState({ user: use })
}}
iconSize={20}
style={styles.input}
>
{ this.confirmanim = comp }}>
{
let use = this.state.user;
use.confirmpass = text;
this.setState({ user: use })
}}
iconSize={20}
style={styles.input}
>
)
}
renderUserAccount() {
return (
this.props.navigation.pop()}
/>
{I18n.t('TEXT_BIG_CREATE_1')}
{I18n.t('TEXT_SUBTITLE_CREATE_1')}
{ this.nameanim = comp }}>
{
let use = this.state.user;
use.lastname = text;
this.setState({ user: use })
}}
iconColor={'#f95a25'}
iconSize={20}
style={styles.input}
>
{ this.surnameanim = comp }}>
{
let use = this.state.user;
use.address = text;
this.setState({ user: use })
}}
style={styles.input}
>
{ this.mailanim = comp }}>
{
let use = this.state.user;
use.email = text;
this.setState({ user: use })
}}
style={styles.input}
>
{ this.passanim = comp }}>
{
let use = this.state.user;
use.password = text;
this.setState({ user: use })
}}
style={styles.input}
>
{ this.confirmanim = comp }}>
{
let use = this.state.user;
use.confirmpass = text;
this.setState({ user: use })
}}
style={styles.input}
>
)
}
_onUserCreateAccount() {
let { user } = this.state;
console.log(user)
if (user !== undefined) {
if (this.checkOrShake(user.lastname, this.nameanim)) {
if (this.checkOrShake(user.address, this.surnameanim)) {
if (this.checkOrShake(user.email, this.mailanim)) {
if (this.checkOrShake(user.password, this.passanim)) {
if (this.checkOrShake(user.confirmpass, this.confirmanim)) {
if (user.confirmpass === user.password) {
this.props.navigation.push(route.creationstep2, {
type: this.type,
user: user
})
} else {
this.passanim.shake(800)
this.confirmanim.shake(800)
}
}
}
}
}
}
} else {
/*this.props.navigator.showSnackbar({
text:"impossible de trouvé l'utilisateur"
})
console.log(user)
*/}
}
checkUserGeolocated() {
let { user } = this.state;
this.setState({ isLoging: true })
if (user !== undefined) {
if (this.checkOrShake(user.lastname, this.nameanim)) {
if (this.checkOrShake(user.address, this.surnameanim)) {
if (this.checkOrShake(user.email, this.mailanim)) {
if (this.checkOrShake(user.member, this.memberanim)) {
categoryChild(user.member).then((codes) => {
if (codes !== undefined && codes !== null && codes.child !== undefined) {
let user = this.state.user;
user.category = codes.child;
this.setState({ user: user })
} this.setState({ isLoging: false })
if (this.checkOrShake(user.password, this.passanim)) {
if (this.checkOrShake(user.confirmpass, this.confirmanim)) {
if (user.password === user.confirmpass) {
this.props.navigation.push(route.creationstep2, {
type: this.type,
user: user
})
} else {
this.passanim.shake(800)
this.confirmanim.shake(800)
this.setState({ isLoging: false })
}
} else {
this.setState({ isLoging: false })
}
} else this.setState({ isLoging: false })
}).catch((e) => {
this.setState({ isLoging: false })
})
} else this.setState({ isLoging: false })
} else this.setState({ isLoging: false })
} else this.setState({ isLoging: false })
} else this.setState({ isLoging: false })
} else {
this.setState({ isLoging: false })
/*this.props.navigator.showSnackbar({
text:"impossible de trouvé la variable user"
})*/
console.log(user)
}
}
checkOrShake(champ, view) {
let res = false;
if (champ !== undefined && champ.length > 0) {
res = true;
} else {
view.shake(800)
}
return res;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: theme.primaryDark,
},
textbtnvalide: {
color: 'white',
fontWeight: 'bold'
},
bigtitle: {
color: 'white',
fontSize: 20,
flex: 1,
fontWeight: 'bold',
textAlign: 'center',
margin: 20,
},
subbigtitle: {
color: 'white',
fontSize: 17,
textAlign: 'center',
margin: 5,
},
btnvalide: {
marginTop: 20,
marginLeft: 20,
marginRight: 20,
borderColor: 'transparent',
backgroundColor: theme.accentLight,
height: 52
},
input: {
height: 60,
marginTop: responsiveHeight(2),
marginLeft: responsiveWidth(5),
marginRight: responsiveWidth(5),
borderRadius: 5,
}
})