reza fixed splash

master
Reza_ashrafi 3 years ago
parent 12859f5f83
commit 314bd19066
  1. 38
      src/redux/proxy.js
  2. 11
      src/redux/reducers/user.js
  3. 4
      src/screens/Otp/index.js
  4. 117
      src/screens/Profile/components/User.js
  5. 6
      src/screens/ShoppingCart/components/Product.js
  6. 32
      src/screens/Splash/index.js

@ -26,22 +26,19 @@ class Proxy {
() => Axios.get(url, { params, ...opt }), () => Axios.get(url, { params, ...opt }),
data || params data || params
); );
} catch (error) { } catch (error) {}
}
}; };
post = (url, params, opt, data) => { post = (url, params, opt, data) => {
try { try {
this.check(url, opt, () => Axios.post(url, params, opt), data || params); this.check(url, opt, () => Axios.post(url, params, opt), data || params);
} catch (error) { } catch (error) {}
}
}; };
put = (url, params, opt, data) => { put = (url, params, opt, data) => {
try { try {
this.check(url, opt, () => Axios.put(url, params, opt), data || params); this.check(url, opt, () => Axios.put(url, params, opt), data || params);
} catch (error) { } catch (error) {}
}
}; };
delete = (url, params, opt, data) => { delete = (url, params, opt, data) => {
@ -52,8 +49,7 @@ class Proxy {
() => Axios.delete(url, { ...opt, data: params }), () => Axios.delete(url, { ...opt, data: params }),
data || params data || params
); );
} catch (error) { } catch (error) {}
}
}; };
check = async (url, { dispatch }, fetch, params) => { check = async (url, { dispatch }, fetch, params) => {
@ -72,6 +68,14 @@ class Proxy {
return response.data.data; return response.data.data;
} }
break; break;
case 403:
console.log(url.split("/")[0] + "/" + "error"),
dispatch({
type: url.split("/")[0] + "/" + "error",
// data: response.data,
// params,
});
return;
default: default:
dispatch({ dispatch({
type: url.split("/")[0] + "/" + "error", type: url.split("/")[0] + "/" + "error",
@ -80,8 +84,7 @@ class Proxy {
}); });
} }
return false; return false;
} catch (error) { } catch (error) {}
}
}; };
refresh = () => { refresh = () => {
@ -95,8 +98,7 @@ class Proxy {
{ headers: { Authorization: `Bearer ${refresh}` } } { headers: { Authorization: `Bearer ${refresh}` } }
); );
return login ? true : false; return login ? true : false;
} catch (error) { } catch (error) {}
}
}; };
login = (url, params, { dispatch }) => { login = (url, params, { dispatch }) => {
@ -104,7 +106,7 @@ class Proxy {
this.post(url, params, { this.post(url, params, {
dispatch: (obj) => { dispatch: (obj) => {
let login = obj.data; let login = obj.data;
if (!login || !login.refreshToken){ if (!login || !login.refreshToken) {
return false; return false;
} }
const refresh = ["refresh", login.refreshToken]; const refresh = ["refresh", login.refreshToken];
@ -116,8 +118,7 @@ class Proxy {
dispatch(obj); dispatch(obj);
}, },
}); });
} catch (error) { } catch (error) {}
}
}; };
logout = (url, params, { dispatch }) => { logout = (url, params, { dispatch }) => {
@ -129,8 +130,7 @@ class Proxy {
dispatch(obj); dispatch(obj);
}, },
}); });
} catch (error) { } catch (error) {}
}
}; };
status = async () => { status = async () => {
try { try {
@ -149,8 +149,8 @@ class Proxy {
}; };
getStatus = async ({ dispatch }) => { getStatus = async ({ dispatch }) => {
let status = await this.status(); let status = await this.status();
dispatch({ type: "user/getStatus", data: {status}}) dispatch({ type: "user/getStatus", data: { status } });
} };
} }
const _proxy = new Proxy(); const _proxy = new Proxy();
export default _proxy; export default _proxy;

@ -61,11 +61,12 @@ const user = (state = initialState, action) => {
return { ...state, loading: false, error: null, profileFields: data }; return { ...state, loading: false, error: null, profileFields: data };
case "user/loading": case "user/loading":
return { ...state, loading: true }; return { ...state, loading: true };
case "error": case "user/error":
asyncAwesomeAlert("خطا", data.message, { console.log('hey');
showCancelButton: false, // asyncAwesomeAlert("خطا", data.message, {
}); // showCancelButton: false,
return { ...state, loading: false, error: data.message }; // });
return { ...state, error : true };
default: default:
return state; return state;
} }

@ -215,8 +215,8 @@ function Otp(props) {
fontFamily: "demi", fontFamily: "demi",
}} }}
> >
{props.route.params?.phone || "09123456789"} {' ' + props.route.params?.phone || "09123456789" + ' '}
</Text> </Text>{" "}
ارسال شد. آن را در قسمت زیر وارد کنید. ارسال شد. آن را در قسمت زیر وارد کنید.
</Text> </Text>
<View <View

@ -1,6 +1,7 @@
import { View, Text, Image, Platform, Pressable } from "react-native"; import { View, Text, Image, Platform, Pressable } from "react-native";
import React from "react"; import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import {user} from "../../../redux/actions";
import Svg, { Path } from "react-native-svg"; import Svg, { Path } from "react-native-svg";
import { asyncAwesomeAlert } from "../../../utils/AsyncWrappers"; import { asyncAwesomeAlert } from "../../../utils/AsyncWrappers";
@ -11,7 +12,7 @@ import Colors from "../../../constants/Colors";
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
const User = ({ user, mobile, theme }) => { const User = ({ user, mobile, theme, logout }) => {
const [dropdown, setDropdown] = React.useState(true); const [dropdown, setDropdown] = React.useState(true);
return ( return (
<View style={tw(`w-full ${ios ? "items-end" : ""}`)}> <View style={tw(`w-full ${ios ? "items-end" : ""}`)}>
@ -79,49 +80,77 @@ const User = ({ user, mobile, theme }) => {
</Svg> </Svg>
</Pressable> </Pressable>
{dropdown && ( {dropdown && (
<Pressable <View style={tw(`flex flex-col pr-16 ${ios ? "items-end" : " "}`)}>
style={tw( <Pressable
`flex w-full pr-16 ${ios ? "items-end" : " "} ${ style={tw(`flex w-full ${mobile ? "mt-0" : "mt-4"}`)}
mobile ? "mt-0" : "mt-4" onPress={() =>
}` asyncAwesomeAlert("نتیجه", "این قابلیت در حال توسعه است.", {
)} showCancelButton: false,
onPress={() => })
asyncAwesomeAlert("نتیجه", "این قابلیت در حال توسعه است.", { }
showCancelButton: false,
})
}
>
<View
style={[
tw(`flex items-center w-full pb-3 mb-3 flex-row-reverse`),
{
borderBottomWidth: 1,
borderColor: Colors.theme1[theme].grayE3,
},
]}
> >
<Text <View
style={{ style={[
fontSize: mobile ? fontSize.base : fontSize.xl, tw(`flex items-center w-full pb-3 mb-3 flex-row-reverse`),
fontFamily: "bold", {
color: Colors.theme1[theme].gray20, borderBottomWidth: 1,
}} borderColor: Colors.theme1[theme].grayE3,
},
]}
> >
افزودن حساب کاربری جدید <Text
</Text> style={{
<Text fontSize: mobile ? fontSize.base : fontSize.xl,
style={{ fontFamily: "bold",
marginRight: 5, color: Colors.theme1[theme].gray20,
marginTop: 3, }}
fontSize: fontSize.xl2, >
fontFamily: "bold", افزودن حساب کاربری جدید
color: Colors.theme1[theme].gray20, </Text>
}} <Text
style={{
marginRight: 5,
marginTop: 3,
fontSize: fontSize.xl2,
fontFamily: "bold",
color: Colors.theme1[theme].gray20,
}}
>
+
</Text>
</View>
</Pressable>
<Pressable
style={tw(`flex w-full ${mobile ? "mt-0" : "mt-4"}`)}
onPress={() =>
asyncAwesomeAlert(
"نتیجه",
"آیا قصد خروج از حساب کاربری فعلی رو داری؟",
{
showCancelButton: true,
onConfirm : () => logout(),
},
)
}
>
<View
style={[
tw(`flex items-center w-full pb-3 mb-3 flex-row-reverse`),
]}
> >
+ <Text
</Text> style={{
</View> fontSize: mobile ? fontSize.base : fontSize.xl,
</Pressable> fontFamily: "bold",
color: Colors.theme1[theme].redFF1,
}}
>
خروج از حساب کاربری
</Text>
</View>
</Pressable>
</View>
)} )}
</View> </View>
); );
@ -133,4 +162,8 @@ const mapStateToProps = (state) => ({
theme: state.publicApi.theme, theme: state.publicApi.theme,
}); });
export default connect(mapStateToProps)(User); const mapDispatchToProps = {
logout : user.logout
}
export default connect(mapStateToProps, mapDispatchToProps)(User);

@ -164,13 +164,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
+ +
</Text> </Text>
</Pressable> </Pressable>
{loading ? ( {/* {loading ? (
<ActivityIndicator <ActivityIndicator
style={tw("mx-2")} style={tw("mx-2")}
size="small" size="small"
color={Colors.theme1[theme].greenBA} color={Colors.theme1[theme].greenBA}
/> />
) : ( ) : ( */}
<Text <Text
style={[ style={[
tw("mx-2.5"), tw("mx-2.5"),
@ -183,7 +183,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
> >
{product?.count} {product?.count}
</Text> </Text>
)} {/* )} */}
<Pressable <Pressable
onPress={() => onPress={() =>

@ -1,7 +1,8 @@
import React, { useEffect } from "react"; 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 { connect } from "react-redux";
import { blog, book, userProduct } from "../../redux/actions"; import { blog, book, userProduct } from "../../redux/actions";
import { useIsFocused } from '@react-navigation/native';
import Logo from "../../assets/images/logo.png"; import Logo from "../../assets/images/logo.png";
@ -17,9 +18,12 @@ function Splash({
userProducts, userProducts,
getUserProducts, getUserProducts,
}) { }) {
const isFocused = useIsFocused();
const [out, setOut] = React.useState(false);
useEffect(() => { useEffect(() => {
if (isLogin !== null) { if (isLogin !== null) {
if (isLogin === false) { if (isLogin === false) {
setOut(true);
navigation.navigate("Login"); navigation.navigate("Login");
} else { } else {
if (blogs.length === 0) { if (blogs.length === 0) {
@ -29,12 +33,38 @@ function Splash({
} else if (userProducts.length === 0) { } else if (userProducts.length === 0) {
getUserProducts(); getUserProducts();
} else { } else {
setOut(true)
navigation.navigate("Root"); navigation.navigate("Root");
} }
} }
} }
}, [isLogin, userProducts, books, blogs]); }, [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 ( return (
<View <View
style={{ style={{

Loading…
Cancel
Save