reza fixed error before 18

master
Reza_ashrafi 3 years ago
parent f983c60bc9
commit 24b1dba5d4
  1. 3
      navigation/index.js
  2. 15
      src/components/AlertModal.js
  3. 1
      src/components/Drawer.js
  4. 7
      src/components/Navbar.js
  5. 1
      src/redux/actions/userProduct.js
  6. 1
      src/redux/reducers/userFactor.js
  7. 1
      src/redux/reducers/userProduct.js
  8. 8
      src/screens/Home/components/Blogs.js
  9. 2
      src/screens/Home/index.js
  10. 12
      src/screens/Otp/index.js
  11. 95
      src/screens/Product/components/Book.js
  12. 2
      src/screens/Profile/components/User.js
  13. 30
      src/screens/ShoppingCart/components/Code.js
  14. 47
      src/screens/ShoppingCart/components/Product.js
  15. 6
      src/screens/ShoppingCart/index.js
  16. 55
      src/screens/Video/index.js
  17. 15
      src/screens/VideoDisplay/index.js

@ -352,6 +352,7 @@ const HomeStackScreen = () => {
<HomeStack.Screen name="Home" component={Home} /> <HomeStack.Screen name="Home" component={Home} />
<HomeStack.Screen name="VOD" component={Videos} /> <HomeStack.Screen name="VOD" component={Videos} />
<HomeStack.Screen name="Video" component={Video} unmountOnExit={true} /> <HomeStack.Screen name="Video" component={Video} unmountOnExit={true} />
<HomeStack.Screen name="ShoppingCart" component={ShoppingCart} />
<HomeStack.Screen name="VideoDisplay" component={VideoDisplay} /> <HomeStack.Screen name="VideoDisplay" component={VideoDisplay} />
<HomeStack.Screen name="Products" component={Products} /> <HomeStack.Screen name="Products" component={Products} />
<HomeStack.Screen name="Product" component={Product} /> <HomeStack.Screen name="Product" component={Product} />
@ -375,6 +376,7 @@ const ProductsStackScreen = () => {
> >
<ProductsStack.Screen name="Products" component={Products} /> <ProductsStack.Screen name="Products" component={Products} />
<ProductsStack.Screen name="Product" component={Product} /> <ProductsStack.Screen name="Product" component={Product} />
<ProductsStack.Screen name="ShoppingCart" component={ShoppingCart} />
<ProductsStack.Screen name="Sample" component={Sample} /> <ProductsStack.Screen name="Sample" component={Sample} />
<ProductsStack.Screen name="Info" component={Info} /> <ProductsStack.Screen name="Info" component={Info} />
</ProductsStack.Navigator> </ProductsStack.Navigator>
@ -392,6 +394,7 @@ const VODStackScreen = () => {
> >
<VODStack.Screen name="VOD" component={Videos} /> <VODStack.Screen name="VOD" component={Videos} />
<VODStack.Screen name="Video" component={Video} unmountOnExit={true} /> <VODStack.Screen name="Video" component={Video} unmountOnExit={true} />
<VODStack.Screen name="ShoppingCart" component={ShoppingCart} />
<VODStack.Screen name="VideoDisplay" component={VideoDisplay} /> <VODStack.Screen name="VideoDisplay" component={VideoDisplay} />
</VODStack.Navigator> </VODStack.Navigator>
); );

@ -91,18 +91,31 @@ const AlertModal = props => {
confirmButtonColor={alert.confirmButtonColor} confirmButtonColor={alert.confirmButtonColor}
onCancelPressed={onCancelPressed} onCancelPressed={onCancelPressed}
onConfirmPressed={(onConfirmPressed)} onConfirmPressed={(onConfirmPressed)}
cancelButtonTextStyle={{
color : '#777',
fontFamily : 'regular',
}}
confirmButtonTextStyle={{
fontFamily : 'regular',
}}
contentStyle={{ contentStyle={{
width: ReactNative.Dimensions.get('window').width / 1.5, width: ReactNative.Dimensions.get('window').width / 1.5,
}} }}
cancelButtonStyle={{ cancelButtonStyle={{
fontFamily : 'regular', fontFamily : 'regular',
borderColor : "#777",
borderWidth : 1,
backgroundColor : 'white',
}} }}
confirmButtonStyle={ confirmButtonStyle={
{ {
width: ReactNative.Dimensions.get('window').width / 4, width: ReactNative.Dimensions.get('window').width / 4,
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
fontFamily : 'regular' fontFamily : 'regular',
borderColor : "#2980b9",
borderWidth : 1,
} }
} }
useNativeDriver={true} useNativeDriver={true}

@ -9,7 +9,6 @@ import {
TouchableOpacity, TouchableOpacity,
Image, Image,
LayoutAnimation, LayoutAnimation,
StatusBar,
} from "react-native"; } from "react-native";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import { asyncAwesomeAlert } from "../utils/AsyncWrappers"; import { asyncAwesomeAlert } from "../utils/AsyncWrappers";

@ -5,6 +5,7 @@ import {
Text, Text,
Appearance, Appearance,
TouchableOpacity, TouchableOpacity,
ActivityIndicator,
} from "react-native"; } from "react-native";
import Svg, { import Svg, {
@ -36,6 +37,7 @@ const Navbar = ({
deleteBookmark, deleteBookmark,
userFavoriteList, userFavoriteList,
theme, theme,
bookmarkLoading,
}) => { }) => {
const navigation = useNavigation(); const navigation = useNavigation();
@ -391,7 +393,9 @@ const Navbar = ({
</> </>
)} )}
{headerOptions?.bookmark && {headerOptions?.bookmark &&
(isActiveBookmark ? ( (bookmarkLoading ? (
<ActivityIndicator size={20} color={Color.theme1[theme].green79} />
) : isActiveBookmark ? (
<Ionicons <Ionicons
name="bookmark" name="bookmark"
style={tw("mr-2")} style={tw("mr-2")}
@ -443,6 +447,7 @@ const Navbar = ({
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
userFavoriteList: state.userFavorite.list, userFavoriteList: state.userFavorite.list,
theme: state.publicApi.theme, theme: state.publicApi.theme,
bookmarkLoading: state.userFavorite.loading,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -19,7 +19,6 @@ const userProduct = {
(data = {}, data2 = {}, data3 = {}) => (data = {}, data2 = {}, data3 = {}) =>
async (dispatch) => { async (dispatch) => {
await proxy.post("userProduct/add", data, { dispatch }); await proxy.post("userProduct/add", data, { dispatch });
await proxy.get("userProduct/list", data2, { dispatch });
await proxy.get("userFactor/info", data3, { dispatch }); await proxy.get("userFactor/info", data3, { dispatch });
}, },
del: del:

@ -58,6 +58,7 @@ export default function userFactor(state = initialState, action) {
case "userFactor/error": case "userFactor/error":
asyncAwesomeAlert("خطا", data.message, { asyncAwesomeAlert("خطا", data.message, {
showCancelButton: false, showCancelButton: false,
confirmText: "باشه"
}); });
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };
default: default:

@ -23,6 +23,7 @@ export default function userFactor(state = initialState, action) {
data.filter((item) => item.product.productType === 2).length > 0 data.filter((item) => item.product.productType === 2).length > 0
? true ? true
: false; : false;
console.log('list fetched!');
return { return {
...state, ...state,
loading: false, loading: false,

@ -29,7 +29,7 @@ const ios = Platform.OS === "ios";
function Blogs({ blogs, mobile, theme }) { function Blogs({ blogs, mobile, theme }) {
return ( return (
<View style={[tw("flex mb-5")]}> <View style={[tw("flex")]}>
<View style={tw("w-full px-4")}> <View style={tw("w-full px-4")}>
<Header title={"خواندنیها"} route={"Blogs"} /> <Header title={"خواندنیها"} route={"Blogs"} />
</View> </View>
@ -37,7 +37,7 @@ function Blogs({ blogs, mobile, theme }) {
showsHorizontalScrollIndicator={false} showsHorizontalScrollIndicator={false}
horizontal={true} horizontal={true}
inverted={true} inverted={true}
style={[tw("flex flex-row mt-3 pb-7")]} style={[tw("flex flex-row mt-3")]}
data={blogs.slice(0, 7)} data={blogs.slice(0, 7)}
renderItem={({ item }) => ( renderItem={({ item }) => (
<Blog blog={item} mobile={mobile} theme={theme} /> <Blog blog={item} mobile={mobile} theme={theme} />
@ -51,11 +51,10 @@ function Blogs({ blogs, mobile, theme }) {
const Blog = ({ blog, mobile, theme }) => { const Blog = ({ blog, mobile, theme }) => {
const navigation = useNavigation(); const navigation = useNavigation();
return ( return (
<Pressable <Pressable
style={[ style={[
tw("rounded-md mr-4 rounded-md relative"), tw("mr-4 relative"),
{ width: mobile ? 250 : width / 2.2 }, { width: mobile ? 250 : width / 2.2 },
]} ]}
onPress={() => navigation.push("Blog", { id: blog?.id })} onPress={() => navigation.push("Blog", { id: blog?.id })}
@ -64,7 +63,6 @@ const Blog = ({ blog, mobile, theme }) => {
source={{ uri: `https://dnvn.ir/api/v1/file/${blog.fileIds}` }} source={{ uri: `https://dnvn.ir/api/v1/file/${blog.fileIds}` }}
resizeMode="contain" resizeMode="contain"
style={[ style={[
tw("rounded-md"),
{ {
flex: 1, flex: 1,
height: mobile ? 180 : ((width / 2.2) * 9) / 16, height: mobile ? 180 : ((width / 2.2) * 9) / 16,

@ -78,7 +78,7 @@ const Home = ({
// Later on in your styles.. // Later on in your styles..
const styles = StyleSheet.create({ const styles = StyleSheet.create({
contentContainerStyle: { contentContainerStyle: {
paddingBottom: 40, // paddingBottom: 40,
// flex : 1, // flex : 1,
// alignItems: "", // alignItems: "",
}, },

@ -118,7 +118,7 @@ function Otp(props) {
let timeout = setTimeout(() => { let timeout = setTimeout(() => {
clearInterval(interval); clearInterval(interval);
setTimeEnd(true); setTimeEnd(true);
}, 10000); }, 120000);
return () => { return () => {
clearInterval(interval); clearInterval(interval);
clearTimeout(timeout); clearTimeout(timeout);
@ -132,10 +132,14 @@ function Otp(props) {
const hour = Math.floor(value / 60); const hour = Math.floor(value / 60);
return ( return (
(hour > 0 (hour > 0
? (hour.toString().length === 1 ? "0" + hour.toString() : hour) + "" ? (minute.toString().length === 1
? "0" + minute.toString()
: minute) + ""
: "") + : "") +
" " +
":" + ":" +
(minute.toString().length === 1 ? "0" + minute.toString() : minute) " " +
(hour.toString().length === 1 ? "0" + hour.toString() : hour)
); );
}, },
[props.route] [props.route]
@ -345,7 +349,7 @@ function Otp(props) {
}, },
]} ]}
> >
{"زمان باقی مانده تا ارسال مجدد: " + duration(time)} {"زمان باقی مانده تا ارسال مجدد:" + " " + duration(time) + " "}
</Text> </Text>
) : ( ) : (
<View style={tw("flex")}> <View style={tw("flex")}>

@ -44,6 +44,7 @@ function Book({
}) { }) {
const navigation = useNavigation(); const navigation = useNavigation();
const [type, setType] = useState(1); const [type, setType] = useState(1);
const [whichTypeAdded, setWhichTypeAdded] = React.useState(null);
const [pageLoading, setPageLoading] = useState(false); const [pageLoading, setPageLoading] = useState(false);
const [imageSlider, setImageSlider] = useState(false); const [imageSlider, setImageSlider] = useState(false);
@ -66,10 +67,54 @@ function Book({
)[0]; )[0];
}, [userProducts, book]); }, [userProducts, book]);
const videoAvailabileInCart = React.useMemo(() => {
return userProducts?.filter(
(product) => product?.productId === book?.product[2]?.id
)[0];
}, [userProducts, book]);
const addToCart = React.useCallback(
async (action, type) => {
setWhichTypeAdded(type);
await action();
},
[book, userId]
);
React.useEffect(() => {
if (userProducts.length && whichTypeAdded) {
setTimeout(() => {
if (whichTypeAdded === "video" && videoAvailabileInCart) {
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
});
} else if (whichTypeAdded === "physical" && physicalAvailabileInCart) {
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
});
} else if (whichTypeAdded === "digital" && digitalAvailabileInCart) {
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
});
}
setWhichTypeAdded(null);
}, 500);
}
}, [userProducts]);
return ( return (
<ScrollView style={[tw("flex flex-1 relative")]}> <ScrollView style={[tw("flex flex-1 relative")]}>
{!mobile && <View style={tw("mt-5")}></View>} {!mobile && <View style={tw("mt-5")}></View>}
{(!book || userFavoriteLoading) && ( {(!book) && (
<View <View
style={[ style={[
tw("absolute left-0 top-0 rounded-md overflow-hidden"), tw("absolute left-0 top-0 rounded-md overflow-hidden"),
@ -221,17 +266,23 @@ function Book({
onPress={() => onPress={() =>
physicalAvailabileInCart physicalAvailabileInCart
? asyncAwesomeAlert( ? asyncAwesomeAlert(
"نتیجه", "",
"این محصول قبلا به سبد خرید اضافه شده است.", "این محصول قبلا به سبد خرید شما اضافه شده است.",
{ {
showCancelButton: false, showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
} }
) )
: pushToCart({ : addToCart(
pushToCart({
productId: book?.product[1]?.id, productId: book?.product[1]?.id,
userId: userId, userId: userId,
count: 1, count: 1,
}) }),
"physical"
)
} }
> >
<> <>
@ -278,17 +329,23 @@ function Book({
onPress={() => onPress={() =>
digitalAvailabileInCart digitalAvailabileInCart
? asyncAwesomeAlert( ? asyncAwesomeAlert(
"خطا", "",
"این محصول قبلا به سبد خرید اضافه شده است.", "این محصول قبلا به سبد خرید شما اضافه شده است.",
{ {
showCancelButton: false, showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
} }
) )
: pushToCart({ : addToCart(
pushToCart({
productId: book?.product[0]?.id, productId: book?.product[0]?.id,
userId: userId, userId: userId,
count: 1, count: 1,
}) }),
"digital"
)
} }
> >
<> <>
@ -356,11 +413,25 @@ function Book({
}, },
]} ]}
onPress={() => onPress={() =>
videoAvailabileInCart
? asyncAwesomeAlert(
"",
"این محصول قبلا به سبد خرید شما اضافه شده است.",
{
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
}
)
: addToCart(
pushToCart({ pushToCart({
productId: book?.product[2]?.id, productId: book?.product[2]?.id,
userId: userId, userId: userId,
count: 1, count: 1,
}) }),
"video"
)
} }
> >
<> <>

@ -133,7 +133,7 @@ const User = ({ user, mobile, theme, logout }) => {
style={tw(`flex w-full ${mobile ? "mt-0" : "mt-4"}`)} style={tw(`flex w-full ${mobile ? "mt-0" : "mt-4"}`)}
onPress={() => onPress={() =>
asyncAwesomeAlert( asyncAwesomeAlert(
"نتیجه", "",
"آیا قصد خروج از حساب کاربری فعلی رو داری؟", "آیا قصد خروج از حساب کاربری فعلی رو داری؟",
{ {
showCancelButton: true, showCancelButton: true,

@ -5,6 +5,7 @@ import {
Pressable, Pressable,
TextInput, TextInput,
KeyboardAvoidingView, KeyboardAvoidingView,
ActivityIndicator,
} from "react-native"; } from "react-native";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { userFactor } from "../../../redux/actions"; import { userFactor } from "../../../redux/actions";
@ -14,13 +15,21 @@ import fontSize from "../../../constants/fontSize";
import Colors from "../../../constants/Colors"; import Colors from "../../../constants/Colors";
import tw from "tailwind-rn"; import tw from "tailwind-rn";
function Code({ codeId, setCodeId, userId, factorId, theme }) { function Code({ codeId, setCodeId, theme, loading }) {
const [value, setValue] = React.useState(codeId || ""); const [value, setValue] = React.useState(codeId || "");
const [requestFlag, setRequestFlag] = React.useState(false);
const setOff = () => { const setOff = () => {
setCodeId({ offCodeValue: value, userId: userId, id: factorId }); setRequestFlag(true);
setCodeId({ offCodeValue: value });
}; };
React.useEffect(() => {
if (!loading) {
setRequestFlag(false);
}
}, [loading]);
return ( return (
<KeyboardAvoidingView <KeyboardAvoidingView
enabled enabled
@ -33,13 +42,13 @@ function Code({ codeId, setCodeId, userId, factorId, theme }) {
]} ]}
> >
<TextInput <TextInput
onChaneText={(text) => setValue(text)} onChangeText={(text) => setValue(text)}
style={[ style={[
tw("border-0 flex-1 text-right pr-3"), tw("border-0 flex-1 text-right pr-3"),
{ fontSize: fontSize.tiny, fontFamily: "regular" }, { fontSize: fontSize.tiny, fontFamily: "regular" },
]} ]}
placeholder={"کد تخفیف دارید ؟"} placeholder={"کد تخفیف دارید ؟"}
placeholderTextColor={Colors.theme1[theme].gray20 + 'aa'} placeholderTextColor={Colors.theme1[theme].gray20 + "aa"}
/> />
<Pressable <Pressable
onPress={() => setOff()} onPress={() => setOff()}
@ -52,6 +61,13 @@ function Code({ codeId, setCodeId, userId, factorId, theme }) {
}, },
]} ]}
> >
{loading && requestFlag ? (
<ActivityIndicator
size={fontSize.tiny}
color={Colors.theme1[theme].white}
style={tw('px-2')}
/>
) : (
<Text <Text
style={[ style={[
tw("text-white"), tw("text-white"),
@ -60,6 +76,7 @@ function Code({ codeId, setCodeId, userId, factorId, theme }) {
> >
ثبت کد ثبت کد
</Text> </Text>
)}
</Pressable> </Pressable>
</View> </View>
</KeyboardAvoidingView> </KeyboardAvoidingView>
@ -68,9 +85,8 @@ function Code({ codeId, setCodeId, userId, factorId, theme }) {
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
codeId: state.userFactor.info?.codeId, codeId: state.userFactor.info?.codeId,
userId: state.user.status?.id, loading: state.userFactor.loading,
factorId: state.userFactor.info?.id, theme: state.publicApi.theme,
theme: state.publicApi.theme
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -21,7 +21,7 @@ import tw from "tailwind-rn";
const width = Dimensions.get("window").width; const width = Dimensions.get("window").width;
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
function Product({ product, grades, pushToCart, loading, mobile, theme }) { function Product({ product, grades, pushToCart, loading, mobile, theme, addActionFlag, getList }) {
const [selectedProduct, setSelectedProduct] = React.useState(null); const [selectedProduct, setSelectedProduct] = React.useState(null);
const submit = async (action) => { const submit = async (action) => {
@ -36,6 +36,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
}, [loading]); }, [loading]);
return ( return (
product && (
<View <View
style={[ style={[
tw( tw(
@ -51,7 +52,8 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
<View style={tw(`flex ${ios ? "flex-row" : "flex-row-reverse"}`)}> <View style={tw(`flex ${ios ? "flex-row" : "flex-row-reverse"}`)}>
<Image <Image
source={{ source={{
uri: "https://dnvn.ir/api/v1/file/" + product.product.book.fileIds, uri:
"https://dnvn.ir/api/v1/file/" + product.product.book.fileIds,
}} }}
style={[ style={[
tw(""), tw(""),
@ -72,7 +74,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
fontFamily: "bold", fontFamily: "bold",
}} }}
> >
{product?.product?.book?.name || " "} {product.product.book.name || " "}
</Text> </Text>
<Text <Text
style={{ style={{
@ -82,7 +84,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
fontFamily: "regular", fontFamily: "regular",
}} }}
> >
{"پایه" + " " + grades[product?.product?.book?.gradeId] || " "} {"پایه" + " " + grades[product.product.book.gradeId] || " "}
</Text> </Text>
<Text <Text
style={{ style={{
@ -91,7 +93,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
fontFamily: "regular", fontFamily: "regular",
}} }}
> >
{product?.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"} {product.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"}
</Text> </Text>
<View <View
style={tw( style={tw(
@ -118,13 +120,15 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
}, },
]} ]}
> >
{separate(product?.product?.price) || " "} {separate(product.product.price) || " "}
</Text> </Text>
</View> </View>
</View> </View>
</View> </View>
<View <View
style={tw(`flex justify-between ${ios ? "items-end" : "items-start"}`)} style={tw(
`flex justify-between ${ios ? "items-end" : "items-start"}`
)}
> >
<AntDesign <AntDesign
name="close" name="close"
@ -134,12 +138,12 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
submit( submit(
pushToCart( pushToCart(
{ {
productId: product?.productId, productId: product.productId,
userId: product?.userId, userId: product.userId,
count: product?.productType === 1 ? -1 : -product?.count, count: product.productType === 1 ? -1 : -product?.count,
}, },
{}, {},
{ id: product?.factorId } { id: product.factorId }
) )
) )
} }
@ -147,15 +151,17 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
<View style={tw("flex items-center mt-2")}> <View style={tw("flex items-center mt-2")}>
<View <View
style={tw( style={tw(
`flex items-center mb-3 ${ios ? "flex-row" : "flex-row-reverse"}` `flex items-center mb-3 ${
ios ? "flex-row" : "flex-row-reverse"
}`
)} )}
> >
<Pressable <Pressable
onPress={() => onPress={() =>
submit( submit(
pushToCart({ pushToCart({
productId: product?.productId, productId: product.productId,
userId: product?.userId, userId: product.userId,
count: 1, count: 1,
}) })
) )
@ -181,7 +187,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
+ +
</Text> </Text>
</Pressable> </Pressable>
{loading && selectedProduct === product?.productId ? ( {(loading && selectedProduct === product.productId) ? (
<ActivityIndicator <ActivityIndicator
style={tw("mx-2")} style={tw("mx-2")}
size="small" size="small"
@ -198,7 +204,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
}, },
]} ]}
> >
{product?.count} {product.count}
</Text> </Text>
)} )}
@ -206,8 +212,8 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
onPress={() => onPress={() =>
submit( submit(
pushToCart({ pushToCart({
productId: product?.productId, productId: product.productId,
userId: product?.userId, userId: product.userId,
count: -1, count: -1,
}) })
) )
@ -252,12 +258,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
}, },
]} ]}
> >
{separate(product?.product?.price * product?.count) || " "} {separate(product.product.price * product.count) || " "}
</Text> </Text>
</View> </View>
</View> </View>
</View> </View>
</View> </View>
)
); );
} }
@ -265,10 +272,12 @@ const mapStateToProps = (state) => ({
grades: state.publicApi.grades, grades: state.publicApi.grades,
mobile: state.publicApi.mobile, mobile: state.publicApi.mobile,
theme: state.publicApi.theme, theme: state.publicApi.theme,
addActionFlag: state.userProduct.addActionFlag,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
pushToCart: userProduct.add, pushToCart: userProduct.add,
getList: userProduct.list
}; };
export default connect(mapStateToProps, mapDispatchToProps)(Product); export default connect(mapStateToProps, mapDispatchToProps)(Product);

@ -91,7 +91,7 @@ function ShoppingCart({
getFactorInfo, getFactorInfo,
loading, loading,
payFactor, payFactor,
theme theme,
}) { }) {
const navigation = useNavigation(); const navigation = useNavigation();
const [position, setPosition] = useState("100%"); const [position, setPosition] = useState("100%");
@ -109,9 +109,7 @@ function ShoppingCart({
}, [list]); }, [list]);
useEffect(() => { useEffect(() => {
if (list.length === 0) {
getList(); getList();
}
getFactorInfo({ userId }); getFactorInfo({ userId });
}, []); }, []);
@ -293,7 +291,7 @@ const mapStateToProps = (state) => ({
userId: state.user.status?.id, userId: state.user.status?.id,
hasPhysical: state.userProduct.hasPhysical, hasPhysical: state.userProduct.hasPhysical,
loading: state.userProduct.loading, loading: state.userProduct.loading,
theme: state.publicApi.theme theme: state.publicApi.theme,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -11,9 +11,11 @@ import {
Text, Text,
Appearance, Appearance,
} from "react-native"; } from "react-native";
import { useNavigation } from "@react-navigation/native";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { publicApi, userProduct } from "../../redux/actions"; import { publicApi, userProduct } from "../../redux/actions";
import separate from "../../utils/separate"; import separate from "../../utils/separate";
import { asyncAwesomeAlert } from "../../utils/AsyncWrappers";
//components //components
import Navbar from "../../components/Navbar"; import Navbar from "../../components/Navbar";
@ -40,10 +42,12 @@ function Product({
pushToCart, pushToCart,
loading, loading,
mobile, mobile,
theme theme,
userProducts,
}) { }) {
const [position, setPosition] = useState("100%"); const [position, setPosition] = useState("100%");
const navigation = useNavigation();
const [addedFlag, setAddedFlag] = React.useState(false);
useEffect(() => { useEffect(() => {
getBook({ bookId: route.params.id }, { id: route.params.id, vod: true }); getBook({ bookId: route.params.id }, { id: route.params.id, vod: true });
}, []); }, []);
@ -52,6 +56,32 @@ function Product({
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
setPosition(position === "100%" ? "0%" : "100%"); setPosition(position === "100%" ? "0%" : "100%");
}; };
const videoAvailabileInCart = React.useMemo(() => {
return userProducts?.filter(
(product) => product?.productId === book?.product[2]?.id
)[0];
}, [userProducts, book]);
const addToCart = React.useCallback(
async (action) => {
setAddedFlag(true);
await action();
},
[book, userId]
);
React.useEffect(() => {
if (videoAvailabileInCart && addedFlag) {
setAddedFlag(false);
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: false,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
});
}
}, [userProducts]);
return ( return (
<SafeAreaView <SafeAreaView
style={{ style={{
@ -90,7 +120,10 @@ function Product({
resizeMode="contain" resizeMode="contain"
style={[ style={[
tw("rounded-sm ml-2"), tw("rounded-sm ml-2"),
{ height: mobile ? width / 3 * 4 / 2.6 : 300, width: mobile ? width / 3 : 210 }, {
height: mobile ? ((width / 3) * 4) / 2.6 : 300,
width: mobile ? width / 3 : 210,
},
]} ]}
/> />
<View style={tw("flex items-end flex-1")}> <View style={tw("flex items-end flex-1")}>
@ -135,11 +168,24 @@ function Product({
width={"100%"} width={"100%"}
loading={loading} loading={loading}
onPress={() => onPress={() =>
videoAvailabileInCart
? asyncAwesomeAlert(
"",
"این محصول قبلا به سبد خرید شما اضافه شده است.",
{
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
}
)
: addToCart(
pushToCart({ pushToCart({
productId: book?.product[2]?.id, productId: book?.product[2]?.id,
userId: userId, userId: userId,
count: 1, count: 1,
}) })
)
} }
/> />
</View> </View>
@ -170,13 +216,14 @@ const styles = StyleSheet.create({
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
book: state.book.info, book: state.book.info,
userProducts: state.userProduct.list,
seasons: state.publicApi.categories, seasons: state.publicApi.categories,
grades: state.publicApi.grades, grades: state.publicApi.grades,
isLogin: state.user.status, isLogin: state.user.status,
userId: state.user.status?.id, userId: state.user.status?.id,
loading: state.userProduct.loading, loading: state.userProduct.loading,
mobile: state.publicApi.mobile, mobile: state.publicApi.mobile,
theme: state.publicApi.theme theme: state.publicApi.theme,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -31,7 +31,6 @@ const ios = Platform.OS === "ios";
function VideoDisplay({ route, mobile, theme }) { function VideoDisplay({ route, mobile, theme }) {
const video = React.useRef(null); const video = React.useRef(null);
const [width, setWidth] = useState(Dimensions.get("window").width); const [width, setWidth] = useState(Dimensions.get("window").width);
const [status, setStatus] = React.useState({});
const [position, setPosition] = useState("100%"); const [position, setPosition] = useState("100%");
const setBoxPosition = () => { const setBoxPosition = () => {
@ -39,15 +38,7 @@ function VideoDisplay({ route, mobile, theme }) {
setPosition(position === "100%" ? "0%" : "100%"); setPosition(position === "100%" ? "0%" : "100%");
}; };
const setOrientation = () => { console.log(video);
if (Dimensions.get("window").height > Dimensions.get("window").width) {
//Device is in portrait mode, rotate to landscape mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
} else {
//Device is in landscape mode, rotate to portrait mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT);
}
}
return ( return (
<SafeAreaView <SafeAreaView
@ -85,9 +76,7 @@ function VideoDisplay({ route, mobile, theme }) {
}} }}
useNativeControls useNativeControls
resizeMode="cover" resizeMode="cover"
onFullscreenUpdate={setOrientation}
isLooping
onPlaybackStatusUpdate={(status) => setStatus(() => status)}
/> />
<Text <Text
style={{ style={{

Loading…
Cancel
Save