From d19b40f2972cc74105cfb8390a3b0fe3a4695b3a Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 17 Nov 2022 17:30:03 +0700 Subject: Login process to Odoo Api --- src/components/Header.js | 42 ++++++++++++++++++++++++--------- src/pages/_app.js | 10 ++++++++ src/pages/api/login.js | 17 ++++++++++++++ src/pages/index.js | 10 ++++---- src/pages/login.js | 51 +++++++++++++++++++++++++++++++++------- src/pages/register.js | 6 ++--- src/pages/shop/product/[slug].js | 6 ++--- src/styles/globals.css | 7 +++--- 8 files changed, 116 insertions(+), 33 deletions(-) create mode 100644 src/pages/api/login.js (limited to 'src') diff --git a/src/components/Header.js b/src/components/Header.js index fb0e56a1..3e9d7ea0 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -8,6 +8,7 @@ import { useEffect, useRef, useState } from "react"; import Head from "next/head"; import Logo from "../images/logo.png"; import { useRouter } from "next/router"; +import { getAuth } from "../helpers/auth"; export default function Header({ title }) { @@ -16,6 +17,11 @@ export default function Header({ title }) { const [searchQuery, setSearchQuery] = useState(q); const searchQueryRef = useRef(); const [isMenuActive, setIsMenuActive] = useState(false); + const [auth, setAuth] = useState(); + + useEffect(() => { + if (!auth) setAuth(getAuth()) + }, [auth]); useEffect(() => { if (q) searchQueryRef.current.blur(); @@ -35,25 +41,39 @@ export default function Header({ title }) { {title} -
-
- Masuk - Daftar +
+
+ {auth ? ( +

Hi, {auth.name}

+ ) : ( + <> + Masuk + Daftar + + )}
-
- - Brand +
+ {auth ? ( + + Profil Saya +
+ +
+ + ) : ''} + + Semua Brand
- - Blog + + Blog Indoteknik
- +

Belum punya akun Indoteknik? Daftar

diff --git a/src/pages/register.js b/src/pages/register.js index 86208dc0..38ea972f 100644 --- a/src/pages/register.js +++ b/src/pages/register.js @@ -9,11 +9,11 @@ export default function Login() { Daftar - Indoteknik -
+
Logo Indoteknik -

Mudahkan Pembelian dengan Indoteknik

+

Mudahkan Pembelian dengan Indoteknik

Daftar untuk melanjutkan

Sudah punya akun Indoteknik? Masuk

diff --git a/src/pages/shop/product/[slug].js b/src/pages/shop/product/[slug].js index f96aba34..bcbebbdf 100644 --- a/src/pages/shop/product/[slug].js +++ b/src/pages/shop/product/[slug].js @@ -2,7 +2,7 @@ import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import Header from "../../../components/Header"; -import { getOdoo } from "../../../helpers/apiOdoo"; +import apiOdoo from "../../../helpers/apiOdoo"; import { createSlug, getId } from "../../../helpers/slug"; import currencyFormat from "../../../helpers/currencyFormat"; import { LazyLoadImage } from "react-lazy-load-image-component"; @@ -11,7 +11,7 @@ import ProductSlider from "../../../components/product/ProductSlider"; export async function getServerSideProps(context) { const { slug } = context.query; - let product = await getOdoo('/api/v1/product/' + getId(slug)); + let product = await apiOdoo('GET', '/api/v1/product/' + getId(slug)); if (product.length == 1) { product = product[0]; } @@ -42,7 +42,7 @@ export default function ProductDetail({product}) { useEffect(() => { setSimilarProducts(null); const getSimilarProducts = async () => { - const dataSimilarProducts = await getOdoo(`/api/v1/product/${getId(slug)}/similar?limit=20`); + const dataSimilarProducts = await apiOdoo('GET', `/api/v1/product/${getId(slug)}/similar?limit=20`); setSimilarProducts(dataSimilarProducts); } getSimilarProducts(); diff --git a/src/styles/globals.css b/src/styles/globals.css index 6ed6582b..2adf7dc9 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -96,8 +96,11 @@ html, body { border text-gray-900 text-center + disabled:text-gray-800 disabled:bg-yellow-700 disabled:border-yellow-700 + ease-linear + duration-150 ; } @@ -183,11 +186,9 @@ html, body { top-0 left-0 bg-white - w-[85%] + w-[80%] h-full z-[60] - py-4 - px-4 overflow-y-auto translate-x-[-100%] ease-linear -- cgit v1.2.3