Advertisement
Guest User

Untitled

a guest
May 17th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import {AsyncStorage, StatusBar, ToastAndroid, Keyboard} from 'react-native';
  3. import { Container, Header, Content, Form, Item, Input, Label,Button, Text, Title, Left, Body, Right, Icon,
  4.   Card, CardItem,} from 'native-base';
  5. import { NavigationActions } from "react-navigation";
  6. import Storage from 'react-native-storage';
  7. import axios from 'axios';
  8. import styles from './styles';
  9. // import Storage from 'react-native-storage';
  10.  
  11.     this.props.navigation.dispatch(NavigationActions.reset({
  12.       index: 0,
  13.       actions: [
  14.         NavigationActions.navigate({ routeName: 'HomeScreen' })
  15.       ]
  16.     }))
  17.  
  18. export default class Login extends Component {
  19.   constructor(props) {
  20.     super(props);
  21.     this.state = {        
  22.         email      : '',
  23.         password    : '',
  24.         isLoading : true,
  25.         token: '',
  26.         isLoggedIn: false    
  27.     };
  28.       this.LoginUser   = this.LoginUser.bind(this);
  29.  
  30.   }
  31.  
  32.  
  33. //for login\\\
  34.  LoginUser = () =>{
  35.     //   this.setState({
  36.     //   isLoading: true
  37.     // })
  38.   // console.log(id);
  39.     if (this.state.email == "") {
  40.       ToastAndroid.show('nama Tidak Boleh Kosong', ToastAndroid.SHORT)
  41.     } else if (this.state.password == "") {
  42.       ToastAndroid.show('Password Tidak Boleh Kosong', ToastAndroid.SHORT)
  43.     } else {
  44.       this.setState({
  45.         isLoading: false
  46.       })
  47.       axios({
  48.         method: 'POST',
  49.         url:    'api',
  50.         data:   {
  51.           email     : this.state.email,
  52.           password  : this.state.password
  53.         },
  54.       })
  55.           .then(response => {
  56.        if (response == 'Try Again') {
  57.                     ToastAndroid.show('Try Again, the input is empty', ToastAndroid.SHORT)
  58.                 } else {
  59.                     ToastAndroid.show('sukses', ToastAndroid.SHORT)
  60.               this.props.navigation.dispatch(resetAction)
  61.     // this.props.navigation.dispatch(goHome)
  62.                     // console.log(navigateAction)
  63.                 }
  64.             })
  65.             .catch((error) => {
  66.                 console.error(error);
  67.             });
  68.         Keyboard.dismiss()
  69.     }
  70.   }
  71.  
  72.  
  73.          // console.log(response.data);
  74.          // alert('gagal')
  75.         // this.storeToAsyncStorage(response.data);
  76.   render() {
  77.     // const { navigate } = this.props.navigation;
  78.     return (
  79.       <Container>
  80.         <Header style={styles.header}>
  81.           <StatusBar
  82.             backgroundColor="#e60000"
  83.             barStyle="light-content"
  84.             />
  85.           <Left />
  86.             {/*<Button transparent>
  87.               <Icon name='menu' />
  88.             </Button>
  89.           </Left>*/}
  90.           <Body>
  91.             <Title>Header</Title>
  92.           </Body>
  93.           <Right />
  94.         </Header>
  95.         <Content style={styles.content} >
  96.           <Content style={styles.login}>
  97.             <Form>
  98.               <Item floatingLabel last style={styles.Lname}>
  99.                 <Label style={styles.name}>User name</Label>
  100.                 <Input
  101.                   onChangeText= {email => this.setState({email})}
  102.                   returnKeyType="next"
  103.                 />
  104.               </Item>
  105.               <Item floatingLabel last style={styles.Lpassword}>
  106.                 <Label style={styles.password}>Password</Label>
  107.                 <Input
  108.                   onChangeText= {password => this.setState({password})}
  109.                   autoCorrect={false}  
  110.                   returnKeyType="go"
  111.                   // ref={(input)=> this.passwordInput = input}
  112.                   secureTextEntry
  113.               />
  114.               </Item>
  115.             </Form>
  116.               <Button block style={styles.button}
  117.                 onPress={this.LoginUser}
  118.               >
  119.                 <Text>Login</Text>
  120.               </Button>
  121.             {/*
  122.  <Button style={styles.Ltext}>
  123.                  <Text style={{color: '#000000'}} >atau</Text>
  124.                 </Button>
  125.               <Button iconLeft block style={styles.fb}>
  126.                 <Icon name='logo-facebook' />
  127.                   <Text>Login With Facebook</Text>
  128.               </Button>
  129.               <Button iconLeft block transparent danger style={styles.google}>
  130.                     <Icon name='logo-googleplus' />
  131.                       <Text>Login With Google</Text>
  132.               </Button>
  133.             */}
  134.              
  135.           </Content>
  136.         </Content>
  137.       </Container>
  138.     );
  139.   }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement