|
|
|
@ -17,7 +17,7 @@ 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'; |
|
|
|
|
import * as Linking from "expo-linking"; |
|
|
|
|
|
|
|
|
|
//components
|
|
|
|
|
import Product from "./components/Product"; |
|
|
|
@ -25,6 +25,7 @@ import Code from "./components/Code"; |
|
|
|
|
import CustomPressable from "../../components/Pressable"; |
|
|
|
|
import Navbar from "../../components/Navbar"; |
|
|
|
|
import Drawer from "../../components/Drawer"; |
|
|
|
|
import Empty from "../../components/Empty"; |
|
|
|
|
|
|
|
|
|
//style
|
|
|
|
|
import fontSize from "../../constants/fontSize"; |
|
|
|
@ -103,7 +104,7 @@ function ShoppingCart({ |
|
|
|
|
.length !== 0; |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if(list.length === 0){ |
|
|
|
|
if (list.length === 0) { |
|
|
|
|
getList(); |
|
|
|
|
} |
|
|
|
|
getFactorInfo({ userId }); |
|
|
|
@ -135,128 +136,138 @@ function ShoppingCart({ |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
<Drawer setBoxPosition={setBoxPosition} position={position} /> |
|
|
|
|
<ScrollView |
|
|
|
|
contentContainerStyle={styles.contentContainerStyle} |
|
|
|
|
style={styles.container} |
|
|
|
|
> |
|
|
|
|
{list |
|
|
|
|
?.sort((a, b) => a?.id - b?.id) |
|
|
|
|
?.map( |
|
|
|
|
(product, index) => |
|
|
|
|
product.condition < 2 && ( |
|
|
|
|
<Product key={index} product={product} loading={loading} /> |
|
|
|
|
) |
|
|
|
|
)} |
|
|
|
|
<Code /> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
"flex w-full border-t py-2 border-gray-300 border-b mt-6" |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<PriceStatus |
|
|
|
|
name="مبلغ سبد خرید" |
|
|
|
|
value={isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice))} |
|
|
|
|
type="normal" |
|
|
|
|
/> |
|
|
|
|
<PriceStatus |
|
|
|
|
name="میزان تخفیف" |
|
|
|
|
value={isEmpty ? 0 : separate(Math.round(factorInfo?.offPrice))} |
|
|
|
|
type="error" |
|
|
|
|
/> |
|
|
|
|
<PriceStatus |
|
|
|
|
name="مالیات بر ارزش افزوده" |
|
|
|
|
value={ |
|
|
|
|
isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice * 0.009)) |
|
|
|
|
} |
|
|
|
|
type="error" |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
"flex flex-row-reverse justify-between items-center w-full py-3" |
|
|
|
|
)} |
|
|
|
|
{list?.filter((product) => product.condition < 2)?.length > 0 ? ( |
|
|
|
|
<ScrollView |
|
|
|
|
contentContainerStyle={styles.contentContainerStyle} |
|
|
|
|
style={styles.container} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.base, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
{list |
|
|
|
|
?.sort((a, b) => a?.id - b?.id) |
|
|
|
|
?.map( |
|
|
|
|
(product, index) => |
|
|
|
|
product.condition < 2 && ( |
|
|
|
|
<Product key={index} product={product} loading={loading} /> |
|
|
|
|
) |
|
|
|
|
)} |
|
|
|
|
<Code /> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
"flex w-full border-t py-2 border-gray-300 border-b mt-6" |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<PriceStatus |
|
|
|
|
name="مبلغ سبد خرید" |
|
|
|
|
value={isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice))} |
|
|
|
|
type="normal" |
|
|
|
|
/> |
|
|
|
|
<PriceStatus |
|
|
|
|
name="میزان تخفیف" |
|
|
|
|
value={isEmpty ? 0 : separate(Math.round(factorInfo?.offPrice))} |
|
|
|
|
type="error" |
|
|
|
|
/> |
|
|
|
|
<PriceStatus |
|
|
|
|
name="مالیات بر ارزش افزوده" |
|
|
|
|
value={ |
|
|
|
|
isEmpty ? 0 : separate(Math.round(factorInfo?.sumPrice * 0.009)) |
|
|
|
|
} |
|
|
|
|
type="error" |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
"flex flex-row-reverse justify-between items-center w-full py-3" |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
جمع کل سبد خرید |
|
|
|
|
</Text> |
|
|
|
|
<View style={tw("flex flex-row-reverse items-center")}> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.xl, |
|
|
|
|
fontSize: fontSize.base, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{isEmpty ? 0 : separate(factorInfo?.payPrice)} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
marginRight: 4, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
تومان |
|
|
|
|
جمع کل سبد خرید |
|
|
|
|
</Text> |
|
|
|
|
<View style={tw("flex flex-row-reverse items-center")}> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.xl, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{isEmpty ? 0 : separate(factorInfo?.payPrice)} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
marginRight: 4, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
تومان |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
<View style={tw("w-full")}> |
|
|
|
|
<Pressable |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
|
"w-full rounded-md flex flex-row justify-center items-center py-3 px-3 my-5" |
|
|
|
|
), |
|
|
|
|
{ backgroundColor: Colors.theme1[colorScheme].greenC8 + "1a" }, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
<View style={tw("w-full")}> |
|
|
|
|
<Pressable |
|
|
|
|
style={[ |
|
|
|
|
tw("mr-1"), |
|
|
|
|
{ |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
tw( |
|
|
|
|
"w-full rounded-md flex flex-row justify-center items-center py-3 px-3 my-5" |
|
|
|
|
), |
|
|
|
|
{ backgroundColor: Colors.theme1[colorScheme].greenC8 + "1a" }, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
هزینه ارسال کالا پس از تعیین محل آدرس مشخص میشود |
|
|
|
|
</Text> |
|
|
|
|
<Ionicons |
|
|
|
|
name="alert-circle-outline" |
|
|
|
|
size={20} |
|
|
|
|
color={Colors.theme1[colorScheme].greenC8} |
|
|
|
|
/> |
|
|
|
|
</Pressable> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("mr-1"), |
|
|
|
|
{ |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
هزینه ارسال کالا پس از تعیین محل آدرس مشخص میشود |
|
|
|
|
</Text> |
|
|
|
|
<Ionicons |
|
|
|
|
name="alert-circle-outline" |
|
|
|
|
size={20} |
|
|
|
|
color={Colors.theme1[colorScheme].greenC8} |
|
|
|
|
/> |
|
|
|
|
</Pressable> |
|
|
|
|
|
|
|
|
|
<CustomPressable |
|
|
|
|
title={hasPhysical ? "ادامه فرایند خرید" : "پرداخت"} |
|
|
|
|
backgroundColor={Colors.theme1[colorScheme].greenCF} |
|
|
|
|
color={"white"} |
|
|
|
|
border={{ color: "#196EC0", width: 0 }} |
|
|
|
|
width={"100%"} |
|
|
|
|
onPress={() => |
|
|
|
|
isEmpty |
|
|
|
|
? asyncAwesomeAlert("خطا", "سبد خرید شما خالی است.", { |
|
|
|
|
showCancelButton: false, |
|
|
|
|
}) |
|
|
|
|
: hasPhysical ? navigation.push("DeliveryForm") : payFactor({userId}) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
</ScrollView> |
|
|
|
|
<CustomPressable |
|
|
|
|
title={hasPhysical ? "ادامه فرایند خرید" : "پرداخت"} |
|
|
|
|
backgroundColor={Colors.theme1[colorScheme].greenCF} |
|
|
|
|
color={"white"} |
|
|
|
|
border={{ color: "#196EC0", width: 0 }} |
|
|
|
|
width={"100%"} |
|
|
|
|
onPress={() => |
|
|
|
|
isEmpty |
|
|
|
|
? asyncAwesomeAlert("خطا", "سبد خرید شما خالی است.", { |
|
|
|
|
showCancelButton: false, |
|
|
|
|
}) |
|
|
|
|
: hasPhysical |
|
|
|
|
? navigation.push("DeliveryForm") |
|
|
|
|
: payFactor({ userId }) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
</ScrollView> |
|
|
|
|
) : ( |
|
|
|
|
<Empty |
|
|
|
|
text={"سبد خرید شما خالی است"} |
|
|
|
|
buttonText={"فروشگاه"} |
|
|
|
|
buttonAction={() => navigation.navigate("Products")} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
</SafeAreaView> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|