Commit 009bc5a8 by Giang Tran

connect api

parent 15e98723
...@@ -5,6 +5,5 @@ ...@@ -5,6 +5,5 @@
import {AppRegistry} from 'react-native'; import {AppRegistry} from 'react-native';
import App from './App'; import App from './App';
import {name as appName} from './app.json'; import {name as appName} from './app.json';
import Payment from './src/Screens/Payment/Payment';
AppRegistry.registerComponent(appName, () => Payment); AppRegistry.registerComponent(appName, () => App);
...@@ -15,33 +15,53 @@ import R from '../../assets/R'; ...@@ -15,33 +15,53 @@ import R from '../../assets/R';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {TABNAVIGATOR, FORGOTPASSWORD} from '../../routers/ScreenNames'; import {TABNAVIGATOR, FORGOTPASSWORD} from '../../routers/ScreenNames';
import {checkFormatArray} from '../../Config/Functions'; import {checkFormatArray} from '../../Config/Functions';
import {loginApi} from '../../apis/Functions/users';
import KEY from '../../assets/AsynStorage';
import AsyncStorage from '@react-native-community/async-storage';
import {showLoading, hideLoading} from '../../actions/loadingAction';
import {saveUserToRedux} from '../../actions/users';
import {connect} from 'react-redux';
const Login = (props) => { const Login = (props) => {
const {navigation} = props; const {navigation} = props;
const [email, setEmail] = useState(''); const [email, setEmail] = useState('Tdgiang@dcv.vn');
const [pass, setPass] = useState(''); const [pass, setPass] = useState('123456');
const navigate = useNavigation(); const navigate = useNavigation();
const onSubmitLogin = () => { const onSubmitLogin = async () => {
navigate.reset({ props.showLoading();
index: 1, const titles = ['tên đăng nhập', 'mật khẩu'];
routes: [{name: TABNAVIGATOR}], const index = checkFormatArray([email, pass]);
});
// const titles = ['tên đăng nhập', 'mật khẩu'];
// const index = checkFormatArray([email, pass]);
// console.log(index);
// if (index === true) { if (index === true) {
// console.log('OK'); console.log('OK');
// navigate.reset({ const firebase = await AsyncStorage.getItem(KEY.FIREBASE);
// index: 1,
// routes: [{name: TABNAVIGATOR}], const res = await loginApi({
// }); email,
// } else { password: pass,
// Alert.alert('Thông báo!', 'Vui lòng điền ' + titles[index]); platform: Platform.OS,
// } device_token: firebase,
account_type: 'CUSTOMER',
});
console.log(res.data);
props.hideLoading();
if (res.data.code == 200 && res.data.data) {
AsyncStorage.setItem(KEY.TOKEN, res.data.data.token);
props.saveUserToRedux(res.data.data);
navigate.reset({
index: 1,
routes: [{name: TABNAVIGATOR}],
});
} else {
Alert.alert('Thông báo!', res.data.message);
}
} else {
Alert.alert('Thông báo!', 'Vui lòng điền ' + titles[index]);
}
}; };
return ( return (
...@@ -134,4 +154,11 @@ const styles = StyleSheet.create({ ...@@ -134,4 +154,11 @@ const styles = StyleSheet.create({
}, },
}); });
export default Login; const mapStateToProps = (state) => {
return {};
};
export default connect(mapStateToProps, {
showLoading,
hideLoading,
saveUserToRedux,
})(Login);
import React, {useState} from 'react'; import React, {useState} from 'react';
import {View, Text, StyleSheet, Image, TouchableOpacity} from 'react-native'; import {
View,
Text,
StyleSheet,
Image,
TouchableOpacity,
Alert,
} from 'react-native';
import InputIcon from '../../components/Input/InputIcon'; import InputIcon from '../../components/Input/InputIcon';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions'; import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import {useForm, Controller} from 'react-hook-form'; import {checkFormatArray} from '../../Config/Functions';
import {showLoading, hideLoading} from '../../actions/loadingAction';
import {connect} from 'react-redux';
import {registorApi} from '../../apis/Functions/users';
const Registor = (props) => { const Registor = (props) => {
const {navigation} = props; const {navigation} = props;
const {control, handleSubmit, errors} = useForm();
const onSubmit = (data) => console.log(data); const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [password_confirmation, setPasswordConfirm] = useState('');
const registorClick = async () => {
props.showLoading();
const titles = ['email', 'mật khẩu', 'xác nhận mật khẩu'];
const index = checkFormatArray([email, password, password_confirmation]);
if (index === true) {
const res = await registorApi({
email,
password,
platform: Platform.OS,
password_confirmation,
});
if (res.data.code == 200 && res.data.data) {
Alert.alert('Đăng ký tài khoản thành công!');
navigation.navigate('LOGIN');
} else {
Alert.alert('Thông báo!', res.data.message);
}
} else {
Alert.alert('Thông báo!', 'Vui lòng điền ' + titles[index]);
}
props.hideLoading();
};
return ( return (
<View <View
...@@ -29,11 +65,15 @@ const Registor = (props) => { ...@@ -29,11 +65,15 @@ const Registor = (props) => {
icon={R.images.iconLock} icon={R.images.iconLock}
title={'Mật khẩu'} title={'Mật khẩu'}
placeholder={'Nhập mật khẩu'} placeholder={'Nhập mật khẩu'}
onChangeText={(val) => setPassword(val)}
isPassWord={true}
/> />
<InputIcon <InputIcon
icon={R.images.iconLock} icon={R.images.iconLock}
title={'Nhập lại mật khẩu'} title={'Nhập lại mật khẩu'}
placeholder={'Nhập mật khẩu'} placeholder={'Nhập mật khẩu'}
onChangeText={(val) => setPasswordConfirm(val)}
isPassWord={true}
/> />
<View <View
...@@ -42,10 +82,10 @@ const Registor = (props) => { ...@@ -42,10 +82,10 @@ const Registor = (props) => {
alignItems: 'center', alignItems: 'center',
}}> }}>
<View style={styles.wrapLogin}> <TouchableOpacity onPress={registorClick} style={styles.wrapLogin}>
<Text style={styles.txtLogin}>Đăng ký</Text> <Text style={styles.txtLogin}>Đăng ký</Text>
<Image source={R.images.iconRight1} style={styles.imgIcon} /> <Image source={R.images.iconRight1} style={styles.imgIcon} />
</View> </TouchableOpacity>
<View style={styles.row}> <View style={styles.row}>
<Text style={styles.txtTitle}>Bn đã có tài khon?</Text> <Text style={styles.txtTitle}>Bn đã có tài khon?</Text>
...@@ -99,4 +139,10 @@ const styles = StyleSheet.create({ ...@@ -99,4 +139,10 @@ const styles = StyleSheet.create({
}, },
}); });
export default Registor; const mapStateToProps = (state) => {
return {};
};
export default connect(mapStateToProps, {
showLoading,
hideLoading,
})(Registor);
import React from 'react'; import React from 'react';
import {connect} from 'react-redux';
import HomeView from './HomeView'; import HomeView from './HomeView';
const Home = props => { const Home = (props) => {
console.log('Information in home', props.user);
return <HomeView />; return <HomeView />;
}; };
export default Home; const mapStateToProps = (state) => {
return {
user: state.userReducer,
};
};
export default connect(mapStateToProps, {})(Home);
...@@ -7,6 +7,11 @@ export const loginApi = async (body) => ...@@ -7,6 +7,11 @@ export const loginApi = async (body) =>
.then((res) => res) .then((res) => res)
.catch((err) => err); .catch((err) => err);
export const registorApi = async (body) =>
PostLogin(url.urlRegistor, body)
.then((res) => res)
.catch((err) => err);
export const logoutApi = async (body) => export const logoutApi = async (body) =>
PostData('http://api.dcvinvest.com/api/auth/logout', body) PostData('http://api.dcvinvest.com/api/auth/logout', body)
.then((res) => res) .then((res) => res)
......
import {NetworkSetting} from '../config/Setting';
const root = 'http://api.dcvinvest.com/'; const root = 'http://api.dcvinvest.com/';
export default { export default {
urllogin: root + '/api/auth/customer-login', urllogin: root + '/api/auth/customer-login',
urlRegistor: root + 'api/auth/customer-register',
}; };
...@@ -4,7 +4,15 @@ import R from '../../assets/R'; ...@@ -4,7 +4,15 @@ import R from '../../assets/R';
import {WIDTHXD, HEIGHTXD, getFontXD} from '../../Config/Functions'; import {WIDTHXD, HEIGHTXD, getFontXD} from '../../Config/Functions';
const InputIcon = (props) => { const InputIcon = (props) => {
const {title, placeholder, icon, onChangeText, maxLength, isPassWord} = props; const {
title,
placeholder,
icon,
onChangeText,
maxLength,
isPassWord,
value,
} = props;
const {wrapLeft, wrapRight, container, iconImg, txtInput} = styles; const {wrapLeft, wrapRight, container, iconImg, txtInput} = styles;
return ( return (
<View style={container}> <View style={container}>
...@@ -18,6 +26,7 @@ const InputIcon = (props) => { ...@@ -18,6 +26,7 @@ const InputIcon = (props) => {
placeholderTextColor={R.colors.placeHolder} placeholderTextColor={R.colors.placeHolder}
placeholder={placeholder} placeholder={placeholder}
secureTextEntry={isPassWord} secureTextEntry={isPassWord}
value={value}
/> />
</View> </View>
</View> </View>
......
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