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