Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react'
- import {
- View,
- Text,
- AppRegistry,
- Image,
- StyleSheet,
- TextInput,
- TouchableOpacity,
- Dimensions,
- KeyboardAvoidingView,
- StatusBar,
- Platform,
- AsyncStorage
- }
- from 'react-native';
- const background = require('../../../img/OTP-bg.png');
- const backBtn = require('../../../img/back.png');
- const { width, height } = Dimensions.get("window");
- export default class Otp extends Component {
- constructor(props) {
- super(props)
- this.ResendOTP = this.ResendOTP.bind(this);
- this.state = {
- }
- }
- onTapBack(){
- this.props.navigator.dismissModal({
- animated: true // does the pop have transition animation or does it happen immediately (optional)
- });
- }
- render(){
- return(
- <Image source={background} style={styles.backgroundImage}>
- <StatusBar backgroundColor="#078f99" barStyle="light-content" />
- <View style={{marginTop:20, padding: 10}}>
- <TouchableOpacity style={{width:20, height:20}} onPress ={()=> this.onTapBack()}>
- <Image source={backBtn} style={{resizeMode:'contain', width:20, height:20}}/>
- </TouchableOpacity>
- </View>
- <View style = {{flexDirection : 'row',padding: 10,width:width, marginTop:20}}>
- <Text style={{flex:1, textAlign: 'center', color: '#ffffff', backgroundColor:'transparent', fontSize:25, fontFamily: 'Lato-Regular'}}>Verification Code</Text>
- </View>
- <View style={{width:width, flexDirection : 'row', marginTop:20, alignItems: 'center', paddingLeft:20, paddingRight:20, justifyContent: 'center'}}>
- <TextInput style={{height:40, width:40, backgroundColor:'rgba(255,255,255,0.4)', marginRight:8, padding:10, textAlign: 'center', color:'#fff', fontWeight:'700'}}
- maxLength = {1}
- keyboardType = "numeric"
- autoFocus = {true}
- ref= {(input)=> this.Number1Input= input }
- maxLength = {1}
- onChangeText = {(number1) => this.Next1(number1)}
- value={this.state.Number1}
- autoCorrect = {false}
- returnKeyType = 'next'
- onSubmitEditing = {() =>this.Number2Input.focus()}
- underlineColorAndroid = "transparent"/>
- <TextInput style={{height:40, width:40, backgroundColor:'rgba(255,255,255,0.4)', marginRight:8, padding:10, textAlign: 'center', color:'#fff', fontWeight:'700'}}
- maxLength = {1}
- keyboardType = "numeric"
- underlineColorAndroid = "transparent"
- ref= {(input)=> this.Number2Input= input }
- maxLength = {1}
- onChangeText = {(number2) => this.Next2(number2) }
- value={this.state.Number2}
- autoCorrect = {false}
- returnKeyType = 'next'
- onSubmitEditing = {() =>this.Number3Input.focus()}
- />
- <TextInput style={{height:40, width:40, backgroundColor:'rgba(255,255,255,0.4)', marginRight:8, padding:10, textAlign: 'center', color:'#fff', fontWeight:'700'}}
- maxLength = {1}
- keyboardType = "numeric"
- underlineColorAndroid = "transparent"
- ref= {(input)=> this.Number3Input= input }
- maxLength = {1}
- onChangeText = {(number3) => this.Next3(number3)}
- value={this.state.Number3}
- autoCorrect = {false}
- returnKeyType = 'next'
- onSubmitEditing = {() =>this.Number4Input.focus()}
- />
- <TextInput style={{height:40, width:40, backgroundColor:'rgba(255,255,255,0.4)', marginRight:8, padding:10, textAlign: 'center', color:'#fff', fontWeight:'700'}}
- maxLength = {1}
- keyboardType = "numeric"
- underlineColorAndroid = "transparent"
- ref= {(input)=> this.Number4Input= input }
- maxLength = {1}
- onChangeText = {(number4) => this.Next4(number4)}
- value={this.state.Number4}
- autoCorrect = {false}
- returnKeyType = 'next'
- onSubmitEditing = {() =>this.Number5Input.focus()}
- />
- <TextInput style={{height:40, width:40, backgroundColor:'rgba(255,255,255,0.4)', marginRight:8, padding:10, textAlign: 'center', color:'#fff', fontWeight:'700'}}
- maxLength = {1}
- keyboardType = "numeric"
- underlineColorAndroid = "transparent"
- ref= {(input)=> this.Number5Input= input }
- maxLength = {1}
- onChangeText = {(number5) => this.Next5(number5)}
- value={this.state.Number5}
- autoCorrect = {false}
- returnKeyType = 'next'
- onSubmitEditing = {() =>this.Number6Input.focus()}
- />
- <TextInput style={{height:40, width:40, backgroundColor:'rgba(255,255,255,0.4)', marginRight:8, padding:10, textAlign: 'center', color:'#fff', fontWeight:'700'}}
- maxLength = {1}
- keyboardType = "numeric"
- underlineColorAndroid = "transparent"
- ref= {(input)=> this.Number6Input= input }
- maxLength = {1}
- onChangeText = {(number6) => this.Next6(number6)}
- value={this.state.number6}
- autoCorrect = {false}
- returnKeyType = 'done'
- />
- </View>
- <TouchableOpacity onPress= {() => this.ClearAll()} style = {{flexDirection : 'row',paddingLeft:60, paddingRight:60,width:width, marginTop:20,justifyContent :'center',alignItems:'center'}}>
- <Text style={{flex:1, textAlign: 'center', color: 'rgba(255,255,255,0.8)', backgroundColor:'transparent', fontSize:15, fontFamily: 'Lato-Light'}}>Clear all</Text>
- </TouchableOpacity>
- <View style = {{flexDirection : 'row',paddingLeft:60, paddingRight:60,width:width, marginTop:10}}>
- <Text style={{flex:1, textAlign: 'center', color: 'rgba(255,255,255,0.8)', backgroundColor:'transparent', fontSize:15, fontFamily: 'Lato-Light'}}>Please enter your verification code sent to {this.props.number}</Text>
- </View>
- <TouchableOpacity onPress ={()=> this.ResendOTP()} style = {{flexDirection : 'row',padding: 10,width:width, justifyContent: 'center', marginTop:10}}>
- <View style={{borderBottomWidth:2, borderColor:'rgba(255,255,255,0.4)'}}><Text style={{textAlign: 'center', color: 'rgba(255,255,255,0.8)', backgroundColor:'transparent', fontSize:15, fontFamily: 'Lato-Light'}}>Resend the verification code?</Text></View>
- </TouchableOpacity>
- </Image>
- );
- }
- ClearAll(){
- this.setState({
- Number1 : false,
- Number2 : false,
- Number3 : false,
- Number4 : false,
- Number5 : false,
- number6 : false,
- });
- this.Number1Input.focus()
- }
- Next1(number1){
- if(number1 == undefined){
- this.setState({Number1 : false});
- }else {
- this.setState({Number1 : number1});
- this.Number2Input.focus()
- }
- }
- Next2(number2){
- if(number2 == undefined){
- this.setState({Number2 : false});
- }else {
- this.setState({Number2 : number2});
- this.Number3Input.focus()
- }
- }
- Next3(number3){
- if(number3 == undefined){
- this.setState({Number3 : false});
- }else {
- this.setState({Number3 : number3});
- this.Number4Input.focus()
- }
- }
- Next4(number4){
- if(number4 == undefined){
- this.setState({Number4 : false});
- }else {
- this.setState({Number4 : number4});
- this.Number5Input.focus()
- }
- }
- Next5(number5){
- if(number5 == undefined){
- this.setState({Number5 : false});
- }else {
- this.setState({Number5 : number5});
- this.Number6Input.focus()
- }
- }
- Next6(number6){
- if(number6 == undefined){
- this.setState({Number6 : false});
- }else {
- this.setState({number6 : number6});
- if(this.state.Number1 === false || this.state.Number2 === false || this.state.Number2Number3 === false || this.state.Number4 === false || this.state.Number5 === false ){
- alert('Please fill all the digits to submit !');
- }else{
- let num1 = this.state.Number1;
- let num2 = this.state.Number2;
- let num3 = this.state.Number3;
- let num4 = this.state.Number4;
- let num5 = this.state.Number5;
- let num6 = number6;
- let otp = num1 + num2 + num3 + num4 + num5 + num6 ;
- fetch('http://api.yohobed.com/api/otp',{
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- verification_code : otp,
- mobile: this.props.number,
- })
- }).then( response => response.json())
- .then( jsonData => {
- console.log('json test',jsonData);
- if(jsonData.success === true){
- AsyncStorage.setItem('@isLogged:key', 'Logged');
- AsyncStorage.setItem('@customer_name:key', this.props.Customer);
- AsyncStorage.setItem('@customer_id:key', jsonData.customer_id.toString());
- AsyncStorage.setItem('@device_type:key', this.props.deviceType);
- AsyncStorage.setItem('@mobile:key', this.props.number);
- AsyncStorage.setItem('@email:key', this.props.email);
- // alert(jsonData.success);
- //sessionsave <---- get JsonData.customer_id && jsonData.customer_name for session
- this.props.navigator.showModal({
- screen: "yohobed.LandingTabViewController",
- navigatorStyle: { navBarHidden: true}
- });
- }else {
- alert('OTP does not match or try sending otp again ?');
- this.ClearAll();
- }
- }).catch( error => alert('Error fetching: ' + error) );
- }
- }
- }
- ResendOTP(){
- fetch('http://api.yohobed.com/api/again_otp',{
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- mobile: this.props.number,
- })
- }).then( response => response.json())
- .then( jsonData => {
- if(jsonData.success === true){
- //sessionsave <---- get JsonData.customer_id && jsonData.customer_name for session
- }else {
- //Error View
- }
- }).catch( error => alert('Error fetching: ' + error) );
- }
- }
- const styles = StyleSheet.create({
- backgroundImage: {
- flex: 1,
- resizeMode: 'cover',
- },
- input: {
- paddingLeft: 10,
- width: 40,
- height: 40,
- textAlign: 'center'
- },
- formContainer: {
- flex : 4,
- flexDirection: 'row',
- width: width,
- justifyContent : 'center'
- },
- verification : {
- alignItems : 'center'
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement