import React, {Component} from 'react';
import {Container, Header, Content, Form, Item, Input, Label, Spinner, Button, Text, Icon} from 'native-base';
import {Platform, StyleSheet, View} from "react-native";
export default class UserRegister extends Component {
constructor(props) {
super(props);
this.state = {
firstName: '',
lastName: '',
email: '',
phoneNumber: '',
password: ''
}
}
canSubmitForm() {
/* No empty fields */
for([key, value] of Object.entries(this.state)) {
if(value === '') {
return false;
}
}
return true;
};
emailInput() {
return -
{
this.setState({email: text});
}}
onSubmitEditing={() => {
this.refs.phoneInput._root.focus()
}}
/>
;
}
passwordInput() {
// FIXME: How to dynamicly set error attribute? replace component, what?
return -
{
this.setState({password: text});
}}
onSubmitEditing={this.onRegisterPress}
/>
}
showError = () => {
// TODO: Format these and highlight error fields
if (this.props.registerError && Object.keys(this.props.registerError).length !== 0) {
const err = this.props.registerError.non_field_errors;
let errorFormatted = err ? err[0] : 'Kunne ikke registrere bruker, prøv igjen...';
return {errorFormatted}
}
else {
return
}
};
showSpinner = () => {
if (this.props.isRegisteringUser) {
return
}
};
render() {
return (
);
}
onRegisterPress = () => {
this.props.onRegisterPress(
this.state.firstName,
this.state.lastName,
this.state.email,
this.state.phoneNumber,
this.state.password,
);
};
registerbutton() {
if( this.props.isRegisteringUser || !this.canSubmitForm() ) {
return (
);
}
return ();
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
input: {
width: 320,
fontSize: 20,
height: 52,
},
registerButton: {
marginBottom: 16,
},
errorBox: {
marginVertical: 10,
},
errorMessage: {
textAlign: 'center',
color: 'red',
},
card: {
borderColor: '#e1e8ee',
borderWidth: 1,
...Platform.select({
ios: {
shadowColor: 'rgba(0,0,0, .2)',
shadowOffset: {height: 0, width: 0},
shadowOpacity: 1,
shadowRadius: 1,
},
android: {
elevation: 1,
},
}),
padding: 8,
margin: 8,
backgroundColor: '#fff',
},
});