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