|
|
|
@ -2,7 +2,10 @@ import React, { useEffect } from "react"; |
|
|
|
|
import separate from "../../../utils/separate"; |
|
|
|
|
import { connect } from "react-redux"; |
|
|
|
|
import { transport } from "../../../redux/actions"; |
|
|
|
|
|
|
|
|
|
//components
|
|
|
|
|
import Loading from "../../../components/Loading"; |
|
|
|
|
import ButtonBetween from "../../../components/ButtonBetween"; |
|
|
|
|
|
|
|
|
|
function TransportMethod({ |
|
|
|
|
list, |
|
|
|
@ -13,23 +16,18 @@ function TransportMethod({ |
|
|
|
|
userId, |
|
|
|
|
loading, |
|
|
|
|
}) { |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (list.length === 0) { |
|
|
|
|
getList(); |
|
|
|
|
} |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
const Method = ({ method }) => { |
|
|
|
|
const Method = ({ method, active }) => { |
|
|
|
|
return isMobile ? ( |
|
|
|
|
<button |
|
|
|
|
className={`flex flex-col border-2 border-solid items-center w-full px-2 py-2 rounded-md mt-4 relative transition-all duration-500 ${ |
|
|
|
|
factorInfo?.transportId === method?.id |
|
|
|
|
? "bg-blueC0 border-blueC0 bg-opacity-5 dark:bg-opacity-5" |
|
|
|
|
: "bg-grayF9 border-gray-200 dark:border-gray-500 dark:bg-opacity-5" |
|
|
|
|
}`}
|
|
|
|
|
<ButtonBetween |
|
|
|
|
width={"100%"} |
|
|
|
|
onClick={() => |
|
|
|
|
factorInfo?.transportId !== method?.id |
|
|
|
|
!active |
|
|
|
|
? setTransport( |
|
|
|
|
{ factorId: factorInfo?.id, transportId: method?.id }, |
|
|
|
|
{ userId }, |
|
|
|
@ -37,42 +35,11 @@ function TransportMethod({ |
|
|
|
|
) |
|
|
|
|
: {} |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
{loading && factorInfo?.transportId !== method?.id ? ( |
|
|
|
|
<Loading |
|
|
|
|
size={2} |
|
|
|
|
color={ |
|
|
|
|
factorInfo?.transportId === method?.id |
|
|
|
|
? "bg-green-500" |
|
|
|
|
: "bg-gray-500" |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
) : ( |
|
|
|
|
<strong |
|
|
|
|
className={`text-tiny transition-all duration-500 ${ |
|
|
|
|
factorInfo?.transportId === method?.id |
|
|
|
|
? "text-green7B dark:text-blueC0" |
|
|
|
|
: "text-blue52 dark:text-gray-400" |
|
|
|
|
}`}
|
|
|
|
|
> |
|
|
|
|
{method.name} |
|
|
|
|
</strong> |
|
|
|
|
)} |
|
|
|
|
<span |
|
|
|
|
className={`lg:text-xs text-tiny mt-2 transition-all duration-500 ${ |
|
|
|
|
factorInfo?.transportId === method?.id |
|
|
|
|
? "text-green7B dark:text-blueC0" |
|
|
|
|
: "text-blue52 dark:text-gray-400" |
|
|
|
|
}`}
|
|
|
|
|
> |
|
|
|
|
هزینه ارسال {separate(method.price)} |
|
|
|
|
</span> |
|
|
|
|
{/* <img |
|
|
|
|
src={method.icon} |
|
|
|
|
alt={method.name} |
|
|
|
|
className="w-7 absolute left-3 top-1/2 transform -translate-y-1/2" |
|
|
|
|
/> */} |
|
|
|
|
</button> |
|
|
|
|
item={"ارسال با" + " " + method.name} |
|
|
|
|
status={separate(method.price) + " " + "تومان"} |
|
|
|
|
active={active} |
|
|
|
|
toggle={true} |
|
|
|
|
/> |
|
|
|
|
) : ( |
|
|
|
|
<button |
|
|
|
|
className={`flex flex-col border border-solid items-center px-2 py-3 rounded-md mt-4 relative transition-all duration-500 w-2/5 ${ |
|
|
|
@ -81,7 +48,7 @@ function TransportMethod({ |
|
|
|
|
: "bg-grayF9 border-grayDB dark:bg-opacity-5" |
|
|
|
|
}`}
|
|
|
|
|
onClick={() => |
|
|
|
|
factorInfo?.transportId !== method?.id |
|
|
|
|
!active |
|
|
|
|
? setTransport( |
|
|
|
|
{ factorId: factorInfo?.id, transportId: method?.id }, |
|
|
|
|
{ userId }, |
|
|
|
@ -90,19 +57,12 @@ function TransportMethod({ |
|
|
|
|
: {} |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
{loading && factorInfo?.transportId !== method?.id ? ( |
|
|
|
|
<Loading |
|
|
|
|
size={4} |
|
|
|
|
color={ |
|
|
|
|
factorInfo?.transportId === method?.id |
|
|
|
|
? "bg-green-500" |
|
|
|
|
: "bg-gray-500" |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
{loading && !active ? ( |
|
|
|
|
<Loading size={4} color={active ? "bg-green-500" : "bg-gray-500"} /> |
|
|
|
|
) : ( |
|
|
|
|
<strong |
|
|
|
|
className={`text-tiny transition-all duration-500 ${ |
|
|
|
|
factorInfo?.transportId === method?.id |
|
|
|
|
active |
|
|
|
|
? "text-green7B dark:text-white" |
|
|
|
|
: "text-blue52 dark:text-white" |
|
|
|
|
}`}
|
|
|
|
@ -113,7 +73,7 @@ function TransportMethod({ |
|
|
|
|
|
|
|
|
|
<span |
|
|
|
|
className={`text-sm transition-all duration-500 mt-2 ${ |
|
|
|
|
factorInfo?.transportId === method?.id |
|
|
|
|
active |
|
|
|
|
? "text-green7B dark:text-white" |
|
|
|
|
: "text-blue52 dark:text-white" |
|
|
|
|
}`}
|
|
|
|
@ -128,9 +88,13 @@ function TransportMethod({ |
|
|
|
|
<strong className="text-green7B font-bold dark:text-white text-base"> |
|
|
|
|
لطفا یک روش ارسال انتخاب کنید |
|
|
|
|
</strong> |
|
|
|
|
<ul className="list-none p-0 m-0 flex flex-col w-full"> |
|
|
|
|
<ul className="list-none p-0 m-0 flex flex-col gap-4 w-full mt-5"> |
|
|
|
|
{list.map((method, index) => ( |
|
|
|
|
<Method method={method} key={index} /> |
|
|
|
|
<Method |
|
|
|
|
method={method} |
|
|
|
|
key={index} |
|
|
|
|
active={factorInfo?.transportId === method?.id} |
|
|
|
|
/> |
|
|
|
|
))} |
|
|
|
|
</ul> |
|
|
|
|
</section> |
|
|
|
@ -141,7 +105,11 @@ function TransportMethod({ |
|
|
|
|
</strong> |
|
|
|
|
<ul className="list-none p-0 m-0 flex flex-row gap-5 flex-wrap"> |
|
|
|
|
{list.map((method, index) => ( |
|
|
|
|
<Method method={method} key={index} /> |
|
|
|
|
<Method |
|
|
|
|
method={method} |
|
|
|
|
key={index} |
|
|
|
|
active={factorInfo?.transportId === method?.id} |
|
|
|
|
/> |
|
|
|
|
))} |
|
|
|
|
</ul> |
|
|
|
|
</section> |
|
|
|
|