From ff830e7c6d6fbd768a91ed8f0e7be460656a6d29 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 30 Dec 2022 09:56:08 +0700 Subject: Address page --- src/components/Header.js | 4 +-- src/helpers/auth.js | 9 +------ src/pages/my/address/create.js | 58 ++++++++++++++++++++++++++++++++++++++++++ src/pages/my/address/index.js | 45 ++++++++++++++++++++++++++++++++ src/pages/my/menu.js | 6 ++--- src/pages/my/profile.js | 10 ++++---- src/pages/shop/checkout.js | 8 +++--- 7 files changed, 118 insertions(+), 22 deletions(-) create mode 100644 src/pages/my/address/create.js create mode 100644 src/pages/my/address/index.js diff --git a/src/components/Header.js b/src/components/Header.js index 99972307..7f08c2c3 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -12,7 +12,7 @@ import { } from "@heroicons/react/24/outline"; // Helpers -import { getAuth, useAuth } from "../helpers/auth"; +import { useAuth } from "../helpers/auth"; // Components import Link from "./Link"; // Images @@ -26,7 +26,7 @@ export default function Header({ title }) { const [suggestions, setSuggestions] = useState([]); const searchQueryRef = useRef(); const [isMenuActive, setIsMenuActive] = useState(false); - const [auth, setAuth] = useAuth(); + const [auth] = useAuth(); useEffect(() => { if (q) { diff --git a/src/helpers/auth.js b/src/helpers/auth.js index c09c7590..62eba2c0 100644 --- a/src/helpers/auth.js +++ b/src/helpers/auth.js @@ -20,14 +20,7 @@ const deleteAuth = () => { } const useAuth = () => { - const [auth, setAuth] = useState({ - id: '', - name: '', - email: '', - phone: '', - mobile: '', - token: '' - }); + const [auth, setAuth] = useState(null); useEffect(() => { const handleIsAuthenticated = () => setAuth(getAuth()); diff --git a/src/pages/my/address/create.js b/src/pages/my/address/create.js new file mode 100644 index 00000000..3f8de7b5 --- /dev/null +++ b/src/pages/my/address/create.js @@ -0,0 +1,58 @@ +import AppBar from "../../../components/AppBar"; +import Layout from "../../../components/Layout"; +import WithAuth from "../../../components/WithAuth"; + +export default function CreateAddress() { + return ( + + + + +
+ + + + + + + + + + + + +
+
+
+ ); +} \ No newline at end of file diff --git a/src/pages/my/address/index.js b/src/pages/my/address/index.js new file mode 100644 index 00000000..cac6e8f6 --- /dev/null +++ b/src/pages/my/address/index.js @@ -0,0 +1,45 @@ +import { useEffect, useState } from "react"; +import AppBar from "../../../components/AppBar"; +import Layout from "../../../components/Layout"; +import Link from "../../../components/Link"; +import WithAuth from "../../../components/WithAuth"; +import apiOdoo from "../../../helpers/apiOdoo"; +import { useAuth } from "../../../helpers/auth"; + +export default function Address() { + const [auth] = useAuth(); + const [addresses, setAddresses] = useState(null); + + useEffect(() => { + const getAddress = async () => { + if (auth) { + const dataAddress = await apiOdoo('GET', `/api/v1/user/${auth.id}/address`); + setAddresses(dataAddress); + } + }; + getAddress(); + }, [auth]); + + return ( + + + + +
+ Tambah Alamat +
+ +
+ { addresses && addresses.map((address, index) => ( +
+

{ address.name }

+

{ address.mobile }

+

{ address.street } { address.street2 }

+ +
+ )) } +
+
+
+ ) +} \ No newline at end of file diff --git a/src/pages/my/menu.js b/src/pages/my/menu.js index 84de3892..e21b0433 100644 --- a/src/pages/my/menu.js +++ b/src/pages/my/menu.js @@ -34,12 +34,12 @@ const serviceMenus = [ ]; const settingMenus = [ - { icon: (),name: 'Daftar Alamat', url: '/my/profile' }, + { icon: (),name: 'Daftar Alamat', url: '/my/address' }, { icon: (),name: 'Keluar Akun', url: '/logout' }, ]; export default function MyMenu() { - const [auth, setAuth] = useAuth(); + const [auth] = useAuth(); return ( <> @@ -52,7 +52,7 @@ export default function MyMenu() {
-

{ auth.name }

+

{ auth?.name }

Akun Bisnis
diff --git a/src/pages/my/profile.js b/src/pages/my/profile.js index be1a67b0..6e40230d 100644 --- a/src/pages/my/profile.js +++ b/src/pages/my/profile.js @@ -47,7 +47,7 @@ export default function MyProfile() {
- { auth?.id && ( + { auth && ( <> +
- +
) } { !editMode && (