From 9a49b8d84761781531cb417731cb9ef802f63541 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 4 Dec 2024 10:59:21 +0700
Subject: <iman> update pengajuan tempo

---
 src/pages/pengajuan-tempo/index.jsx | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

(limited to 'src/pages/pengajuan-tempo/index.jsx')

diff --git a/src/pages/pengajuan-tempo/index.jsx b/src/pages/pengajuan-tempo/index.jsx
index 9f772ddd..25db0c4b 100644
--- a/src/pages/pengajuan-tempo/index.jsx
+++ b/src/pages/pengajuan-tempo/index.jsx
@@ -6,7 +6,7 @@ import DesktopView from '@/core/components/views/DesktopView';
 import MobileView from '@/core/components/views/MobileView';
 import { getAuth } from '~/libs/auth';
 import { useRouter } from 'next/router';
-import { useEffect } from 'react';
+import { useEffect, useState } from 'react';
 
 const PagePengajuanTempo = dynamic(() =>
   import('@/lib/pengajuan-tempo/component/PengajuanTempo')
@@ -15,30 +15,35 @@ const PagePengajuanTempo = dynamic(() =>
 export default function TrackingOrder() {
   const auth = getAuth();
   const router = useRouter();
+  const [isLoading, setIsLoading] = useState(true); // Set default isLoading to true
 
   useEffect(() => {
-    if (!auth) {
+    if (!auth) return; // Prevent unnecessary processing if auth is not ready
+
+    if (auth.tempoProgres === 'review') {
+      router.push('/pengajuan-tempo/review');
+    } else if (!auth.parentId) {
+      router.push('/pengajuan-tempo/switch-account');
+    } else if (!auth) {
       const nextUrl = encodeURIComponent(router.asPath);
       router.push(`/login?next=${nextUrl}`);
-    } else if (!auth?.parentId) {
-      router.push('/pengajuan-tempo/switch-account');
+    } else {
+      setIsLoading(false); // Set isLoading to false only when routing is not required
     }
   }, [auth, router]);
 
-  if (!auth?.parentId) {
-    return null;
+  if (isLoading || !auth) {
+    return null; // Show nothing while loading or if auth is not ready
   }
 
   return (
     <>
       <Seo title='Pengajuan Tempo - Indoteknik.com' />
-
       <DesktopView>
         <BasicLayout>
           <PagePengajuanTempo />
         </BasicLayout>
       </DesktopView>
-
       <MobileView>
         <BasicLayout>
           <PagePengajuanTempo />
-- 
cgit v1.2.3

