reza fixed cart submit

master
Reza_ashrafi 3 years ago
parent 25caef9116
commit 1fbe8fae3e
  1. 15
      src/screens/DeliveryForm/index.js
  2. 34
      src/screens/ShoppingCart/index.js

@ -13,7 +13,7 @@ import React, { useEffect } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { userFactor, userAddress } from "../../redux/actions"; import { userFactor, userAddress } from "../../redux/actions";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import Svg, { G, Path } from "react-native-svg"; import { asyncAwesomeAlert } from "../../utils/AsyncWrappers";
//components //components
import Navbar from "../../components/Navbar"; import Navbar from "../../components/Navbar";
@ -28,7 +28,7 @@ import tw from "tailwind-rn";
import Colors from "../../constants/Colors"; import Colors from "../../constants/Colors";
import fontSize from "../../constants/fontSize"; 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 colorScheme = Appearance.getColorScheme();
const navigation = useNavigation(); const navigation = useNavigation();
@ -36,6 +36,8 @@ const DeliveryForm = ({ list, form, getList, getFactorInfo, userId }) => {
getFactorInfo({ userId }); getFactorInfo({ userId });
getList(); getList();
}, []); }, []);
console.log(userFactor);
return ( return (
<SafeAreaView <SafeAreaView
style={{ style={{
@ -74,7 +76,13 @@ const DeliveryForm = ({ list, form, getList, getFactorInfo, userId }) => {
color={"white"} color={"white"}
border={{ color: "#196EC0", width: 0 }} border={{ color: "#196EC0", width: 0 }}
width={"100%"} width={"100%"}
onPress={() => navigation.push("DeliveryForm")} onPress={() =>
factorInfo.transportId && factorInfo.userAddressId
? payFactor({userId})
: asyncAwesomeAlert("خطا", "آدرس یا نحوه ارسال را وارد کنید", {
showCancelButton: false,
})
}
/> />
</View> </View>
</ScrollView> </ScrollView>
@ -103,6 +111,7 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = { const mapDispatchToProps = {
getFactorInfo: userFactor.info, getFactorInfo: userFactor.info,
getList: userAddress.list, getList: userAddress.list,
payFactor : userFactor.payment
}; };
export default connect(mapStateToProps, mapDispatchToProps)(DeliveryForm); export default connect(mapStateToProps, mapDispatchToProps)(DeliveryForm);

@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect, useCallback } from "react";
import { import {
View, View,
Text, Text,
@ -15,7 +15,9 @@ import { connect } from "react-redux";
import { userProduct, userFactor } from "../../redux/actions"; import { userProduct, userFactor } from "../../redux/actions";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import { asyncAwesomeAlert } from "../../utils/AsyncWrappers";
import separate from "../../utils/separate"; import separate from "../../utils/separate";
import * as Linking from 'expo-linking';
//components //components
import Product from "./components/Product"; import Product from "./components/Product";
@ -89,20 +91,26 @@ function ShoppingCart({
getList, getList,
getFactorInfo, getFactorInfo,
loading, loading,
payFactor,
}) { }) {
const navigation = useNavigation(); const navigation = useNavigation();
const colorScheme = Appearance.getColorScheme(); const colorScheme = Appearance.getColorScheme();
const [position, setPosition] = useState("100%"); 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(() => { useEffect(() => {
getList(); getList();
getFactorInfo({ userId }); getFactorInfo({ userId });
}, []); }, []);
const setBoxPosition = () => { const setBoxPosition = useCallback(() => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
setPosition(position === "100%" ? "0%" : "100%"); setPosition(position === "100%" ? "0%" : "100%");
}; }, [userId]);
return ( return (
<SafeAreaView <SafeAreaView
@ -145,17 +153,19 @@ function ShoppingCart({
> >
<PriceStatus <PriceStatus
name="مبلغ سبد خرید" name="مبلغ سبد خرید"
value={separate(Math.round(factorInfo?.sumPrice))} value={isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice))}
type="normal" type="normal"
/> />
<PriceStatus <PriceStatus
name="میزان تخفیف" name="میزان تخفیف"
value={separate(Math.round(factorInfo?.offPrice))} value={isEmpty ? 0 : separate(Math.round(factorInfo?.offPrice))}
type="error" type="error"
/> />
<PriceStatus <PriceStatus
name="مالیات بر ارزش افزوده" name="مالیات بر ارزش افزوده"
value={separate(Math.round(factorInfo?.sumPrice * 0.009))} value={
isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice * 0.009))
}
type="error" type="error"
/> />
</View> </View>
@ -185,7 +195,7 @@ function ShoppingCart({
}, },
]} ]}
> >
{separate(factorInfo?.payPrice)} {isEmpty ? 0 : separate(factorInfo?.payPrice)}
</Text> </Text>
<Text <Text
style={[ style={[
@ -230,12 +240,18 @@ function ShoppingCart({
</Pressable> </Pressable>
<CustomPressable <CustomPressable
title={"ادامه فرایند خرید"} title={hasPhysical ? "ادامه فرایند خرید" : "پرداخت"}
backgroundColor={Colors.theme1[colorScheme].greenCF} backgroundColor={Colors.theme1[colorScheme].greenCF}
color={"white"} color={"white"}
border={{ color: "#196EC0", width: 0 }} border={{ color: "#196EC0", width: 0 }}
width={"100%"} width={"100%"}
onPress={() => navigation.push("DeliveryForm")} onPress={() =>
isEmpty
? asyncAwesomeAlert("خطا", "سبد خرید شما خالی است.", {
showCancelButton: false,
})
: hasPhysical ? navigation.push("DeliveryForm") : payFactor({userId})
}
/> />
</View> </View>
</ScrollView> </ScrollView>

Loading…
Cancel
Save