From 6b221cccd58710682c99db7afbc29322da042880 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 31 Oct 2023 10:44:25 +0700
Subject: - Add redirect after activation - Add register form validation

---
 src/lib/auth/components/LoginMobile.jsx | 99 ++++++++++++++++++++-------------
 1 file changed, 60 insertions(+), 39 deletions(-)

(limited to 'src/lib/auth/components/LoginMobile.jsx')

diff --git a/src/lib/auth/components/LoginMobile.jsx b/src/lib/auth/components/LoginMobile.jsx
index 6e1831d4..58ae4e6e 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'>
-          <PageContent path='/login' />
-        </div> */}
+
+        <section className='my-10 md:my-0'>
+          <PageContent path='/register' />
+        </section>
       </div>
     </MobileView>
-  )
-}
+  );
+};
 
-export default LoginMobile
+export default LoginMobile;
-- 
cgit v1.2.3


From 94c1fba12e054165e7447e9cf778dd7de8922304 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 31 Oct 2023 10:51:23 +0700
Subject: Fix login mobile page content path

---
 src/lib/auth/components/LoginMobile.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/lib/auth/components/LoginMobile.jsx')

diff --git a/src/lib/auth/components/LoginMobile.jsx b/src/lib/auth/components/LoginMobile.jsx
index 58ae4e6e..40924fbe 100644
--- a/src/lib/auth/components/LoginMobile.jsx
+++ b/src/lib/auth/components/LoginMobile.jsx
@@ -149,7 +149,7 @@ const LoginMobile = () => {
         </div>
 
         <section className='my-10 md:my-0'>
-          <PageContent path='/register' />
+          <PageContent path='/login' />
         </section>
       </div>
     </MobileView>
-- 
cgit v1.2.3

