summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/auth/hooks/useLogin.js101
-rw-r--r--src/lib/product/components/Product/ProductDesktop.jsx16
2 files changed, 54 insertions, 63 deletions
diff --git a/src/lib/auth/hooks/useLogin.js b/src/lib/auth/hooks/useLogin.js
index 17731a86..dc9580ea 100644
--- a/src/lib/auth/hooks/useLogin.js
+++ b/src/lib/auth/hooks/useLogin.js
@@ -1,80 +1,83 @@
-import Link from '@/core/components/elements/Link/Link'
-import { setAuth } from '@/core/utils/auth'
-import { useRouter } from 'next/router'
-import { useRef, useState } from 'react'
-import loginApi from '../api/loginApi'
-import odooApi from '@/core/api/odooApi'
-import { setCookie } from 'cookies-next'
-import { useSession } from 'next-auth/react'
+import Link from '@/core/components/elements/Link/Link';
+import { setAuth } from '@/core/utils/auth';
+import { useRouter } from 'next/router';
+import { useRef, useState } from 'react';
+import loginApi from '../api/loginApi';
+import odooApi from '@/core/api/odooApi';
+import { setCookie } from 'cookies-next';
+import { useSession } from 'next-auth/react';
const useLogin = () => {
- const router = useRouter()
- const [isLoading, setIsLoading] = useState(false)
- const [alert, setAlert] = useState(null)
- const [isValid, setIsValid] = useState(false)
+ const router = useRouter();
+ const [isLoading, setIsLoading] = useState(false);
+ const [alert, setAlert] = useState(null);
+ const [isValid, setIsValid] = useState(false);
- const emailRef = useRef(null)
- const passwordRef = useRef(null)
+ const emailRef = useRef(null);
+ const passwordRef = useRef(null);
const inputVal = () => ({
email: emailRef.current.value,
- password: passwordRef.current.value
- })
+ password: passwordRef.current.value,
+ });
const handleChangeInput = () => {
- const { email, password } = inputVal()
- const isValidInput = email && password
- setIsValid(isValidInput)
- }
+ const { email, password } = inputVal();
+ const isValidInput = email && password;
+ setIsValid(isValidInput);
+ };
const handleSubmit = async (e) => {
- e.preventDefault()
- setAlert(null)
- setIsLoading(true)
- const { email, password } = inputVal()
- const login = await loginApi({ email, password })
- setIsLoading(false)
+ e.preventDefault();
+ setAlert(null);
+ setIsLoading(true);
+ const { email, password } = inputVal();
+ const login = await loginApi({ email, password });
+ setIsLoading(false);
if (login.isAuth) {
- setAuth(login.user)
- router.push(router.query?.next || '/')
- return
+ setAuth(login.user);
+ router.push(router.query?.next || '/');
+ return;
}
switch (login.reason) {
case 'NOT_FOUND':
setAlert({
children: 'Email atau password tidak cocok',
- type: 'info'
- })
- break
+ type: 'info',
+ });
+ break;
case 'NOT_ACTIVE':
setAlert({
children: (
<>
Email belum diaktivasi,
- <Link className='text-gray-900' href={`/activate?email=${email}`}>
+ <Link
+ className='text-gray-900'
+ href={`?activation=email&email=${email}`}
+ >
aktivasi sekarang
</Link>
</>
),
- type: 'info'
- })
- break
+ type: 'info',
+ });
+ break;
}
- }
+ };
const handleGoogleSubmit = async (session) => {
const params = {
- access_token: session.accessToken
- }
- const data = await odooApi('POST', '/api/v1/user/validate-sso', params)
+ access_token: session.accessToken,
+ };
+ const data = await odooApi('POST', '/api/v1/user/validate-sso', params);
if (data.isAuth) {
- session.odooUser = data.user
- setCookie('auth', JSON.stringify(session?.odooUser))
- router.push(decodeURIComponent(router?.query?.next) ?? '/')
- return
+ session.odooUser = data.user;
+ setCookie('auth', JSON.stringify(session?.odooUser));
+ router.push(decodeURIComponent(router?.query?.next) ?? '/');
+ return;
}
- }
+ };
return {
handleChangeInput,
@@ -84,8 +87,8 @@ const useLogin = () => {
alert,
emailRef,
passwordRef,
- handleGoogleSubmit
- }
-}
+ handleGoogleSubmit,
+ };
+};
-export default useLogin
+export default useLogin;
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 11c34009..a8cca416 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -45,21 +45,9 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
const { setRefreshCart, refreshCart } = useProductCartContext()
- const getLowestPrice = useCallback(() => {
- const prices = product.variants.map((variant) => ({
- price: variant.price,
- isFlashsale: variant.isFlashsale
- }))
- const lowest = prices.reduce((lowest, price) => {
- return price.price < lowest.price ? price : lowest
- }, prices[0])
- return lowest
- }, [product])
-
useEffect(() => {
- const lowest = getLowestPrice()
- setLowestPrice(lowest)
- }, [getLowestPrice])
+ setLowestPrice({ price: product?.lowestPrice })
+ }, [product])
useEffect(() => {
const getBackgound = async () => {