Commit 88a3f7ff by Prachpawee

update router and add validation to register

parent 8b3c48f3
......@@ -28,6 +28,7 @@
"react-native-elements": "^1.1.0",
"react-native-gesture-handler": "^1.2.1",
"react-native-router-flux": "^4.0.6",
"react-native-validate-form": "^1.1.3",
"react-native-vector-icons": "^6.5.0",
"react-native-web": "^0.11.4",
"react-navigation": "^3.11.0",
......
import React from 'react';
import { TextInput, Text, View } from 'react-native';
import { Icon, Item, Input } from 'native-base';
import { color, theme } from '../../constants/Styles';
const InputField = ({
name, // field name - required
customStyle,
onChangeText, // event
value, // field value
disabled,
placeholder,
errors, // this array prop is automatically passed down to this component from <Form />
isPass,
}) => {
return (
<View style={theme.inputContainer}>
<TextInput
value={value && value}
onChangeText={onChangeText ? val => onChangeText(val) : null}
placeholder={placeholder ? placeholder : ''}
placeholderTextColor={color.grey2}
disabled={disabled}
style={customStyle ? customStyle : {}}
secureTextEntry={isPass}
/>
{errors &&
errors.length > 0 &&
errors.map((item, index) =>
item.field === name && item.error ? (
// <Text key={`${index}`} style={{ color: 'red', marginLeft: 5, marginTop: 5 }}>
// {item.error}
// </Text>
<Icon key={`${index}`} name="close" style={theme.inputErr} />
) : null
)}
</View>
);
};
export default InputField;
import { StyleSheet } from 'react-native';
export const color = {
grey1: '#808080',
grey2: '#cacaca',
grey3: '#4a4a4a',
primary: '#f44c4c',
};
export const theme = StyleSheet.create({
startContainer: { top: 120, paddingHorizontal: 50 },
startTitle: { textAlign: 'center', color: '#4a4a4a', fontSize: 36 },
startFormContainer: { paddingRight: 10, marginBottom: 10, marginTop: 40 },
redRoundedBtn: { borderRadius: 40, backgroundColor: '#f97070' },
startContainer: {
top: 120,
paddingHorizontal: 50,
},
startTitle: {
textAlign: 'center',
color: color.grey3,
fontSize: 36,
},
startFormContainer: {
paddingRight: 10,
marginBottom: 10,
marginTop: 40,
},
redRoundedBtn: {
borderRadius: 40,
backgroundColor: color.primary,
},
input: {
width: 300,
// borderBottomColor: '#cfd7db',
// borderBottomWidth: 1,
marginLeft: 5,
color: color.grey1,
marginTop: 30,
},
inputErr: { color: 'red', position: 'absolute', right: 5, bottom: 5, fontSize: 20 },
inputContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'flex-end',
borderBottomColor: '#cfd7db',
borderBottomWidth: 1,
},
});
......@@ -5,8 +5,11 @@ import store from '../store';
import PageOne from '../screens/private/PageOne';
import PageTwo from '../screens/private/PageTwo';
import LoginPage from '../screens/public/LoginPage';
import LoginPage from '../screens/public/login';
import HomePage from '../screens/private/HomePage';
import Register from '../screens/public/register';
import ForgotPass from '../screens/public/forgotPassword';
import SendEmail from '../screens/public/sendEmail';
class AppRouterComponent extends Component {
render() {
......@@ -14,10 +17,13 @@ class AppRouterComponent extends Component {
<Provider store={store}>
<Router>
<Scene key="root" hideNavBar>
<Scene key="HomePage" component={HomePage} initial={true} />
<Scene key="HomePage" component={HomePage} />
<Scene key="PageOne" component={PageOne} />
<Scene key="PageTwo" component={PageTwo} />
<Scene key="LoginPage" component={LoginPage} />
<Scene key="LoginPage" component={LoginPage} initial={true} />
<Scene key="Register" component={Register} />
<Scene key="ForgotPass" component={ForgotPass} />
<Scene key="SendEmail" component={SendEmail} />
</Scene>
</Router>
</Provider>
......
import React, { Component } from 'react';
import { Container, Text, Content, Input, View, Form, Item, Button } from 'native-base';
import { theme } from '../../constants/Styles';
import { Actions } from 'react-native-router-flux';
export default class forgotPassword extends Component {
render() {
return (
......@@ -19,7 +20,13 @@ export default class forgotPassword extends Component {
</Item>
</Form>
<Button full style={[theme.redRoundedBtn, { marginTop: 75 }]}>
<Button
full
style={[theme.redRoundedBtn, { marginTop: 75 }]}
onPress={() => {
Actions.SendEmail();
}}
>
<Text>SEND</Text>
</Button>
</Content>
......
import React, { Component } from 'react';
import { Container, Text, Content, Input, Radio, Form, Item, Left, Right, Button, Row } from 'native-base';
import { theme } from '../../constants/Styles';
import { Actions } from 'react-native-router-flux';
export default class login extends Component {
constructor(props) {
super(props);
......@@ -47,14 +48,35 @@ export default class login extends Component {
</Row>
</Left>
<Right>
<Text style={{ color: '#cacaca' }}>Forgot password?</Text>
<Text
style={{ color: '#cacaca' }}
onPress={() => {
Actions.ForgotPass();
}}
>
Forgot password?
</Text>
</Right>
</Row>
<Button full style={[theme.redRoundedBtn, { marginTop: 75 }]}>
<Button
full
style={[theme.redRoundedBtn, { marginTop: 75 }]}
onPress={() => {
Actions.HomePage();
}}
>
<Text>LOGIN</Text>
</Button>
<Text style={{ color: '#4a4a4a', textAlign: 'center', marginTop: 20 }}>
Don't have an account? <Text style={{ color: '#f44c4c', fontWeight: 'bold' }}>Register</Text>
Don't have an account?{' '}
<Text
style={{ color: '#f44c4c', fontWeight: 'bold' }}
onPress={() => {
Actions.Register();
}}
>
Register
</Text>
</Text>
</Content>
</Container>
......
import React, { Component } from 'react';
import { Container, Text, Content, Input, Form, Item, Left, Button, Row, CheckBox } from 'native-base';
import { Container, Text, Content, Left, Button, Row, CheckBox } from 'native-base';
import { theme } from '../../constants/Styles';
import { Form, Field } from 'react-native-validate-form';
import InputField from '../../components/layout/InputField';
// validatioms
const required = value => (value ? undefined : 'This is a required field.');
const email = value =>
value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,5}$/i.test(value)
? 'Please provide a valid email address.'
: undefined;
const phoneNum = value => (value && !/^[0][689][0-9]{8}$/i.test(value) ? 'Invalid number' : undefined);
const cfPassword = value => (value && value == this.password ? 'Password not match' : undefined); //how??
export default class register extends Component {
constructor(props) {
super(props);
this.state = {
errors: [],
isCheck: false,
name: '',
surName: '',
email: '',
password: '',
cfPassword: '',
phoneNum: '',
};
}
submitForm() {
let submitResults = this.registerForm.validate();
let errors = [];
submitResults.forEach(item => {
errors.push({ field: item.fieldName, error: item.error });
});
this.setState({ errors: errors });
}
submitSuccess() {
console.log('Submit Success!');
}
submitFailed() {
console.log('Submit Failed!');
}
render() {
const InputText = props => {
return (
<Item>
<Input
placeholder={props.placeholder}
secureTextEntry={props.isPass}
placeholderTextColor={'#cacaca'}
style={{ color: '#808080' }}
/>
</Item>
);
};
return (
<Container>
<Content style={theme.startContainer}>
<Text style={theme.startTitle}>Register</Text>
<Form style={theme.startFormContainer}>
<InputText placeholder={'Name'} />
<InputText placeholder={'Surname'} />
<InputText placeholder={'E-mail'} />
<InputText placeholder={'Password'} isPass={true} />
<InputText placeholder={'Confirm password'} isPass={true} />
<InputText placeholder={'Phone number'} />
<Form
ref={ref => (this.registerForm = ref)}
validate={true}
submit={this.submitSuccess.bind(this)}
failed={this.submitFailed.bind(this)}
errors={this.state.errors}
style={theme.startFormContainer}
>
{/* ---name--- */}
<Field
required
component={InputField}
validations={[required]}
name="name"
value={this.state.name}
onChangeText={val => this.setState({ name: val })}
customStyle={[theme.input, { marginTop: 0 }]}
placeholder="Name"
/>
{/* ---surName--- */}
<Field
required
component={InputField}
validations={[required]}
name="surName"
value={this.state.surName}
onChangeText={val => this.setState({ surName: val })}
customStyle={theme.input}
placeholder="Surname"
/>
{/* ---email--- */}
<Field
required
component={InputField}
validations={[required, email]}
name="email"
value={this.state.email}
onChangeText={val => this.setState({ email: val })}
customStyle={theme.input}
placeholder="E-mail"
/>
{/* ---password--- */}
<Field
required
component={InputField}
validations={[required]}
name="password"
value={this.state.password}
onChangeText={val => this.setState({ password: val })}
customStyle={theme.input}
placeholder="Password"
isPass={true}
/>
{/* ---cf password--- */}
<Field
required
component={InputField}
validations={[required, cfPassword]}
name="cfPassword"
value={this.state.cfPassword}
onChangeText={val => this.setState({ cfPassword: val })}
customStyle={theme.input}
placeholder="Confirm password"
isPass={true}
/>
{/* ---phone no--- */}
<Field
required
component={InputField}
validations={[required, phoneNum]}
name="phoneNum"
value={this.state.phoneNum}
onChangeText={val => this.setState({ phoneNum: val })}
customStyle={theme.input}
placeholder="Phone number"
/>
</Form>
<Row style={{ marginTop: 30 }}>
<Left>
......@@ -55,7 +150,7 @@ export default class register extends Component {
</Row>
</Left>
</Row>
<Button full style={{ marginTop: 50, borderRadius: 40, backgroundColor: '#f97070' }}>
<Button full style={[theme.redRoundedBtn, { marginTop: 50 }]} onPress={this.submitForm.bind(this)}>
<Text>CONTINUE</Text>
</Button>
</Content>
......
......@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { Container, Text, Content, View, Button } from 'native-base';
import { Image } from 'react-native';
import { theme } from '../../constants/Styles';
import { Actions } from 'react-native-router-flux';
export default class sendEmail extends Component {
render() {
return (
......@@ -20,7 +21,13 @@ export default class sendEmail extends Component {
We sent an email with instructions for resetting your password.
</Text>
</View>
<Button full style={[theme.redRoundedBtn, { marginTop: 60 }]}>
<Button
full
style={[theme.redRoundedBtn, { marginTop: 60 }]}
onPress={() => {
Actions.LoginPage();
}}
>
<Text>DONE</Text>
</Button>
<Button transparent style={{ marginTop: 40, alignSelf: 'center' }}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment