|
|
@ -1,12 +1,19 @@ |
|
|
|
import React from "react"; |
|
|
|
import React from "react"; |
|
|
|
import { connect } from "react-redux"; |
|
|
|
import { connect } from "react-redux"; |
|
|
|
import { userAddress, userFactor, publicApi } from "../../../../../redux/actions"; |
|
|
|
import { |
|
|
|
|
|
|
|
userAddress, |
|
|
|
|
|
|
|
userFactor, |
|
|
|
|
|
|
|
publicApi, |
|
|
|
|
|
|
|
menu, |
|
|
|
|
|
|
|
dialog, |
|
|
|
|
|
|
|
} from "../../../../../redux/actions"; |
|
|
|
import { Link, useNavigate } from "react-router-dom"; |
|
|
|
import { Link, useNavigate } from "react-router-dom"; |
|
|
|
|
|
|
|
|
|
|
|
//components
|
|
|
|
//components
|
|
|
|
import Empty from "../../../../../components/Empty"; |
|
|
|
import Empty from "../../../../../components/Empty"; |
|
|
|
import Button from "../../../../../components/Button"; |
|
|
|
import Button from "../../../../../components/Button"; |
|
|
|
import FloatingButton from "../../../../../components/FloatingButton"; |
|
|
|
import FloatingButton from "../../../../../components/FloatingButton"; |
|
|
|
|
|
|
|
import { add } from "lodash"; |
|
|
|
|
|
|
|
|
|
|
|
const ProfileAddress = ({ |
|
|
|
const ProfileAddress = ({ |
|
|
|
addresses, |
|
|
|
addresses, |
|
|
@ -20,21 +27,124 @@ const ProfileAddress = ({ |
|
|
|
mobile, |
|
|
|
mobile, |
|
|
|
isDark, |
|
|
|
isDark, |
|
|
|
headerOptions, |
|
|
|
headerOptions, |
|
|
|
setHeaderOptions |
|
|
|
setHeaderOptions, |
|
|
|
|
|
|
|
setMenu, |
|
|
|
|
|
|
|
menu, |
|
|
|
|
|
|
|
deleteAddress, |
|
|
|
|
|
|
|
setDialog, |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const navigation = useNavigate(); |
|
|
|
const navigation = useNavigate(); |
|
|
|
const Location = ({ address, active }) => { |
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
|
|
|
setHeaderOptions(headerOptions); |
|
|
|
|
|
|
|
getFactorInfo({ userId }); |
|
|
|
|
|
|
|
getList(); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<div className="flex-1 flex flex-col relative"> |
|
|
|
|
|
|
|
{addresses.length > 0 ? ( |
|
|
|
|
|
|
|
<div className="w-full mt-2 px-4"> |
|
|
|
|
|
|
|
<div className="p-0 m-0 flex flex-col"> |
|
|
|
|
|
|
|
{addresses.map((address, index) => ( |
|
|
|
|
|
|
|
<Location |
|
|
|
|
|
|
|
address={address} |
|
|
|
|
|
|
|
key={index} |
|
|
|
|
|
|
|
active={userAddressId === address?.id} |
|
|
|
|
|
|
|
isDark={isDark} |
|
|
|
|
|
|
|
userId={userId} |
|
|
|
|
|
|
|
update={update} |
|
|
|
|
|
|
|
setMenu={setMenu} |
|
|
|
|
|
|
|
menu={menu} |
|
|
|
|
|
|
|
deleteAddress={deleteAddress} |
|
|
|
|
|
|
|
setDialog={setDialog} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
))} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<Empty text="هیچ آدرسی ثبت نشده :(" /> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
<FloatingButton |
|
|
|
|
|
|
|
action={() => navigation("/createAddress")} |
|
|
|
|
|
|
|
position={{ bottom: 100, right: 16 }} |
|
|
|
|
|
|
|
size={16} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Location = ({ |
|
|
|
|
|
|
|
address, |
|
|
|
|
|
|
|
active, |
|
|
|
|
|
|
|
isDark, |
|
|
|
|
|
|
|
userId, |
|
|
|
|
|
|
|
update, |
|
|
|
|
|
|
|
setMenu, |
|
|
|
|
|
|
|
menu, |
|
|
|
|
|
|
|
deleteAddress, |
|
|
|
|
|
|
|
setDialog, |
|
|
|
|
|
|
|
}) => { |
|
|
|
|
|
|
|
const [locationMenu, setLocationMenu] = React.useState(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
|
|
|
if (locationMenu) { |
|
|
|
|
|
|
|
setMenu(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [locationMenu]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
|
|
|
if (!menu) { |
|
|
|
|
|
|
|
setLocationMenu(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [menu]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const delAddress = (id) => { |
|
|
|
|
|
|
|
setMenu(); |
|
|
|
|
|
|
|
setDialog({ |
|
|
|
|
|
|
|
text: "آدرس رو حذف کنیم؟", |
|
|
|
|
|
|
|
type: "confirm", |
|
|
|
|
|
|
|
accept: () => deleteAddress({ id }), |
|
|
|
|
|
|
|
open: true, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clickOnMenu = (e) => { |
|
|
|
|
|
|
|
setLocationMenu(true); |
|
|
|
|
|
|
|
e.stopPropagation(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div |
|
|
|
<div |
|
|
|
className={`bg-opacity-5 border border-solid flex flex-row items-center w-full px-3 py-2 rounded-md mt-2 ${ |
|
|
|
className={`bg-opacity-5 border border-solid flex flex-row items-center w-full px-3 py-2 rounded-md mt-2 relative ${ |
|
|
|
active ? "bg-blueC0 border-blueC0" : "bg-gray-300 border-gray-300" |
|
|
|
active ? "bg-blueC0 border-blueC0" : "bg-gray-300 border-gray-300" |
|
|
|
}`}
|
|
|
|
}`}
|
|
|
|
onClick={() => |
|
|
|
onClick={() => |
|
|
|
userAddressId === address?.id |
|
|
|
active ? {} : update({ userAddressId: address.id, userId }) |
|
|
|
? {} |
|
|
|
|
|
|
|
: update({ userAddressId: address.id, userId }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
> |
|
|
|
> |
|
|
|
|
|
|
|
<div |
|
|
|
|
|
|
|
className={`absolute left-8 top-0 transform transition-all origin-bottom-left ${ |
|
|
|
|
|
|
|
locationMenu ? "scale-100" : "scale-0" |
|
|
|
|
|
|
|
} -translate-y-1/2 bg-white roundd-md flex flex-col gap-1 p-1 shadow-all divide-y divide-solid divide-gray-200`}
|
|
|
|
|
|
|
|
style={{ zIndex: 70 }} |
|
|
|
|
|
|
|
onClick={(e) => e.stopPropagation()} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Link |
|
|
|
|
|
|
|
to={"/editAddress/" + address.id} |
|
|
|
|
|
|
|
className="py-3 pr-2 pl-10 text-sm font-bold" |
|
|
|
|
|
|
|
onClick={() => setMenu()} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
ویرایش |
|
|
|
|
|
|
|
</Link> |
|
|
|
|
|
|
|
<button |
|
|
|
|
|
|
|
className="py-3 pr-2 pl-10 border-none m-0 text-sm text-red19 font-bold" |
|
|
|
|
|
|
|
onClick={() => delAddress(address.id)} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
حذف |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div className={"flex flex-col flex-1 mr-2"}> |
|
|
|
<div className={"flex flex-col flex-1 mr-2"}> |
|
|
|
{active && ( |
|
|
|
{active && ( |
|
|
|
<div className={"w-full flex flex-row justify-between mb-3"}> |
|
|
|
<div className={"w-full flex flex-row justify-between mb-3"}> |
|
|
@ -44,7 +154,12 @@ const ProfileAddress = ({ |
|
|
|
</strong> |
|
|
|
</strong> |
|
|
|
<span className={"text-xs text-gray1 mr-2.5"}>فعال</span> |
|
|
|
<span className={"text-xs text-gray1 mr-2.5"}>فعال</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width={24} height={24}> |
|
|
|
<svg |
|
|
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg" |
|
|
|
|
|
|
|
width={24} |
|
|
|
|
|
|
|
height={24} |
|
|
|
|
|
|
|
onClick={(e) => clickOnMenu(e)} |
|
|
|
|
|
|
|
> |
|
|
|
<g fill="#07612c" data-name="vuesax/linear/more"> |
|
|
|
<g fill="#07612c" data-name="vuesax/linear/more"> |
|
|
|
<path d="M10 19a2 2 0 1 0 2-2 2.006 2.006 0 0 0-2 2Z" /> |
|
|
|
<path d="M10 19a2 2 0 1 0 2-2 2.006 2.006 0 0 0-2 2Z" /> |
|
|
|
<path |
|
|
|
<path |
|
|
@ -71,7 +186,12 @@ const ProfileAddress = ({ |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
{!active && ( |
|
|
|
{!active && ( |
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width={24} height={24}> |
|
|
|
<svg |
|
|
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg" |
|
|
|
|
|
|
|
width={24} |
|
|
|
|
|
|
|
height={24} |
|
|
|
|
|
|
|
onClick={(e) => clickOnMenu(e)} |
|
|
|
|
|
|
|
> |
|
|
|
<g fill={"#aaa"} data-name="vuesax/linear/more"> |
|
|
|
<g fill={"#aaa"} data-name="vuesax/linear/more"> |
|
|
|
<path d="M10 19a2 2 0 1 0 2-2 2.006 2.006 0 0 0-2 2Z" /> |
|
|
|
<path d="M10 19a2 2 0 1 0 2-2 2.006 2.006 0 0 0-2 2Z" /> |
|
|
|
<path |
|
|
|
<path |
|
|
@ -96,38 +216,6 @@ const ProfileAddress = ({ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
|
|
|
setHeaderOptions(headerOptions); |
|
|
|
|
|
|
|
getFactorInfo({ userId }); |
|
|
|
|
|
|
|
getList(); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<div className="flex-1 flex flex-col relative"> |
|
|
|
|
|
|
|
{addresses.length > 0 ? ( |
|
|
|
|
|
|
|
<div className="w-full mt-2 px-4"> |
|
|
|
|
|
|
|
<div className="p-0 m-0 flex "> |
|
|
|
|
|
|
|
{addresses.map((address, index) => ( |
|
|
|
|
|
|
|
<Location |
|
|
|
|
|
|
|
address={address} |
|
|
|
|
|
|
|
key={index} |
|
|
|
|
|
|
|
active={userAddressId === address?.id} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
))} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<Empty text="هیچ آدرسی ثبت نشده :(" /> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
<FloatingButton |
|
|
|
|
|
|
|
action={() => navigation("/createAddress")} |
|
|
|
|
|
|
|
position={{ bottom: 100, right: 16 }} |
|
|
|
|
|
|
|
size={16} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
const mapStateToProps = (state) => ({ |
|
|
@ -137,6 +225,7 @@ const mapStateToProps = (state) => ({ |
|
|
|
addresses: state.userAddress.list, |
|
|
|
addresses: state.userAddress.list, |
|
|
|
mobile: state.publicApi.mobile, |
|
|
|
mobile: state.publicApi.mobile, |
|
|
|
isDark: state.publicApi.isDark, |
|
|
|
isDark: state.publicApi.isDark, |
|
|
|
|
|
|
|
menu: state.menu.open, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
const mapDispatchToProps = { |
|
|
@ -144,6 +233,9 @@ const mapDispatchToProps = { |
|
|
|
update: userFactor.update, |
|
|
|
update: userFactor.update, |
|
|
|
getList: userAddress.list, |
|
|
|
getList: userAddress.list, |
|
|
|
setHeaderOptions: publicApi.setHeaderOptions, |
|
|
|
setHeaderOptions: publicApi.setHeaderOptions, |
|
|
|
|
|
|
|
setMenu: menu.set, |
|
|
|
|
|
|
|
deleteAddress: userAddress.del, |
|
|
|
|
|
|
|
setDialog: dialog.set, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ProfileAddress); |
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ProfileAddress); |
|
|
|