diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/auth/components/LoginDesktop.jsx | 82 | ||||
| -rw-r--r-- | src/lib/auth/components/LoginMobile.jsx | 97 | ||||
| -rw-r--r-- | src/lib/auth/hooks/useLogin.js | 101 | ||||
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 6 | ||||
| -rw-r--r-- | src/lib/product/components/Product/ProductMobile.jsx | 2 | ||||
| -rw-r--r-- | src/lib/product/components/ProductCard.jsx | 31 |
6 files changed, 188 insertions, 131 deletions
diff --git a/src/lib/auth/components/LoginDesktop.jsx b/src/lib/auth/components/LoginDesktop.jsx index d22da6f8..1333db14 100644 --- a/src/lib/auth/components/LoginDesktop.jsx +++ b/src/lib/auth/components/LoginDesktop.jsx @@ -1,46 +1,54 @@ -import DesktopView from '@/core/components/views/DesktopView' -import useLogin from '../hooks/useLogin' -import Link from '@/core/components/elements/Link/Link' -import PageContent from '@/lib/content/components/PageContent' -import Alert from '@/core/components/elements/Alert/Alert' -import { useSession, signIn, SignOut } from 'next-auth/react' -import Image from 'next/image' -import { useRouter } from 'next/router' -import { useContext, useEffect, useState } from 'react' -import { getAuth, setAuth } from '@/core/utils/auth' -import { setCookie } from 'cookies-next' -import BottomPopup from '@/core/components/elements/Popup/BottomPopup' -import Spinner from '@/core/components/elements/Spinner/Spinner' -import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' -import odooApi from '@/core/api/odooApi' +import DesktopView from '@/core/components/views/DesktopView'; +import useLogin from '../hooks/useLogin'; +import Link from '@/core/components/elements/Link/Link'; +import PageContent from '@/lib/content/components/PageContent'; +import Alert from '@/core/components/elements/Alert/Alert'; +import { useSession, signIn, SignOut } from 'next-auth/react'; +import { useRouter } from 'next/router'; +import { useEffect, useState } from 'react'; +import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; +import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'; const LoginDesktop = () => { - const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef, handleGoogleSubmit } = - useLogin() + const { + handleSubmit, + handleChangeInput, + isLoading, + isValid, + alert, + emailRef, + passwordRef, + handleGoogleSubmit, + } = useLogin(); - const router = useRouter() - const [query, setQuery] = useState(router?.query?.next || '/') - const { data: session } = useSession() + const router = useRouter(); + const [query, setQuery] = useState(router?.query?.next || '/'); + const { data: session } = useSession(); const handleGoogle = async () => { - const url = query != '/' ? '/login?source=google&next=' + query : '/login?source=google' - await signIn('google', { callbackUrl: url }) - } + const url = + query != '/' + ? '/login?source=google&next=' + query + : '/login?source=google'; + await signIn('google', { callbackUrl: url }); + }; useEffect(() => { if (session) { - handleGoogleSubmit(session) + handleGoogleSubmit(session); } - }, [session]) + }, [session]); if (router.query.source) { return ( <BottomPopup active={true} close=''> - <div className='leading-7 text-gray_r-12/80 flex justify-center'>Mohon Tunggu</div> + <div className='leading-7 text-gray_r-12/80 flex justify-center'> + Mohon Tunggu + </div> <div className='container flex justify-center my-4'> <LogoSpinner width={48} height={48} /> </div> </BottomPopup> - ) + ); } return ( @@ -48,7 +56,9 @@ const LoginDesktop = () => { <div className='container mx-auto'> <div className='grid grid-cols-2 gap-x-10 pt-16'> <div> - <h1 className='text-2xl font-semibold'>Selamat Datang di Indoteknik</h1> + <h1 className='text-2xl font-semibold'> + Selamat Datang di Indoteknik + </h1> <h2 className='text-gray_r-11 font-normal mt-1 mb-4'> Masuk ke akun kamu untuk mulai transaksi! </h2> @@ -59,7 +69,10 @@ const LoginDesktop = () => { </Alert> )} - <form className='w-full mt-6 flex flex-col gap-y-4' onSubmit={handleSubmit}> + <form + className='w-full mt-6 flex flex-col gap-y-4' + onSubmit={handleSubmit} + > <div> <label htmlFor='email'>Alamat Email</label> <input @@ -118,7 +131,10 @@ const LoginDesktop = () => { <div className='text-gray_r-11 mt-10'> Belum punya akun Indoteknik?{' '} - <Link href='/register' className='inline'> + <Link + href={`/register?${new URLSearchParams(router.query)}`} + className='inline' + > Daftar akun baru </Link> </div> @@ -129,7 +145,7 @@ const LoginDesktop = () => { </div> </div> </DesktopView> - ) -} + ); +}; -export default LoginDesktop +export default LoginDesktop; diff --git a/src/lib/auth/components/LoginMobile.jsx b/src/lib/auth/components/LoginMobile.jsx index 6e1831d4..40924fbe 100644 --- a/src/lib/auth/components/LoginMobile.jsx +++ b/src/lib/auth/components/LoginMobile.jsx @@ -1,19 +1,17 @@ -import Image from 'next/image' -import IndoteknikLogo from '@/images/logo.png' -import Link from '@/core/components/elements/Link/Link' -import Alert from '@/core/components/elements/Alert/Alert' -import MobileView from '@/core/components/views/MobileView' -import useLogin from '../hooks/useLogin' +import Image from 'next/image'; +import IndoteknikLogo from '@/images/logo.png'; +import Link from '@/core/components/elements/Link/Link'; +import Alert from '@/core/components/elements/Alert/Alert'; +import MobileView from '@/core/components/views/MobileView'; +import useLogin from '../hooks/useLogin'; -import { useSession, signIn, SignOut } from 'next-auth/react' -import { useRouter } from 'next/router' -import { useEffect, useState } from 'react' -import { setCookie } from 'cookies-next' -import BottomPopup from '@/core/components/elements/Popup/BottomPopup' -import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' -import odooApi from '@/core/api/odooApi' -import { getAuth } from '@/core/utils/auth' -import PageContent from '@/lib/content/components/PageContent' +import { useSession, signIn, SignOut } from 'next-auth/react'; +import { useRouter } from 'next/router'; +import { useEffect, useState } from 'react'; +import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; +import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'; +import { getAuth } from '@/core/utils/auth'; +import PageContent from '@/lib/content/components/PageContent'; const LoginMobile = () => { const { @@ -24,43 +22,55 @@ const LoginMobile = () => { alert, emailRef, passwordRef, - handleGoogleSubmit - } = useLogin() + handleGoogleSubmit, + } = useLogin(); - const router = useRouter() - const [query, setQuery] = useState(router?.query?.next || '/') - const { data: session } = useSession() - const auth = getAuth() + const router = useRouter(); + const [query, setQuery] = useState(router?.query?.next || '/'); + const { data: session } = useSession(); + const auth = getAuth(); const handleGoogle = async () => { - const url = query != '/' ? '/login?source=google&next=' + query : '/login?source=google' - await signIn('google', { callbackUrl: url }) - } + const url = + query != '/' + ? '/login?source=google&next=' + query + : '/login?source=google'; + await signIn('google', { callbackUrl: url }); + }; useEffect(() => { if (session) { - handleGoogleSubmit(session) + handleGoogleSubmit(session); } - }, [session]) + }, [session]); if (router.query.source) { return ( <BottomPopup active={true} close={true}> - <div className='leading-7 text-gray_r-12/80 flex justify-center'>Mohon Tunggu</div> + <div className='leading-7 text-gray_r-12/80 flex justify-center'> + Mohon Tunggu + </div> <div className='container flex justify-center my-4'> <LogoSpinner width={48} height={48} /> </div> </BottomPopup> - ) + ); } return ( <MobileView> <div className='p-6 pt-10 flex flex-col items-center min-h-screen'> <Link href='/'> - <Image src={IndoteknikLogo} alt='Logo Indoteknik' width={150} height={50} /> + <Image + src={IndoteknikLogo} + alt='Logo Indoteknik' + width={150} + height={50} + /> </Link> <h1 className='text-2xl mt-4 font-semibold'>Mulai Belanja Sekarang</h1> - <h2 className='text-gray_r-11 font-normal mt-1 mb-4'>Masuk ke akun kamu untuk belanja</h2> + <h2 className='text-gray_r-11 font-normal mt-1 mb-4'> + Masuk ke akun kamu untuk belanja + </h2> {alert && ( <Alert className='text-center' type={alert.type}> @@ -68,7 +78,10 @@ const LoginMobile = () => { </Alert> )} - <form className='w-full mt-6 flex flex-col gap-y-4' onSubmit={handleSubmit}> + <form + className='w-full mt-6 flex flex-col gap-y-4' + onSubmit={handleSubmit} + > <div> <label htmlFor='email'>Alamat Email</label> <input @@ -96,7 +109,11 @@ const LoginMobile = () => { placeholder='••••••••••••' /> </div> - <button type='submit' className='btn-yellow w-full mt-2' disabled={!isValid || isLoading}> + <button + type='submit' + className='btn-yellow w-full mt-2' + disabled={!isValid || isLoading} + > {!isLoading ? 'Masuk' : 'Loading...'} </button> </form> @@ -123,16 +140,20 @@ const LoginMobile = () => { <div className='text-gray_r-11 mt-4'> Belum punya akun Indoteknik?{' '} - <Link href='/register' className='inline'> + <Link + href={`/register?${new URLSearchParams(router.query)}`} + className='inline' + > Daftar </Link> </div> - {/* <div className='mt-5'> + + <section className='my-10 md:my-0'> <PageContent path='/login' /> - </div> */} + </section> </div> </MobileView> - ) -} + ); +}; -export default LoginMobile +export default LoginMobile; 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 a8cca416..5f034c09 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -441,11 +441,11 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { {sellingProductFormat(product?.qtySold) + ' Terjual'} </div> )} - {lowestPrice?.isFlashsale && lowestPrice?.price.discountPercentage > 0 ? ( + {product?.flashSale?.id && lowestPrice?.price.discountPercentage > 0 ? ( <> <div className='flex gap-x-1 items-center mt-2'> <div className='badge-solid-red text-caption-1'> - {lowestPrice?.price?.discountPercentage}% + {Math.floor(lowestPrice?.price?.discountPercentage)}% </div> <div className='text-gray_r-9 line-through text-caption-1'> {currencyFormat(lowestPrice?.price?.price)} @@ -584,7 +584,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { <> <div className='flex items-center gap-x-1 justify-center'> <div className='badge-solid-red text-caption-1'> - {variant?.price?.discountPercentage}% + {Math.floor(variant?.price?.discountPercentage)}% </div> <div className='line-through text-caption-1 text-gray_r-11'> {currencyFormat(variant?.price?.price)} diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index ef2c0002..e23e2fb9 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -260,7 +260,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { {activeVariant.isFlashsale && activeVariant?.price?.discountPercentage > 0 ? ( <> <div className='flex gap-x-1 items-center'> - <div className='badge-solid-red'>{activeVariant?.price?.discountPercentage}%</div> + <div className='badge-solid-red'>{Math.floor(activeVariant?.price?.discountPercentage)}%</div> <div className='text-gray_r-11 line-through text-caption-1'> {currencyFormat(activeVariant?.price?.price)} </div> diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index 9500a3fd..fa555bcf 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -12,6 +12,7 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { const callForPriceWhatsapp = whatsappUrl('product', { name: product.name, + manufacture: product.manufacture?.name, url: createSlug('/shop/product/', product.name, product.id, true) }) @@ -41,7 +42,7 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { <div className='flex gap-x-1 items-center p-2 justify-center'> <div className='bg-yellow-400 rounded-lg p-1 h-6 w-19 flex items-center justify-center '> <span className='text-sm font-bold text-black'> - {product?.lowestPrice.discountPercentage}% + {Math.floor(product?.lowestPrice.discountPercentage)}% </span> </div> <div className='bg-red-600 border border-solid border-yellow-400 p-2 rounded-full h-6 flex w-fit items-center justify-center gap-x-2'> @@ -102,7 +103,9 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { {product?.lowestPrice.priceDiscount > 0 ? ( currencyFormat(product?.lowestPrice.priceDiscount) ) : ( - <a href={callForPriceWhatsapp}>Call for Inquiry</a> + <a rel='noopener noreferrer' target='_blank' href={callForPriceWhatsapp}> + Call for Inquiry + </a> )} </div> </> @@ -117,7 +120,9 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { </div> </> ) : ( - <a href={callForPriceWhatsapp}>Call for Inquiry</a> + <a rel='noopener noreferrer' target='_blank' href={callForPriceWhatsapp}> + Call for Inquiry + </a> )} </div> )} @@ -125,7 +130,11 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { <div className='flex w-full items-center gap-x-1 '> {product?.stockTotal > 0 && <div className='badge-solid-red'>Ready Stock</div>} {/* <div className='badge-gray'>{product?.stockTotal > 5 ? '> 5' : '< 5'}</div> */} - {product?.qtySold > 0 && <div className='text-gray_r-9 text-[11px]'>{sellingProductFormat(product?.qtySold) + ' Terjual'}</div>} + {product?.qtySold > 0 && ( + <div className='text-gray_r-9 text-[11px]'> + {sellingProductFormat(product?.qtySold) + ' Terjual'} + </div> + )} </div> </div> </div> @@ -205,7 +214,9 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { {product?.lowestPrice?.priceDiscount > 0 ? ( currencyFormat(product?.lowestPrice?.priceDiscount) ) : ( - <a href={callForPriceWhatsapp}>Call for Inquiry</a> + <a rel='noopener noreferrer' target='_blank' href={callForPriceWhatsapp}> + Call for Inquiry + </a> )} </div> </> @@ -220,7 +231,9 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { </div> </> ) : ( - <a href={callForPriceWhatsapp}>Call for Inquiry</a> + <a rel='noopener noreferrer' target='_blank' href={callForPriceWhatsapp}> + Call for Inquiry + </a> )} </div> )} @@ -228,7 +241,11 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { <div className='flex w-full items-center gap-x-1 '> {product?.stockTotal > 0 && <div className='badge-solid-red'>Ready Stock</div>} {/* <div className='badge-gray'>{product?.stockTotal > 5 ? '> 5' : '< 5'}</div> */} - {product?.qtySold > 0 && <div className='text-gray_r-9 text-[11px]'>{sellingProductFormat(product?.qtySold) + ' Terjual'}</div>} + {product?.qtySold > 0 && ( + <div className='text-gray_r-9 text-[11px]'> + {sellingProductFormat(product?.qtySold) + ' Terjual'} + </div> + )} </div> </div> </div> |
