diff --git a/src/redux/proxy.js b/src/redux/proxy.js index b7c8d98..afcf307 100644 --- a/src/redux/proxy.js +++ b/src/redux/proxy.js @@ -26,22 +26,19 @@ class Proxy { () => Axios.get(url, { params, ...opt }), data || params ); - } catch (error) { - } + } catch (error) {} }; post = (url, params, opt, data) => { try { this.check(url, opt, () => Axios.post(url, params, opt), data || params); - } catch (error) { - } + } catch (error) {} }; put = (url, params, opt, data) => { try { this.check(url, opt, () => Axios.put(url, params, opt), data || params); - } catch (error) { - } + } catch (error) {} }; delete = (url, params, opt, data) => { @@ -52,8 +49,7 @@ class Proxy { () => Axios.delete(url, { ...opt, data: params }), data || params ); - } catch (error) { - } + } catch (error) {} }; check = async (url, { dispatch }, fetch, params) => { @@ -70,8 +66,16 @@ class Proxy { let response = fetch(); dispatch({ type: url, data: response.data.data, params }); return response.data.data; - } + } break; + case 403: + console.log(url.split("/")[0] + "/" + "error"), + dispatch({ + type: url.split("/")[0] + "/" + "error", + // data: response.data, + // params, + }); + return; default: dispatch({ type: url.split("/")[0] + "/" + "error", @@ -80,8 +84,7 @@ class Proxy { }); } return false; - } catch (error) { - } + } catch (error) {} }; refresh = () => { @@ -95,8 +98,7 @@ class Proxy { { headers: { Authorization: `Bearer ${refresh}` } } ); return login ? true : false; - } catch (error) { - } + } catch (error) {} }; login = (url, params, { dispatch }) => { @@ -104,9 +106,9 @@ class Proxy { this.post(url, params, { dispatch: (obj) => { let login = obj.data; - if (!login || !login.refreshToken){ + if (!login || !login.refreshToken) { return false; - } + } const refresh = ["refresh", login.refreshToken]; const access = ["access", login.accessToken]; const userData = ["userData", JSON.stringify(login.profile)]; @@ -116,8 +118,7 @@ class Proxy { dispatch(obj); }, }); - } catch (error) { - } + } catch (error) {} }; logout = (url, params, { dispatch }) => { @@ -129,8 +130,7 @@ class Proxy { dispatch(obj); }, }); - } catch (error) { - } + } catch (error) {} }; status = async () => { try { @@ -149,8 +149,8 @@ class Proxy { }; getStatus = async ({ dispatch }) => { let status = await this.status(); - dispatch({ type: "user/getStatus", data: {status}}) - } + dispatch({ type: "user/getStatus", data: { status } }); + }; } const _proxy = new Proxy(); export default _proxy; diff --git a/src/redux/reducers/user.js b/src/redux/reducers/user.js index d0f7b1b..4ec3de1 100644 --- a/src/redux/reducers/user.js +++ b/src/redux/reducers/user.js @@ -61,11 +61,12 @@ const user = (state = initialState, action) => { return { ...state, loading: false, error: null, profileFields: data }; case "user/loading": return { ...state, loading: true }; - case "error": - asyncAwesomeAlert("خطا", data.message, { - showCancelButton: false, - }); - return { ...state, loading: false, error: data.message }; + case "user/error": + console.log('hey'); + // asyncAwesomeAlert("خطا", data.message, { + // showCancelButton: false, + // }); + return { ...state, error : true }; default: return state; } diff --git a/src/screens/Otp/index.js b/src/screens/Otp/index.js index b1d312d..e96362e 100644 --- a/src/screens/Otp/index.js +++ b/src/screens/Otp/index.js @@ -215,8 +215,8 @@ function Otp(props) { fontFamily: "demi", }} > - {props.route.params?.phone || "09123456789"} - + {' ' + props.route.params?.phone || "09123456789" + ' '} + {" "} ارسال شد. آن را در قسمت زیر وارد کنید. { +const User = ({ user, mobile, theme, logout }) => { const [dropdown, setDropdown] = React.useState(true); return ( @@ -79,49 +80,77 @@ const User = ({ user, mobile, theme }) => { {dropdown && ( - - asyncAwesomeAlert("نتیجه", "این قابلیت در حال توسعه است.", { - showCancelButton: false, - }) - } - > - + + asyncAwesomeAlert("نتیجه", "این قابلیت در حال توسعه است.", { + showCancelButton: false, + }) + } > - - افزودن حساب کاربری جدید - - + افزودن حساب کاربری جدید + + + + + + + + + asyncAwesomeAlert( + "نتیجه", + "آیا قصد خروج از حساب کاربری فعلی رو داری؟", + { + showCancelButton: true, + onConfirm : () => logout(), + }, + + ) + } + > + - + - - - + + خروج از حساب کاربری + + + + )} ); @@ -133,4 +162,8 @@ const mapStateToProps = (state) => ({ theme: state.publicApi.theme, }); -export default connect(mapStateToProps)(User); +const mapDispatchToProps = { + logout : user.logout +} + +export default connect(mapStateToProps, mapDispatchToProps)(User); diff --git a/src/screens/ShoppingCart/components/Product.js b/src/screens/ShoppingCart/components/Product.js index c827aeb..88b2f07 100644 --- a/src/screens/ShoppingCart/components/Product.js +++ b/src/screens/ShoppingCart/components/Product.js @@ -164,13 +164,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { + - {loading ? ( + {/* {loading ? ( - ) : ( + ) : ( */} {product?.count} - )} + {/* )} */} diff --git a/src/screens/Splash/index.js b/src/screens/Splash/index.js index 7eacc3a..2e6f10e 100644 --- a/src/screens/Splash/index.js +++ b/src/screens/Splash/index.js @@ -1,7 +1,8 @@ import React, { useEffect } from "react"; -import { View, Image, ActivityIndicator, Dimensions } from "react-native"; +import { View, Image, ActivityIndicator, Dimensions, BackHandler } from "react-native"; import { connect } from "react-redux"; import { blog, book, userProduct } from "../../redux/actions"; +import { useIsFocused } from '@react-navigation/native'; import Logo from "../../assets/images/logo.png"; @@ -17,9 +18,12 @@ function Splash({ userProducts, getUserProducts, }) { + const isFocused = useIsFocused(); + const [out, setOut] = React.useState(false); useEffect(() => { if (isLogin !== null) { if (isLogin === false) { + setOut(true); navigation.navigate("Login"); } else { if (blogs.length === 0) { @@ -29,12 +33,38 @@ function Splash({ } else if (userProducts.length === 0) { getUserProducts(); } else { + setOut(true) navigation.navigate("Root"); } } } }, [isLogin, userProducts, books, blogs]); + if(isFocused && out){ + setOut(false); + BackHandler.exitApp(); + } + + if(isFocused && !out){ + if (isLogin !== null) { + if (isLogin === false) { + setOut(true); + navigation.navigate("Login"); + } else { + if (blogs.length === 0) { + getBlogs(); + } else if (books.length === 0) { + getBooks({ vod: true }); + } else if (userProducts.length === 0) { + getUserProducts(); + } else { + setOut(true) + navigation.navigate("Root"); + } + } + } + } + return (