reza fixed splash

master
Reza_ashrafi 3 years ago
parent 12859f5f83
commit 314bd19066
  1. 42
      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 }),
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;

@ -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;
}

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

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

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

@ -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 (
<View
style={{

Loading…
Cancel
Save