From 5933732a74ae1ca4124ddd4e8265b1f443234736 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 21 Feb 2023 21:51:51 +0700 Subject: fix --- src/core/components/elements/Image/Image.jsx | 16 ++--- src/core/components/elements/Sidebar/Sidebar.jsx | 4 +- src/lib/transaction/components/Transaction.jsx | 79 +++++++++++++----------- src/lib/wishlist/api/wishlistsApi.js | 10 +++ src/lib/wishlist/components/Wishlists.jsx | 41 ++++++++++++ src/lib/wishlist/hooks/useWishlists.js | 14 +++++ src/pages/my/wishlist.jsx | 10 +++ 7 files changed, 129 insertions(+), 45 deletions(-) create mode 100644 src/lib/wishlist/api/wishlistsApi.js create mode 100644 src/lib/wishlist/components/Wishlists.jsx create mode 100644 src/lib/wishlist/hooks/useWishlists.js create mode 100644 src/pages/my/wishlist.jsx diff --git a/src/core/components/elements/Image/Image.jsx b/src/core/components/elements/Image/Image.jsx index 579660a4..a6f0b00c 100644 --- a/src/core/components/elements/Image/Image.jsx +++ b/src/core/components/elements/Image/Image.jsx @@ -2,13 +2,15 @@ import { LazyLoadImage } from "react-lazy-load-image-component" import "react-lazy-load-image-component/src/effects/opacity.css" const Image = ({ ...props }) => ( - + <> + + ) Image.defaultProps = LazyLoadImage.defaultProps diff --git a/src/core/components/elements/Sidebar/Sidebar.jsx b/src/core/components/elements/Sidebar/Sidebar.jsx index 88de1c1c..c840a688 100644 --- a/src/core/components/elements/Sidebar/Sidebar.jsx +++ b/src/core/components/elements/Sidebar/Sidebar.jsx @@ -44,8 +44,8 @@ const Sidebar = ({
{ !auth && ( <> - Daftar - Masuk + Daftar + Masuk ) } { auth && ( diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx index e049a9ac..0759dbf8 100644 --- a/src/lib/transaction/components/Transaction.jsx +++ b/src/lib/transaction/components/Transaction.jsx @@ -46,15 +46,6 @@ const Transaction = ({ id }) => { toast.error('Terjadi kesalahan internal, coba lagi nanti atau hubungi kami') } - const [ section, setSection ] = useState({ - customer: false, - invoice: false, - shipping: false - }) - const toggleSection = (name) => { - setSection({ ...section, [name]: !section[name] }) - } - const [ cancelTransaction, setCancelTransaction ] = useState(false) const openCancelTransaction = () => setCancelTransaction(true) const closeCancelTransaction = () => setCancelTransaction(false) @@ -142,33 +133,7 @@ const Transaction = ({ id }) => { - toggleSection('customer')} - /> - - { section.customer && } - - - - toggleSection('shipping')} - /> - - { section.shipping && } - - - - toggleSection('invoice')} - /> - - { section.invoice && } + @@ -288,6 +253,48 @@ const Transaction = ({ id }) => { ) } +const SectionAddress = ({ address }) => { + const [ section, setSection ] = useState({ + customer: false, + invoice: false, + shipping: false + }) + const toggleSection = (name) => { + setSection({ ...section, [name]: !section[name] }) + } + + return ( + <> + toggleSection('customer')} + /> + + { section.customer && } + + + + toggleSection('shipping')} + /> + + { section.shipping && } + + + + toggleSection('invoice')} + /> + { section.invoice && } + + ) +} + const SectionButton = ({ label, active, toggle }) => ( + diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx index e2a11390..0bd6137e 100644 --- a/src/pages/my/menu.jsx +++ b/src/pages/my/menu.jsx @@ -101,7 +101,7 @@ const MenuHeader = ({ children, ...props }) => ( ) const LinkItem = ({ children, ...props }) => ( - + { children }
-- cgit v1.2.3 From 98c8fc56db91664b98a50e9113787b56fe785b9e Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 21 Feb 2023 22:33:32 +0700 Subject: fix --- src/core/utils/address.js | 31 ++++++++++++ src/lib/address/api/addressesApi.js | 10 ++++ src/lib/address/components/Addresses.jsx | 68 ++++++++++++++++++++++++++ src/lib/address/hooks/useAddresses.js | 13 +++++ src/lib/invoice/components/Invoice.jsx | 2 +- src/lib/transaction/components/Transaction.jsx | 2 +- src/lib/wishlist/components/Wishlists.jsx | 12 +++-- src/pages/my/address/index.jsx | 10 ++++ src/pages/my/menu.jsx | 2 +- 9 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 src/core/utils/address.js create mode 100644 src/lib/address/api/addressesApi.js create mode 100644 src/lib/address/components/Addresses.jsx create mode 100644 src/lib/address/hooks/useAddresses.js create mode 100644 src/pages/my/address/index.jsx diff --git a/src/core/utils/address.js b/src/core/utils/address.js new file mode 100644 index 00000000..b89dd924 --- /dev/null +++ b/src/core/utils/address.js @@ -0,0 +1,31 @@ +const getAddress = () => { + if (typeof window !== 'undefined') { + const address = localStorage.getItem('address') + if (address) return JSON.parse(address) + } + return {} +} + +const setAddress = (address) => { + if (typeof window !== 'undefined') { + localStorage.setItem('address', JSON.stringify(address)) + } + return +} + +const getItemAddress = (key) => { + let address = getAddress() + return address[key] +} + +const updateItemAddress = (key, value) => { + let address = getAddress() + address[key] = value + setAddress(address) + return +} + +export { + getItemAddress, + updateItemAddress +} \ No newline at end of file diff --git a/src/lib/address/api/addressesApi.js b/src/lib/address/api/addressesApi.js new file mode 100644 index 00000000..1edfc077 --- /dev/null +++ b/src/lib/address/api/addressesApi.js @@ -0,0 +1,10 @@ +import odooApi from "@/core/api/odooApi" +import { getAuth } from "@/core/utils/auth" + +const addressesApi = async () => { + const auth = getAuth() + const dataAddresses = await odooApi('GET', `/api/v1/user/${auth.id}/address`) + return dataAddresses +} + +export default addressesApi \ No newline at end of file diff --git a/src/lib/address/components/Addresses.jsx b/src/lib/address/components/Addresses.jsx new file mode 100644 index 00000000..7a82c0da --- /dev/null +++ b/src/lib/address/components/Addresses.jsx @@ -0,0 +1,68 @@ +import Link from "@/core/components/elements/Link/Link" +import Spinner from "@/core/components/elements/Spinner/Spinner" +import useAuth from "@/core/hooks/useAuth" +import { getItemAddress, updateItemAddress } from "@/core/utils/address" +import { useRouter } from "next/router" +import useAddresses from "../hooks/useAddresses" + +const Addresses = () => { + const router = useRouter() + const { + select = null + } = router.query + const auth = useAuth() + const { addresses } = useAddresses() + const selectedAdress = getItemAddress(select || '') + const changeSelectedAddress = (id) => { + if (!select) return + updateItemAddress(select, id) + router.back() + } + + if (addresses.isLoading) { + return ( +
+ +
+ ) + } + + return ( +
+
+ Tambah Alamat +
+ +
+ { addresses.data?.map((address, index) => { + let type = address.type.charAt(0).toUpperCase() + address.type.slice(1) + ' Address'; + return ( +
+
changeSelectedAddress(address.id)}> +
+
{ type }
+ { auth?.partnerId == address.id && ( +
Utama
+ ) } +
+

{ address.name }

+ { address.mobile && ( +

{ address.mobile }

+ ) } +

+ { address.street } +

+
+ Ubah Alamat +
+ ); + }) } +
+
+ ) +} + +export default Addresses \ No newline at end of file diff --git a/src/lib/address/hooks/useAddresses.js b/src/lib/address/hooks/useAddresses.js new file mode 100644 index 00000000..9968d790 --- /dev/null +++ b/src/lib/address/hooks/useAddresses.js @@ -0,0 +1,13 @@ +import { useQuery } from "react-query" +import addressesApi from "../api/addressesApi" + +const useAddresses = () => { + const fetchAddresses = async () => await addressesApi() + const { data, isLoading } = useQuery('addresses', fetchAddresses) + + return { + addresses: { data, isLoading } + } +} + +export default useAddresses \ No newline at end of file diff --git a/src/lib/invoice/components/Invoice.jsx b/src/lib/invoice/components/Invoice.jsx index 3e0baaee..aee4a498 100644 --- a/src/lib/invoice/components/Invoice.jsx +++ b/src/lib/invoice/components/Invoice.jsx @@ -10,7 +10,7 @@ const Invoice = ({ id }) => { if (invoice.isLoading) { return ( -
+
) diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx index 0759dbf8..0017afba 100644 --- a/src/lib/transaction/components/Transaction.jsx +++ b/src/lib/transaction/components/Transaction.jsx @@ -70,7 +70,7 @@ const Transaction = ({ id }) => { if (transaction.isLoading) { return ( -
+
) diff --git a/src/lib/wishlist/components/Wishlists.jsx b/src/lib/wishlist/components/Wishlists.jsx index 8a456a8d..4bb63933 100644 --- a/src/lib/wishlist/components/Wishlists.jsx +++ b/src/lib/wishlist/components/Wishlists.jsx @@ -15,16 +15,22 @@ const Wishlists = () => { const pageCount = Math.ceil(wishlists.data?.productTotal / limit) + if (wishlists.isLoading) { + return ( +
+ +
+ ) + } + return (
- { wishlists.isLoading && ( - - ) } { wishlists.data?.products?.length == 0 && ( Wishlist anda masih kosong ) } +
{wishlists.data?.products.map((product) => ( diff --git a/src/pages/my/address/index.jsx b/src/pages/my/address/index.jsx new file mode 100644 index 00000000..29e21c30 --- /dev/null +++ b/src/pages/my/address/index.jsx @@ -0,0 +1,10 @@ +import AppLayout from "@/core/components/layouts/AppLayout" +import AddressesComponent from "@/lib/address/components/Addresses" + +export default function Addresses() { + return ( + + + + ) +} \ No newline at end of file diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx index 0bd6137e..2ae00722 100644 --- a/src/pages/my/menu.jsx +++ b/src/pages/my/menu.jsx @@ -77,7 +77,7 @@ export default function Menu() {
- + Daftar Alamat -- cgit v1.2.3 From 036e72780ddb7a510795b329919ff9dd957af6d7 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 21 Feb 2023 22:38:25 +0700 Subject: fix --- src/core/components/elements/Sidebar/Sidebar.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/components/elements/Sidebar/Sidebar.jsx b/src/core/components/elements/Sidebar/Sidebar.jsx index c840a688..48ceacf6 100644 --- a/src/core/components/elements/Sidebar/Sidebar.jsx +++ b/src/core/components/elements/Sidebar/Sidebar.jsx @@ -1,8 +1,8 @@ import Link from "../Link/Link" import greeting from "@/core/utils/greeting" -import { Cog6ToothIcon } from "@heroicons/react/24/solid" import useAuth from "@/core/hooks/useAuth" import { AnimatePresence, motion } from "framer-motion" +import { CogIcon } from "@heroicons/react/24/outline" const Sidebar = ({ active, @@ -61,7 +61,7 @@ const Sidebar = ({ href="/my/menu" className="!text-gray_r-11 ml-auto my-auto" > - + ) } -- cgit v1.2.3