Guest User

Untitled

a guest
Apr 26th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import { Text, View, TouchableOpacity, Dimensions, ImageBackground, Image, Alert } from "react-native";
  3. import { Icon, Content, Button } from "native-base";
  4. import { TextField } from 'react-native-material-textfield';
  5. import IconVector from 'react-native-vector-icons/FontAwesome';
  6.  
  7. import * as Http from '../../Helpers/Http';
  8. import lang from '../../Helpers/Language';
  9. const height = Dimensions.get("window").height;
  10. const width = Dimensions.get("window").width;
  11.  
  12. export default class Register extends Component {
  13.   static navigationOptions = {
  14.     title: '',
  15.     header: null
  16.   };
  17.  
  18.   constructor(props) {
  19.     super(props);
  20.     this.state = {
  21.       email: '',
  22.       phone:'',
  23.       password: '',
  24.       repassword:'',
  25.       secureTextEntry: true,
  26.       loginMode: 'email',
  27.       countryCode:'+62'
  28.     }
  29.     this._passwordAccessory = this._passwordAccessory.bind(this);
  30.   }
  31.  
  32.   registerValidation(){
  33.     // if(this.state.UserName == ''){
  34.     //   return Alert.alert("Please Fill the User Name Field.");
  35.     // }else if(this.state.UserName.length < 8){
  36.     //   return Alert.alert("User Name Field Must Contain at Least 8 Character.")
  37.     // }
  38.  
  39.     // if(this.state.UserFullName == ''){
  40.     //   return Alert.alert("Please Fill the Full Name Field.");
  41.     // }else if(this.state.UserFullName.length < 8){
  42.     //   return Alert.alert("Full Name Field Must Contain at Least 8 Character.")
  43.     // }
  44.  
  45.     let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ;
  46.     if(this.state.email == ''){
  47.       Alert.alert('Please Fill the Email Field');
  48.       return false;
  49.     }else if(reg.test(this.state.email) === false)
  50.     {
  51.       Alert.alert("Email Format not Correct");
  52.       return false;
  53.     }
  54.  
  55.     if(this.state.password != this.state.repassword){
  56.       Alert.alert('Password not Match');
  57.       return false;
  58.     }else if(this.state.password.length < 8 ){
  59.       Alert.alert('Password Field Must Contain at Least 8 Character');
  60.       return false;
  61.     }
  62.  
  63.     if(this.state.phone == ''){
  64.       Alert.alert('Please Fill the Phone Number Field');
  65.       return false;
  66.     }
  67.  
  68.     return true;
  69.   }
  70.  
  71.   registerUser() {
  72.  
  73.     let status_validation = this.registerValidation();
  74.  
  75.     // Example to use Http Helper
  76.     let reqParams = {
  77.       link: 'register',
  78.       method: 'POST',
  79.       show_error_alert: true,
  80.       body: {
  81.         "name":this.state.email,
  82.         "email":this.state.email,
  83.         "displayName":this.state.email,
  84.         "phone":this.state.phone,
  85.         "password":this.state.password,
  86.         "login_type":"none",
  87.         "countryCode":this.state.countryCode,
  88.         "role":1
  89.       }
  90.     }
  91.  
  92.     if(status_validation == true){
  93.       Http.createRequest(reqParams).then((resp) => {
  94.         this._resetForm();
  95.         if(resp.message == '1007'){
  96.           Alert.alert(lang('api_response_success.1007'));
  97.           return;
  98.         }
  99.  
  100.         if(resp.message == '1008'){
  101.           Alert.alert(
  102.             'Notification',
  103.             lang('api_response_success.1008'),
  104.             [
  105.               {text: 'Ok', onPress: () => this.props.navigation.navigate('homeScreen')},
  106.             ],
  107.             { cancelable: false }
  108.           )
  109.  
  110.         }
  111.  
  112.       }).catch((err) => console.log("Respon API Error", err.message));
  113.     }
  114.   }
  115.  
  116.   _passwordAccessory() {
  117.     return(
  118.       <IconVector
  119.         name={ this.state.secureTextEntry ? 'eye' : 'eye-slash'}
  120.         size={20}
  121.         color='red'
  122.         onPress={() => {
  123.           this.setState((previousState) => ({ secureTextEntry: !previousState.secureTextEntry }))
  124.         }}
  125.       />
  126.     );
  127.   }
  128.  
  129.   _resetForm() {
  130.     this.setState({
  131.       email: '',
  132.       phone:'',
  133.       password: '',
  134.       repassword:'',
  135.       secureTextEntry: true,
  136.       loginMode: 'email',
  137.       countryCode:'+62'
  138.     });
  139.   }
  140.  
  141.   render() {
  142.     return (
  143.       <View style={{ flex: 1 }}>
  144.         <ImageBackground source={require('../../Assets/authBackG.jpg')} style={{ width: width, height: height }} >
  145.           <View style={{ flexDirection: 'row', justifyContent: 'space-between', margin: 10 }} >
  146.             <TouchableOpacity onPress={() => this.props.navigation.goBack()} style={{ justifyContent: 'center', alignItems: 'center', height: 50, width: 50, backgroundColor:'transparent' }}>
  147.               <Icon name='md-arrow-back' style={{ color: 'white', fontSize: 25 }} />
  148.             </TouchableOpacity>
  149.             <Text style={{ color: 'white', fontSize: 16, marginTop: 20, backgroundColor:'transparent', fontFamily: 'Nunito-Bold' }} >SIGN UP</Text>
  150.             <View style={{ width: 50 }} />
  151.           </View>
  152.           <Content style={{ paddingHorizontal: 40 }} >
  153.             <TextField
  154.               label='EMAIL'
  155.               baseColor='white'
  156.               tintColor='red'
  157.               textColor='white'
  158.               value={this.state.email}
  159.               onChangeText={(email) => this.setState({ email })}
  160.             />
  161.             <View style={{flexDirection:'row', flex:1}}>
  162.  
  163.               <TextField
  164.                 containerStyle={{flex:0.15}}
  165.                 // style={{flex:0.8}}
  166.                 // label='NO. HP'
  167.                 baseColor='white'
  168.                 tintColor='red'
  169.                 textColor='white'
  170.                 keyboardType = 'numeric'
  171.                 value={this.state.countryCode}
  172.                 onChangeText={(countryCode) => this.setState({ countryCode })}
  173.               />
  174.               <View style={{flex:0.05}}>
  175.               </View>
  176.               <TextField
  177.                 containerStyle={{flex:0.8}}
  178.                 // style={{flex:0.8}}
  179.                 label='NO. HP'
  180.                 baseColor='white'
  181.                 tintColor='red'
  182.                 textColor='white'
  183.                 keyboardType = 'numeric'
  184.                 value={this.state.phone}
  185.                 onChangeText={(phone) => this.setState({ phone })}
  186.               />
  187.             </View>
  188.             {/* <View style={{ flexDirection: 'row' }} > */}
  189.             <TextField
  190.               label='PASSWORD'
  191.               // inputContainerStyle={{ width: width * 3 / 4 - 20 }}
  192.               baseColor='white'
  193.               secureTextEntry={this.state.secureTextEntry}
  194.               tintColor='red'
  195.               textColor='white'
  196.               value={this.state.password}
  197.               onChangeText={(password) => this.setState({ password })}
  198.               renderAccessory={this._passwordAccessory}
  199.             />
  200.             {/* <TouchableOpacity onPress={() => this.toogleSecureTextEntry()} style={{ padding: 10, alignSelf: 'center' }} >
  201.                   <Icon name={this.state.secureTextEntry ? 'ios-eye-outline' : 'ios-eye-off-outline'} style={{ color: 'white' }} />
  202.                 </TouchableOpacity> */}
  203.             {/* </View> */}
  204.             {/* <View style={{ flexDirection: 'row' }} > */}
  205.             <TextField
  206.               label='ULANG PASSWORD'
  207.               // inputContainerStyle={{ width: width * 3 / 4 - 20 }}
  208.               baseColor='white'
  209.               secureTextEntry={this.state.secureTextEntry}
  210.               tintColor='red'
  211.               textColor='white'
  212.               value={this.state.repassword}
  213.               onChangeText={(repassword) => this.setState({ repassword })}
  214.             />
  215.             {/* <TouchableOpacity onPress={() => this.toogleSecureTextEntry()} style={{ padding: 10, alignSelf: 'center' }} >
  216.                   <Icon name={this.state.secureTextEntry ? 'ios-eye-outline' : 'ios-eye-off-outline'} style={{ color: 'white' }} />
  217.                 </TouchableOpacity> */}
  218.             {/* </View> */}
  219.  
  220.             <Button
  221.               onPress={()=>this.registerUser()}
  222.               block style={{ backgroundColor: 'red', marginTop: 30 }} >
  223.               <Text style={{ color: 'white', fontFamily: 'Nunito-Bold' }} >REGISTER</Text>
  224.             </Button>
  225.  
  226.             <Text on style={{ color: 'white', borderBottomColor: 'white', borderBottomWidth: 1, alignSelf: 'center', marginTop: 25, fontFamily: 'Nunito-Bold' }}> OR SIGN UP WITH </Text>
  227.  
  228.             {
  229.               //login with fb or g+
  230.             }
  231.             <View style={{ flexDirection: 'row', justifyContent: 'space-between', marginTop: 20 }} >
  232.               <TouchableOpacity
  233.                 onPress={()=>{}}
  234.                 style={styles.buttonStyleSoc}
  235.               >
  236.                 <Text style={styles.buttonTextStyleSoc}>
  237.                   <IconVector name="facebook" size={14} color="#3b5998" />
  238.                   &nbsp;&nbsp;Facebook
  239.                 </Text>
  240.               </TouchableOpacity>
  241.  
  242.               <TouchableOpacity
  243.                 onPress={()=>{}}
  244.                 style={styles.buttonStyleSoc}
  245.               >
  246.                 <Text style={styles.buttonTextStyleSoc}>
  247.                 <IconVector name="google-plus" size={14} color="#d34836" />
  248.                 &nbsp;&nbsp;Google
  249.                 </Text>
  250.               </TouchableOpacity>
  251.             </View>
  252.  
  253.             <Text on style={{ color: 'white', borderBottomColor: 'white', borderBottomWidth: 1, alignSelf: 'center', marginTop: 25, fontFamily: 'Nunito-Bold' }} onPress={() => this.props.navigation.goBack()} > Already have an account ? Login here </Text>
  254.  
  255.           </Content>
  256.         </ImageBackground>
  257.       </View>
  258.     );
  259.   }
  260. }
  261.  
  262. const styles = {
  263.  
  264.   buttonTextStyleSoc: {
  265.     color: 'black',
  266.     alignSelf: 'center',
  267.     paddingVertical: 15,
  268.     fontSize: 14,
  269.     fontFamily: 'Nunito-Bold'
  270.  
  271.   },
  272.   buttonStyleSoc: {
  273.     width: '48%',
  274.     backgroundColor: '#ffffff',
  275.     alignItems: 'center',
  276.     height: 50,
  277.     borderRadius: 5,
  278.     marginTop: 7
  279.   },
  280. }
Advertisement
Add Comment
Please, Sign In to add comment