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/LoginDesktop.jsx | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

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

diff --git a/src/lib/auth/components/LoginDesktop.jsx b/src/lib/auth/components/LoginDesktop.jsx
index 3a7477b9..42fa8896 100644
--- a/src/lib/auth/components/LoginDesktop.jsx
+++ b/src/lib/auth/components/LoginDesktop.jsx
@@ -9,27 +9,39 @@ 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'
 
 const LoginDesktop = () => {
-  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 })
   }
-
   useEffect(() => {
-    if(session){
-      setCookie('auth', JSON.stringify(session?.odooUser))
-      router.push(query)
+    if (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='container flex justify-center my-4'>
+          <LogoSpinner width={48} height={48} />
+        </div>
+      </BottomPopup>
+    )
+  }
 
   return (
     <DesktopView>
-- 
cgit v1.2.3

