From 01e86fb4a54b801a9b8124455611c312e5de4af0 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 14 Aug 2023 15:04:45 +0700
Subject: google sign in

---
 src/lib/auth/components/LoginMobile.jsx | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

(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 b365330b..c5177625 100644
--- a/src/lib/auth/components/LoginMobile.jsx
+++ b/src/lib/auth/components/LoginMobile.jsx
@@ -5,10 +5,22 @@ 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 { useState } from 'react'
+
 const LoginMobile = () => {
   const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef } =
     useLogin()
 
+  const router = useRouter()
+  const [query, setQuery] = useState(router?.query?.next || '/')
+  const { data: session } = useSession()
+
+  if (session) {
+    router.push(query)
+  }
+
   return (
     <MobileView>
       <div className='p-6 pt-10 flex flex-col items-center min-h-screen'>
@@ -56,6 +68,26 @@ const LoginMobile = () => {
             {!isLoading ? 'Masuk' : 'Loading...'}
           </button>
         </form>
+        <div className='flex  items-center mt-3 mb-3'>
+          <hr className='flex-1' />
+          <p className='text-gray-400'>ATAU</p>
+          <hr className='flex-1' />
+        </div>
+
+        <button
+          type='submit'
+          className='border border-gray-500 p-2 rounded-md hover:bg-gray-100  w-full mt-2 flex items-center justify-center gap-x-2'
+          onClick={() => signIn('google',  { callbackUrl: '/login' })}
+        >
+          <Image
+            src='/images/icons8-google.svg'
+            alt='google image'
+            className='h-7 w-7'
+            width={10}
+            height={10}
+          />
+          <p>Masuk dengan Google</p>
+        </button>
 
         <div className='text-gray_r-11 mt-4'>
           Belum punya akun Indoteknik?{' '}
-- 
cgit v1.2.3


From f01f28a7eac76c6da5bf857bfc80fd347586ce7f Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 16 Aug 2023 09:39:47 +0700
Subject: register google

---
 src/lib/auth/components/LoginMobile.jsx | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 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 c5177625..68ceb769 100644
--- a/src/lib/auth/components/LoginMobile.jsx
+++ b/src/lib/auth/components/LoginMobile.jsx
@@ -7,7 +7,8 @@ import useLogin from '../hooks/useLogin'
 
 import { useSession, signIn, SignOut } from 'next-auth/react'
 import { useRouter } from 'next/router'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
+import { setCookie } from 'cookies-next'
 
 const LoginMobile = () => {
   const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef } =
@@ -17,9 +18,17 @@ const LoginMobile = () => {
   const [query, setQuery] = useState(router?.query?.next || '/')
   const { data: session } = useSession()
 
-  if (session) {
-    router.push(query)
+  const handleGoogle = async () => {
+    const url = query != '/' ? '/login?next=' + query : '/login'
+    await signIn('google', { callbackUrl: url })
+    setCookie('auth', JSON.stringify(session?.odooUser))
   }
+  useEffect(() => {
+    if (session) {
+      setCookie('auth', JSON.stringify(session?.odooUser))
+      router.push(query)
+    }
+  }, [session])
 
   return (
     <MobileView>
@@ -77,7 +86,7 @@ const LoginMobile = () => {
         <button
           type='submit'
           className='border border-gray-500 p-2 rounded-md hover:bg-gray-100  w-full mt-2 flex items-center justify-center gap-x-2'
-          onClick={() => signIn('google',  { callbackUrl: '/login' })}
+          onClick={() => handleGoogle()}
         >
           <Image
             src='/images/icons8-google.svg'
-- 
cgit v1.2.3


From b6f6bf23f90ff0dfadf9bf0af8866c2cfc17aa9c Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 18 Aug 2023 11:02:39 +0700
Subject: handling redirect login

---
 src/lib/auth/components/LoginMobile.jsx | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 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 68ceb769..095f4174 100644
--- a/src/lib/auth/components/LoginMobile.jsx
+++ b/src/lib/auth/components/LoginMobile.jsx
@@ -9,27 +9,41 @@ 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'
 
 const LoginMobile = () => {
-  const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef } =
+  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 auth = getAuth()
 
   const handleGoogle = async () => {
-    const url = query != '/' ? '/login?next=' + query : '/login'
+    const url = query != '/' ? '/login?source=google&next=' + query : '/login?source=google'
     await signIn('google', { callbackUrl: url })
-    setCookie('auth', JSON.stringify(session?.odooUser))
   }
   useEffect(() => {
     if (session) {
-      setCookie('auth', JSON.stringify(session?.odooUser))
-      router.push(query)
+      handleGoogleSubmit(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='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'>
-- 
cgit v1.2.3


From 6155dd4ea416de8cbd3be3c9409e2246ad61d60c Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 1 Sep 2023 13:48:07 +0700
Subject: hide button google sign up & shipmet page

---
 src/lib/auth/components/LoginMobile.jsx | 8 ++++----
 1 file changed, 4 insertions(+), 4 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 095f4174..2d6501cd 100644
--- a/src/lib/auth/components/LoginMobile.jsx
+++ b/src/lib/auth/components/LoginMobile.jsx
@@ -91,13 +91,13 @@ const LoginMobile = () => {
             {!isLoading ? 'Masuk' : 'Loading...'}
           </button>
         </form>
-        <div className='flex  items-center mt-3 mb-3'>
+        {/* <div className='flex  items-center mt-3 mb-3'>
           <hr className='flex-1' />
           <p className='text-gray-400'>ATAU</p>
           <hr className='flex-1' />
-        </div>
+        </div> */}
 
-        <button
+        {/* <button
           type='submit'
           className='border border-gray-500 p-2 rounded-md hover:bg-gray-100  w-full mt-2 flex items-center justify-center gap-x-2'
           onClick={() => handleGoogle()}
@@ -110,7 +110,7 @@ const LoginMobile = () => {
             height={10}
           />
           <p>Masuk dengan Google</p>
-        </button>
+        </button> */}
 
         <div className='text-gray_r-11 mt-4'>
           Belum punya akun Indoteknik?{' '}
-- 
cgit v1.2.3

