From b72f69dea5e08eb680ec6c2e81c9131cc99c00d3 Mon Sep 17 00:00:00 2001 From: mahdi Date: Tue, 21 Jun 2022 15:54:33 +0430 Subject: [PATCH] address list fixed | 90 --- src/assets/icons/white-dropdown.svg | 2 +- src/views/Address/index.js | 16 +- .../Dashboard/layouts/Main/Addresses/index.js | 186 +++++++++++++----- .../layouts/Mobile/ProfileAddress/index.js | 7 +- src/views/DeliveryForm/Address/index.js | 4 +- 5 files changed, 149 insertions(+), 66 deletions(-) diff --git a/src/assets/icons/white-dropdown.svg b/src/assets/icons/white-dropdown.svg index 1af44c5..71323cd 100644 --- a/src/assets/icons/white-dropdown.svg +++ b/src/assets/icons/white-dropdown.svg @@ -1,6 +1,6 @@ - + diff --git a/src/views/Address/index.js b/src/views/Address/index.js index c23d643..c102d68 100644 --- a/src/views/Address/index.js +++ b/src/views/Address/index.js @@ -292,11 +292,12 @@ export const Address = ({ ); }; + console.log({ state: location?.state }); return (
@@ -330,7 +331,7 @@ export const Address = ({ onClick={() => submit()} /> - {/* */}
diff --git a/src/views/Dashboard/layouts/Main/Addresses/index.js b/src/views/Dashboard/layouts/Main/Addresses/index.js index d2373e4..026d632 100644 --- a/src/views/Dashboard/layouts/Main/Addresses/index.js +++ b/src/views/Dashboard/layouts/Main/Addresses/index.js @@ -1,16 +1,17 @@ import React from "react"; import { connect } from "react-redux"; -import { userAddress, userFactor } from "../../../../../redux/actions"; +import { + userAddress, + userFactor, + dialog, + menu, +} from "../../../../../redux/actions"; //components import Button from "../../../../../components/Button"; -import FloatingButton from "../../../../../components/FloatingButton"; import { Link, useNavigate } from "react-router-dom"; -//assets -import menuIcon from "./menu.svg"; - const ProfileAddress = ({ addresses, update, @@ -64,56 +65,142 @@ const ProfileAddress = ({ ); }; -const Location = ({ address, active, userId, isDark, update }) => { +const Location = ({ + address, + active, + userId, + isDark, + update, + setMenu, + setDialog, + deleteAddress, +}) => { + 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 ( - <> +
+ active ? {} : update({ userAddressId: address.id, userId }) + } + >
- active ? {} : update({ userAddressId: address.id, userId }) - } + 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()} > -
- {active && ( -
-
- آدرس انتخابی شما - فعال -
- -
- )} -
-
- - {"آدرس:" + " " + address.address} - - - {"نام:" + " " + address.firstName + " " + address.lastName} - - - {"کد پستی:" + " " + address.postalCode} - - - {"شماره تماس:" + " " + address.cellphone} - + setMenu()} + > + ویرایش + + +
+
+ {active && ( +
+
+ آدرس انتخابی شما + فعال
+ clickOnMenu(e)} + > + + + + +
-
- +
); }; @@ -129,6 +216,9 @@ const mapDispatchToProps = { getFactorInfo: userFactor.info, update: userFactor.update, getList: userAddress.list, + deleteAddress: userAddress.del, + setMenu: menu.set, + setDialog: dialog.set, }; export default connect(mapStateToProps, mapDispatchToProps)(ProfileAddress); diff --git a/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js b/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js index 041c90c..55a954c 100644 --- a/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js +++ b/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js @@ -15,6 +15,7 @@ import { Link, useNavigate } from "react-router-dom"; import Empty from "../../../../../components/Empty"; import Button from "../../../../../components/Button"; import FloatingButton from "../../../../../components/FloatingButton"; + import { add } from "lodash"; const ProfileAddress = ({ @@ -48,7 +49,7 @@ const ProfileAddress = ({
{addresses.length > 0 ? (
-
+
{addresses.map((address, index) => ( { const [locationMenu, setLocationMenu] = React.useState(false); @@ -118,7 +120,7 @@ const Location = ({ return (
@@ -225,6 +227,7 @@ const mapStateToProps = (state) => ({ loading: state.userFactor.loading, addresses: state.userAddress.list, mobile: state.publicApi.mobile, + isMobile: state.publicApi.isMobile, isDark: state.publicApi.isDark, menu: state.menu.open, }); diff --git a/src/views/DeliveryForm/Address/index.js b/src/views/DeliveryForm/Address/index.js index 1a97c34..de70352 100644 --- a/src/views/DeliveryForm/Address/index.js +++ b/src/views/DeliveryForm/Address/index.js @@ -125,7 +125,7 @@ function Address({ ); }; - + return isMobile ? (
@@ -158,7 +158,7 @@ function Address({ ) : (
انتخاب آدرس -
    +
      {addresses.map((address, index) => (