diff --git a/src/screens/DeliveryForm/index.js b/src/screens/DeliveryForm/index.js index 5996473..22d5f3b 100644 --- a/src/screens/DeliveryForm/index.js +++ b/src/screens/DeliveryForm/index.js @@ -13,7 +13,7 @@ import React, { useEffect } from "react"; import { connect } from "react-redux"; import { userFactor, userAddress } from "../../redux/actions"; import { useNavigation } from "@react-navigation/native"; -import Svg, { G, Path } from "react-native-svg"; +import { asyncAwesomeAlert } from "../../utils/AsyncWrappers"; //components import Navbar from "../../components/Navbar"; @@ -28,7 +28,7 @@ import tw from "tailwind-rn"; import Colors from "../../constants/Colors"; import fontSize from "../../constants/fontSize"; -const DeliveryForm = ({ list, form, getList, getFactorInfo, userId }) => { +const DeliveryForm = ({ list, form, getList, getFactorInfo, userId, payFactor, factorInfo }) => { const colorScheme = Appearance.getColorScheme(); const navigation = useNavigation(); @@ -36,6 +36,8 @@ const DeliveryForm = ({ list, form, getList, getFactorInfo, userId }) => { getFactorInfo({ userId }); getList(); }, []); + + console.log(userFactor); return ( { color={"white"} border={{ color: "#196EC0", width: 0 }} width={"100%"} - onPress={() => navigation.push("DeliveryForm")} + onPress={() => + factorInfo.transportId && factorInfo.userAddressId + ? payFactor({userId}) + : asyncAwesomeAlert("خطا", "آدرس یا نحوه ارسال را وارد کنید", { + showCancelButton: false, + }) + } /> @@ -103,6 +111,7 @@ const mapStateToProps = (state) => ({ const mapDispatchToProps = { getFactorInfo: userFactor.info, getList: userAddress.list, + payFactor : userFactor.payment }; export default connect(mapStateToProps, mapDispatchToProps)(DeliveryForm); diff --git a/src/screens/ShoppingCart/index.js b/src/screens/ShoppingCart/index.js index 9565d7c..31bb5b6 100644 --- a/src/screens/ShoppingCart/index.js +++ b/src/screens/ShoppingCart/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useCallback } from "react"; import { View, Text, @@ -15,7 +15,9 @@ import { connect } from "react-redux"; import { userProduct, userFactor } from "../../redux/actions"; import { Ionicons } from "@expo/vector-icons"; import { useNavigation } from "@react-navigation/native"; +import { asyncAwesomeAlert } from "../../utils/AsyncWrappers"; import separate from "../../utils/separate"; +import * as Linking from 'expo-linking'; //components import Product from "./components/Product"; @@ -89,20 +91,26 @@ function ShoppingCart({ getList, getFactorInfo, loading, + payFactor, }) { const navigation = useNavigation(); const colorScheme = Appearance.getColorScheme(); const [position, setPosition] = useState("100%"); + const isEmpty = list.filter((product) => product.condition < 2).length === 0; + const hasPhysical = + list.filter((product) => product.condition < 2 && product.productType === 2) + .length !== 0; + useEffect(() => { getList(); getFactorInfo({ userId }); }, []); - const setBoxPosition = () => { + const setBoxPosition = useCallback(() => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); setPosition(position === "100%" ? "0%" : "100%"); - }; + }, [userId]); return ( @@ -185,7 +195,7 @@ function ShoppingCart({ }, ]} > - {separate(factorInfo?.payPrice)} + {isEmpty ? 0 : separate(factorInfo?.payPrice)} navigation.push("DeliveryForm")} + onPress={() => + isEmpty + ? asyncAwesomeAlert("خطا", "سبد خرید شما خالی است.", { + showCancelButton: false, + }) + : hasPhysical ? navigation.push("DeliveryForm") : payFactor({userId}) + } />