summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/Header.js4
-rw-r--r--src/helpers/auth.js9
-rw-r--r--src/pages/my/address/create.js58
-rw-r--r--src/pages/my/address/index.js45
-rw-r--r--src/pages/my/menu.js6
-rw-r--r--src/pages/my/profile.js10
-rw-r--r--src/pages/shop/checkout.js8
7 files changed, 118 insertions, 22 deletions
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 (
+ <WithAuth>
+ <Layout>
+ <AppBar title="Tambah Alamat" />
+
+ <form className="px-4">
+ <label className="form-label mt-4 mb-2">Nama Kontak</label>
+ <input
+ type="text"
+ className="form-input bg-gray_r-2"
+ placeholder="John Doe"
+ name="name"
+ />
+ <label className="form-label mt-4 mb-2">No. Handphone</label>
+ <input
+ type="tel"
+ className="form-input bg-gray_r-2"
+ placeholder="08xxxxxxxx"
+ name="mobile"
+ />
+ <label className="form-label mt-4 mb-2">Alamat</label>
+ <input
+ type="tel"
+ className="form-input bg-gray_r-2"
+ placeholder="Jl. Bandengan Utara"
+ name="street"
+ />
+ <label className="form-label mt-4 mb-2">Kota atau Kecamatan</label>
+ <input
+ type="tel"
+ className="form-input bg-gray_r-2"
+ placeholder="Kel. Penjaringan Kec. Penjaringan Kota Jakarta Utara"
+ name="street2"
+ />
+ <label className="form-label mt-4 mb-2">Kode Pos</label>
+ <input
+ type="tel"
+ className="form-input bg-gray_r-2"
+ placeholder="10100"
+ name="street2"
+ />
+
+ <button
+ type="button"
+ className="btn-yellow float-right mt-6 w-full"
+ >
+ Simpan
+ </button>
+ </form>
+ </Layout>
+ </WithAuth>
+ );
+} \ 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 (
+ <WithAuth>
+ <Layout>
+ <AppBar title="Daftar Alamat" />
+
+ <div className="text-right mt-4 px-4">
+ <Link href="/my/address/create">Tambah Alamat</Link>
+ </div>
+
+ <div className="grid gap-y-4 p-4">
+ { addresses && addresses.map((address, index) => (
+ <div className="p-4 rounded-md border border-gray_r-7" key={index}>
+ <p className="font-medium">{ address.name }</p>
+ <p className="mt-3 text-gray_r-11">{ address.mobile }</p>
+ <p className="mt-1 text-gray_r-11 leading-6">{ address.street } { address.street2 }</p>
+ <button className="btn-light mt-3 w-full">Ubah Alamat</button>
+ </div>
+ )) }
+ </div>
+ </Layout>
+ </WithAuth>
+ )
+} \ 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: (<MapIcon className="w-5" />),name: 'Daftar Alamat', url: '/my/profile' },
+ { icon: (<MapIcon className="w-5" />),name: 'Daftar Alamat', url: '/my/address' },
{ icon: (<ArrowRightOnRectangleIcon className="w-5" />),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() {
<UserIcon className="w-6" />
</div>
<div>
- <h2>{ auth.name }</h2>
+ <h2>{ auth?.name }</h2>
<div className="badge-red font-normal text-xs">Akun Bisnis</div>
</div>
</div>
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() {
<AppBar title="Akun Saya" />
<form onSubmit={update} className="w-full px-4">
- { auth?.id && (
+ { auth && (
<>
<label className="form-label mt-4 mb-2">Email</label>
<input
@@ -106,22 +106,22 @@ export default function MyProfile() {
) }
{ editMode && (
- <div className="flex justify-end gap-x-3">
+ <div className="flex gap-x-3">
<button
type="button"
- className="btn-light float-right mt-4"
+ className="btn-light flex-1 float-right mt-4"
onClick={cancelEdit}
>
Batal
</button>
- <button type="submit" className="btn-yellow float-right mt-4">Simpan</button>
+ <button type="submit" className="btn-yellow flex-1 float-right mt-4">Simpan</button>
</div>
) }
{ !editMode && (
<button
type="button"
- className="btn-light float-right mt-4"
+ className="btn-light float-right mt-4 w-full"
onClick={() => setEditMode(true)}
>
Ubah Profil
diff --git a/src/pages/shop/checkout.js b/src/pages/shop/checkout.js
index 286219c3..5a47dd5e 100644
--- a/src/pages/shop/checkout.js
+++ b/src/pages/shop/checkout.js
@@ -17,7 +17,7 @@ import { createSlug } from "../../helpers/slug";
export default function Checkout() {
- const [auth, setAuth] = useAuth();
+ const [auth] = useAuth();
const [address, setAddress] = useState(null);
const [selectedAddress, setSelectedAddress] = useState(null);
const [selectedPayment, setSelectedPayment] = useState(null);
@@ -34,7 +34,7 @@ export default function Checkout() {
useEffect(() => {
const getAddress = async () => {
- if (auth?.id) {
+ if (auth) {
const dataAddress = await apiOdoo('GET', `/api/v1/user/${auth.id}/address`);
setAddress(dataAddress);
}
@@ -145,9 +145,9 @@ export default function Checkout() {
/>
</div>
<div className="w-8/12 flex flex-col">
- <Link href={'/shop/product/' + createSlug(product.parent.name, product.parent.id)} className="product-card__title wrap-line-ellipsis-2">
+ <p className="product-card__title wrap-line-ellipsis-2">
{product.parent.name}
- </Link>
+ </p>
<p className="text-caption-2 text-gray_r-11 mt-1">
{product.code || '-'}
{product.attributes.length > 0 ? ` | ${product.attributes.join(', ')}` : ''}