|
|
@ -1,4 +1,4 @@ |
|
|
|
import React, { useState, useEffect } from "react"; |
|
|
|
import React, { useState, useEffect, useMemo, useCallback } from "react"; |
|
|
|
import { |
|
|
|
import { |
|
|
|
userProduct, |
|
|
|
userProduct, |
|
|
|
userFactor, |
|
|
|
userFactor, |
|
|
@ -24,7 +24,6 @@ import { connect } from "react-redux"; |
|
|
|
function ShoppingCart({ |
|
|
|
function ShoppingCart({ |
|
|
|
isDark, |
|
|
|
isDark, |
|
|
|
isMobile, |
|
|
|
isMobile, |
|
|
|
list, |
|
|
|
|
|
|
|
factorInfo, |
|
|
|
factorInfo, |
|
|
|
user, |
|
|
|
user, |
|
|
|
getList, |
|
|
|
getList, |
|
|
@ -37,11 +36,11 @@ function ShoppingCart({ |
|
|
|
loading, |
|
|
|
loading, |
|
|
|
setDialog, |
|
|
|
setDialog, |
|
|
|
isLogin, |
|
|
|
isLogin, |
|
|
|
|
|
|
|
useless, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
const [phase, setPhase] = useState("products"); |
|
|
|
const [phase, setPhase] = useState("products"); |
|
|
|
const navigation = useNavigate(); |
|
|
|
const navigation = useNavigate(); |
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
console.log("gl1") |
|
|
|
|
|
|
|
if (isLogin) getList(); |
|
|
|
if (isLogin) getList(); |
|
|
|
getFactorInfo({ userId: user?.id }); |
|
|
|
getFactorInfo({ userId: user?.id }); |
|
|
|
setHeaderOptions(headerOptions); |
|
|
|
setHeaderOptions(headerOptions); |
|
|
@ -53,14 +52,15 @@ function ShoppingCart({ |
|
|
|
} |
|
|
|
} |
|
|
|
}, [phase]); |
|
|
|
}, [phase]); |
|
|
|
|
|
|
|
|
|
|
|
const productsLength = userProducts?.filter( |
|
|
|
const productsLength = useMemo(() => { |
|
|
|
(product) => product.condition < 2 |
|
|
|
return userProducts?.filter((product) => product.condition < 2)?.length; |
|
|
|
)?.length; |
|
|
|
}, [userProducts]); |
|
|
|
|
|
|
|
|
|
|
|
const next = { |
|
|
|
const next = useMemo(() => { |
|
|
|
|
|
|
|
return { |
|
|
|
products: () => |
|
|
|
products: () => |
|
|
|
productsLength |
|
|
|
productsLength |
|
|
|
? userProducts.filter((object) => object.productType === 2).length > 0 |
|
|
|
? userProducts.filter((object) => object.productType === 2)?.length |
|
|
|
? setPhase("deliveryForm") |
|
|
|
? setPhase("deliveryForm") |
|
|
|
: setDialog({ |
|
|
|
: setDialog({ |
|
|
|
type: "confirm", |
|
|
|
type: "confirm", |
|
|
@ -81,8 +81,9 @@ function ShoppingCart({ |
|
|
|
console.log("Go to shaparak"); |
|
|
|
console.log("Go to shaparak"); |
|
|
|
}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
}, [userProducts, user]); |
|
|
|
|
|
|
|
|
|
|
|
const Table = () => { |
|
|
|
const Table = React.useCallback(() => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="w-full flex flex-col"> |
|
|
|
<div className="w-full flex flex-col"> |
|
|
|
<header className="w-full flex gap-10"> |
|
|
|
<header className="w-full flex gap-10"> |
|
|
@ -94,11 +95,11 @@ function ShoppingCart({ |
|
|
|
</strong> |
|
|
|
</strong> |
|
|
|
</header> |
|
|
|
</header> |
|
|
|
<ul className="w-full mt-2 list-none p-0"> |
|
|
|
<ul className="w-full mt-2 list-none p-0"> |
|
|
|
{list |
|
|
|
{userProducts |
|
|
|
.sort((a, b) => a?.id - b?.id) |
|
|
|
?.sort((a, b) => a?.id - b?.id) |
|
|
|
.map( |
|
|
|
?.map( |
|
|
|
(product, index) => |
|
|
|
(product, index) => |
|
|
|
product.condition < 2 && ( |
|
|
|
product?.condition < 2 && ( |
|
|
|
<Product loading={loading} key={index} product={product} /> |
|
|
|
<Product loading={loading} key={index} product={product} /> |
|
|
|
) |
|
|
|
) |
|
|
|
)} |
|
|
|
)} |
|
|
@ -108,11 +109,13 @@ function ShoppingCart({ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}, [userProducts]); |
|
|
|
|
|
|
|
|
|
|
|
const PriceStatus = ({ name, value, type }) => { |
|
|
|
const PriceStatus = useCallback( |
|
|
|
return isMobile ? ( |
|
|
|
({ name, value, type }) => { |
|
|
|
<div className="w-full flex justify-between py-3"> |
|
|
|
return ( |
|
|
|
|
|
|
|
<React.Fragment> |
|
|
|
|
|
|
|
<div className="w-full flex lg:hidden justify-between py-3"> |
|
|
|
<strong className="font-semibold text-tiny dark:text-white text-blue5F"> |
|
|
|
<strong className="font-semibold text-tiny dark:text-white text-blue5F"> |
|
|
|
{name} |
|
|
|
{name} |
|
|
|
</strong> |
|
|
|
</strong> |
|
|
@ -137,11 +140,11 @@ function ShoppingCart({ |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) : ( |
|
|
|
<div className="w-full hidden lg:flex justify-between py-4"> |
|
|
|
<div className="w-full flex justify-between py-4"> |
|
|
|
|
|
|
|
<strong className="font-semibold text-tiny dark:text-white text-blue5F"> |
|
|
|
<strong className="font-semibold text-tiny dark:text-white text-blue5F"> |
|
|
|
{name} |
|
|
|
{name} |
|
|
|
</strong> |
|
|
|
</strong> |
|
|
|
|
|
|
|
{value ? ( |
|
|
|
<span |
|
|
|
<span |
|
|
|
className="font-medium text-lg dark:text-white" |
|
|
|
className="font-medium text-lg dark:text-white" |
|
|
|
style={{ |
|
|
|
style={{ |
|
|
@ -162,14 +165,19 @@ function ShoppingCart({ |
|
|
|
تومان |
|
|
|
تومان |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
|
|
|
|
) : null} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
</React.Fragment> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
[useless] |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const layouts = { |
|
|
|
const layouts = useMemo(() => { |
|
|
|
|
|
|
|
return { |
|
|
|
products: isMobile ? ( |
|
|
|
products: isMobile ? ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
{list |
|
|
|
{userProducts |
|
|
|
.sort((a, b) => a?.id - b?.id) |
|
|
|
.sort((a, b) => a?.id - b?.id) |
|
|
|
.map( |
|
|
|
.map( |
|
|
|
(product, index) => |
|
|
|
(product, index) => |
|
|
@ -187,11 +195,11 @@ function ShoppingCart({ |
|
|
|
buttonText="فروشگاه" |
|
|
|
buttonText="فروشگاه" |
|
|
|
buttonAction={() => navigation("/products")} |
|
|
|
buttonAction={() => navigation("/products")} |
|
|
|
/> |
|
|
|
/> |
|
|
|
// <strong className="text-blueC0">سبد خرید شما خالی است.</strong>
|
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
deliveryForm: <DeliveryForm setPhase={setPhase} />, |
|
|
|
deliveryForm: <DeliveryForm setPhase={setPhase} />, |
|
|
|
address: <Address setPhase={setPhase} />, |
|
|
|
address: <Address setPhase={setPhase} />, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
}, [isMobile, userProducts, loading]); |
|
|
|
|
|
|
|
|
|
|
|
return isMobile ? ( |
|
|
|
return isMobile ? ( |
|
|
|
<div className="w-full flex flex-col px-4 pb-24"> |
|
|
|
<div className="w-full flex flex-col px-4 pb-24"> |
|
|
@ -221,11 +229,13 @@ function ShoppingCart({ |
|
|
|
<strong className="font-bold text-tiny text-blue5F dark:text-white"> |
|
|
|
<strong className="font-bold text-tiny text-blue5F dark:text-white"> |
|
|
|
جمع کل سبد خرید |
|
|
|
جمع کل سبد خرید |
|
|
|
</strong> |
|
|
|
</strong> |
|
|
|
|
|
|
|
{factorInfo?.payFactor ? ( |
|
|
|
<p className="font-medium text-greenBA text-lg dark:text-white"> |
|
|
|
<p className="font-medium text-greenBA text-lg dark:text-white"> |
|
|
|
{separate(productsLength ? factorInfo?.payPrice : 0) + |
|
|
|
{separate(factorInfo?.payPrice) + |
|
|
|
" " + |
|
|
|
" " + |
|
|
|
"تومان"} |
|
|
|
"تومان"} |
|
|
|
</p> |
|
|
|
</p> |
|
|
|
|
|
|
|
) : null} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div |
|
|
|
<div |
|
|
|
className="w-full rounded-md flex justify-center items-center py-2.5 px-3 mt-5 mb-4" |
|
|
|
className="w-full rounded-md flex justify-center items-center py-2.5 px-3 mt-5 mb-4" |
|
|
@ -276,8 +286,7 @@ function ShoppingCart({ |
|
|
|
}`}
|
|
|
|
}`}
|
|
|
|
> |
|
|
|
> |
|
|
|
<div className="flex flex-col flex-1">{layouts[phase]}</div> |
|
|
|
<div className="flex flex-col flex-1">{layouts[phase]}</div> |
|
|
|
{console.log(list)} |
|
|
|
{userProducts?.filter((product) => product?.condition < 2)?.length |
|
|
|
{list?.filter((product) => product?.condition < 2)?.length |
|
|
|
|
|
|
|
? phase !== "address" && ( |
|
|
|
? phase !== "address" && ( |
|
|
|
<div |
|
|
|
<div |
|
|
|
className="flex flex-col w-1/4 p-10 bg-white shadow-all rounded-md px-4 py-4" |
|
|
|
className="flex flex-col w-1/4 p-10 bg-white shadow-all rounded-md px-4 py-4" |
|
|
@ -286,17 +295,21 @@ function ShoppingCart({ |
|
|
|
<div className="flex flex-col w-full border-t py-2 border-gray-300 border-b"> |
|
|
|
<div className="flex flex-col w-full border-t py-2 border-gray-300 border-b"> |
|
|
|
<PriceStatus |
|
|
|
<PriceStatus |
|
|
|
name="مبلغ سبد خرید" |
|
|
|
name="مبلغ سبد خرید" |
|
|
|
value={productsLength ? factorInfo?.sumPrice : ""} |
|
|
|
value={factorInfo?.sumPrice ? factorInfo?.sumPrice : " "} |
|
|
|
type="normal" |
|
|
|
type="normal" |
|
|
|
/> |
|
|
|
/> |
|
|
|
<PriceStatus |
|
|
|
<PriceStatus |
|
|
|
name="هزینه حمل و نقل" |
|
|
|
name="هزینه حمل و نقل" |
|
|
|
value={productsLength ? factorInfo?.transportPrice : 0} |
|
|
|
value={ |
|
|
|
|
|
|
|
factorInfo?.transportPrice |
|
|
|
|
|
|
|
? factorInfo?.transportPrice |
|
|
|
|
|
|
|
: " " |
|
|
|
|
|
|
|
} |
|
|
|
type="error" |
|
|
|
type="error" |
|
|
|
/> |
|
|
|
/> |
|
|
|
<PriceStatus |
|
|
|
<PriceStatus |
|
|
|
name="میزان تخفیف" |
|
|
|
name="میزان تخفیف" |
|
|
|
value={productsLength ? factorInfo?.offPrice : ""} |
|
|
|
value={factorInfo?.offPrice ? factorInfo?.offPrice : " "} |
|
|
|
type="error" |
|
|
|
type="error" |
|
|
|
/> |
|
|
|
/> |
|
|
|
{/* <PriceStatus |
|
|
|
{/* <PriceStatus |
|
|
@ -398,7 +411,6 @@ function ShoppingCart({ |
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
isDark: state.publicApi.isDark, |
|
|
|
isDark: state.publicApi.isDark, |
|
|
|
isMobile: state.publicApi.isMobile, |
|
|
|
isMobile: state.publicApi.isMobile, |
|
|
|
list: state.userProduct.list, |
|
|
|
|
|
|
|
payPrice: state.userProduct.sum, |
|
|
|
payPrice: state.userProduct.sum, |
|
|
|
factorInfo: state.userFactor.info, |
|
|
|
factorInfo: state.userFactor.info, |
|
|
|
user: state.user.status, |
|
|
|
user: state.user.status, |
|
|
|