Commit c3631d0b by Nguyễn Thị Thúy

fix bug timeout

parent 20e8226c
...@@ -106,7 +106,8 @@ const Profile = (props) => { ...@@ -106,7 +106,8 @@ const Profile = (props) => {
const res = await verifyAccountApi(data); const res = await verifyAccountApi(data);
props.hideLoading(); props.hideLoading();
console.log(res); console.log(res);
if (res.data.code == 200) { if (res?.status == 200 && res.data) {
if(res.data.code == 200) {
setTimeout(() => { setTimeout(() => {
props.saveUserToRedux(res.data.data); props.saveUserToRedux(res.data.data);
Alert.alert(I18n.t('Notification'), res.data.message); Alert.alert(I18n.t('Notification'), res.data.message);
...@@ -118,6 +119,11 @@ const Profile = (props) => { ...@@ -118,6 +119,11 @@ const Profile = (props) => {
}, 500); }, 500);
} }
} else { } else {
setTimeout(() => {
Alert.alert(I18n.t('Notification'), 'upload fail');
}, 500);
}
} else {
Alert.alert( Alert.alert(
I18n.t('Notification'), I18n.t('Notification'),
I18n.t('Please_fill_in') + titles[index], I18n.t('Please_fill_in') + titles[index],
......
import KEY from '../assets/AsynStorage'; import KEY from '../assets/AsynStorage';
import axios from 'axios'; import axios from 'axios';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
axios.defaults.timeout = 10000; axios.defaults.timeout = 10000;
export async function GetData(url, data) { export async function GetData(url, data) {
const token = await AsyncStorage.getItem(KEY.TOKEN); const token = await AsyncStorage.getItem(KEY.TOKEN);
let myRequest = { let myRequest = {
...@@ -31,6 +33,7 @@ export async function GetData(url, data) { ...@@ -31,6 +33,7 @@ export async function GetData(url, data) {
return err; return err;
}); });
} }
export async function PostLogin(url, json) { export async function PostLogin(url, json) {
let myRequest = { let myRequest = {
method: 'post', method: 'post',
...@@ -86,6 +89,11 @@ export async function PostData(url, json, isAuth = true) { ...@@ -86,6 +89,11 @@ export async function PostData(url, json, isAuth = true) {
export async function PostFormData(url, data) { export async function PostFormData(url, data) {
const token = await AsyncStorage.getItem(KEY.TOKEN); const token = await AsyncStorage.getItem(KEY.TOKEN);
const source = axios.CancelToken.source();
const timeout = setTimeout(() => {
source.cancel();
// Timeout Logic
}, 1000);
console.log(token); console.log(token);
let myRequest = { let myRequest = {
method: 'post', method: 'post',
...@@ -95,15 +103,23 @@ export async function PostFormData(url, data) { ...@@ -95,15 +103,23 @@ export async function PostFormData(url, data) {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
Authorization: 'Bearer ' + token, Authorization: 'Bearer ' + token,
}, },
timeout: 30 * 1000, timeout: 1000,
data: data, data: data,
cancelToken: source.token,
}; };
console.log('post data mobile', myRequest.data); console.log('post data mobile', myRequest.data);
return await axios(myRequest) return await axios(myRequest)
.then((response) => response) .then((response) => {
.then((response) => response) clearTimeout(timeout);
return response;
})
.then((response) => {
clearTimeout(timeout);
return response;
})
.catch((error) => { .catch((error) => {
console.log(error); clearTimeout(timeout);
console.log('errorTimeout', error);
const err = { const err = {
message: 'error', message: 'error',
status: error.request.status, status: error.request.status,
......
...@@ -63,8 +63,10 @@ const PickerImg = (props) => { ...@@ -63,8 +63,10 @@ const PickerImg = (props) => {
const res = await changeAvatart( const res = await changeAvatart(
createFormData(image, {uid: props.user.uid, platform: Platform.OS}), createFormData(image, {uid: props.user.uid, platform: Platform.OS}),
); );
console.log('upload avatar', res)
props.hideLoading(); props.hideLoading();
if (res.data.code == 200) { if (res?.status == 200 && res.data) {
if(res.data.code == 200) {
setTimeout(() => { setTimeout(() => {
props.saveUserToRedux(res.data.data); props.saveUserToRedux(res.data.data);
Alert.alert(I18n.t('Notification'), res.data.message); Alert.alert(I18n.t('Notification'), res.data.message);
...@@ -75,6 +77,12 @@ const PickerImg = (props) => { ...@@ -75,6 +77,12 @@ const PickerImg = (props) => {
Alert.alert(I18n.t('Notification'), res.data.message); Alert.alert(I18n.t('Notification'), res.data.message);
}, 500); }, 500);
} }
} else {
setImgAvatart(props.user.picture_url);
setTimeout(() => {
Alert.alert(I18n.t('Notification'), 'upload fail');
}, 500);
}
}; };
const onchoosGalery = () => { const onchoosGalery = () => {
......
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