import React, { Component } from 'react'; import { connect } from 'react-redux'; import { AppRegistry, StyleSheet, TextInput, View, Alert, Button, Text, AsyncStorage, Image, TouchableOpacity, ActivityIndicator, KeyboardAvoidingView } from 'react-native'; import axios from 'axios'; import Ionicons from 'react-native-vector-icons/Ionicons'; import Setting from '../../Setting'; class LoginScreen extends Component { constructor(props) { super(props) this.state = { username: '', password: '', isLoading: false } this.root = this.props.component.root; //save token //this.root.saveToken('asdasd'); //ambil token //this.root.state.token } UserLoginFunction = (username,password) => { // const { username } = this.state; // const { password } = this.state; this.setState({ isLoading: true }); axios({ method: 'get', url: Setting.baseUrl + '/auth/login', params: { email: username, password: password, } }).then((response) => { const token = response.data.data.token; if (token != '') { let str = token; this.root.saveToken(str) } else { Alert.alert(response); } this.setState({ isLoading: false }); }).catch((error) => { alert("Username / Password salah !"); this.setState({ isLoading: false }); }); } render() { return ( {/* gambar backgroundColor */} {/* gambar logo */} {/* username */} this.setState({ username })} underlineColorAndroid='transparent' style={styles.Textform} /> {/* end of username */} {/* password */} this.setState({ username })} underlineColorAndroid='transparent' style={styles.Textform} secureTextEntry={true} /> {/* end of passsword */} {this.state.isLoading == true && ( )} {this.state.isLoading == false && ( {this.UserLoginFunction(this.state.username,this.state.password)}}> Login )} {this.state.isLoading == false && ( { this.props.component.root.navigate('Register', { }); }}> Register )} {/* end of parent */} dengan masuk berarti anda sudah menyetujui syarat dan ketentuan kami ); } } const styles = StyleSheet.create({ container: { alignItems: "center" }, TextInputStyleClass:{ flex:1, fontSize:20, color:'#FFF', textAlign:'center', justifyContent:'center', marginTop:10, // alignItems:'center', }, Textform:{ flex:1, fontSize:17, color:'#F2526E', marginLeft:20 }, button:{ backgroundColor:'#F2526E', borderColor:'#F2526E', borderRadius:5, width:270, height:50, marginBottom:15, }, buttonRegister:{ backgroundColor:'#2ECC71', borderColor:'#2ECC71', borderRadius:5, width:270, height:50, marginBottom:15 }, }); function mapStateToProps(state) { return { component: state.component, } } function mapDispatchToProps(dispatch) { return { setRoot: (root) => dispatch({ type: 'set_root', root: root }) } } export default connect( mapStateToProps, mapDispatchToProps )(LoginScreen);