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 { 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 (
<SafeAreaView
style={{
@ -74,7 +76,13 @@ const DeliveryForm = ({ list, form, getList, getFactorInfo, userId }) => {
color={"white"}
border={{ color: "#196EC0", width: 0 }}
width={"100%"}
onPress={() => navigation.push("DeliveryForm")}
onPress={() =>
factorInfo.transportId && factorInfo.userAddressId
? payFactor({userId})
: asyncAwesomeAlert("خطا", "آدرس یا نحوه ارسال را وارد کنید", {
showCancelButton: false,
})
}
/>
</View>
</ScrollView>
@ -103,6 +111,7 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = {
getFactorInfo: userFactor.info,
getList: userAddress.list,
payFactor : userFactor.payment
};
export default connect(mapStateToProps, mapDispatchToProps)(DeliveryForm);

@ -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 (
<SafeAreaView
@ -145,17 +153,19 @@ function ShoppingCart({
>
<PriceStatus
name="مبلغ سبد خرید"
value={separate(Math.round(factorInfo?.sumPrice))}
value={isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice))}
type="normal"
/>
<PriceStatus
name="میزان تخفیف"
value={separate(Math.round(factorInfo?.offPrice))}
value={isEmpty ? 0 : separate(Math.round(factorInfo?.offPrice))}
type="error"
/>
<PriceStatus
name="مالیات بر ارزش افزوده"
value={separate(Math.round(factorInfo?.sumPrice * 0.009))}
value={
isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice * 0.009))
}
type="error"
/>
</View>
@ -185,7 +195,7 @@ function ShoppingCart({
},
]}
>
{separate(factorInfo?.payPrice)}
{isEmpty ? 0 : separate(factorInfo?.payPrice)}
</Text>
<Text
style={[
@ -230,12 +240,18 @@ function ShoppingCart({
</Pressable>
<CustomPressable
title={"ادامه فرایند خرید"}
title={hasPhysical ? "ادامه فرایند خرید" : "پرداخت"}
backgroundColor={Colors.theme1[colorScheme].greenCF}
color={"white"}
border={{ color: "#196EC0", width: 0 }}
width={"100%"}
onPress={() => navigation.push("DeliveryForm")}
onPress={() =>
isEmpty
? asyncAwesomeAlert("خطا", "سبد خرید شما خالی است.", {
showCancelButton: false,
})
: hasPhysical ? navigation.push("DeliveryForm") : payFactor({userId})
}
/>
</View>
</ScrollView>

Loading…
Cancel
Save