summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-12-09 15:00:45 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-12-09 15:00:45 +0700
commitf2451beed670dc697aa2026b2df6ad1ad1e90da2 (patch)
treee25ff3230b6878ff037216b6cd1dad527440dfb8 /src/pages
parente9cd13307f0095dc4edc5048752675d80c551564 (diff)
<iman> update pengajuan tempo
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/pengajuan-tempo/index.jsx44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/pages/pengajuan-tempo/index.jsx b/src/pages/pengajuan-tempo/index.jsx
index 271914c3..f0681663 100644
--- a/src/pages/pengajuan-tempo/index.jsx
+++ b/src/pages/pengajuan-tempo/index.jsx
@@ -7,38 +7,62 @@ import MobileView from '@/core/components/views/MobileView';
import { getAuth } from '~/libs/auth';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
+import odooApi from '@/core/api/odooApi';
const PagePengajuanTempo = dynamic(() =>
import('@/lib/pengajuan-tempo/component/PengajuanTempo')
);
export default function TrackingOrder() {
+ const [tempo, setTempo] = useState(null);
+ const [isLoading, setIsLoading] = useState(true);
const auth = getAuth();
- console.log('auth', auth);
const router = useRouter();
- const [isLoading, setIsLoading] = useState(true); // Set default isLoading to true
useEffect(() => {
- // if (!auth) return; // Prevent unnecessary processing if auth is not ready
+ const loadTempo = async () => {
+ try {
+ if (auth?.partnerId) {
+ const dataTempo = await odooApi(
+ 'GET',
+ `/api/v1/check/${auth.partnerId}/tempo`
+ );
+ setTempo(dataTempo);
+ }
+ } catch (error) {
+ console.error('Error fetching tempo data:', error);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+ if (auth) {
+ loadTempo();
+ } else {
+ setIsLoading(false);
+ }
+ }, [auth]);
+
+ useEffect(() => {
if (!auth) {
const nextUrl = encodeURIComponent(router.asPath);
router.push(`/login?next=${nextUrl}`);
} else if (!auth.parentId) {
router.push('/pengajuan-tempo/switch-account');
- } else if (auth.tempoProgres === 'review') {
+ } else if (auth.tempoProgres === 'review' && !tempo?.paymentTerm) {
router.push('/pengajuan-tempo/review');
- } else if (auth.tempoProgres === 'approve') {
+ } else if (
+ auth.tempoProgres === 'approve' &&
+ tempo?.paymentTerm?.toLowerCase().includes('tempo')
+ ) {
router.push('/pengajuan-tempo/approve');
} else if (auth.tempoProgres === 'rejected') {
router.push('/pengajuan-tempo/rejected');
- } else {
- setIsLoading(false); // Set isLoading to false only when routing is not required
}
- }, [auth, router]);
+ }, [auth, router, tempo]);
- if (isLoading || !auth) {
- return null; // Show nothing while loading or if auth is not ready
+ if (isLoading || !auth || !tempo) {
+ return null; // Tidak render apa pun selama loading atau auth/tempo belum tersedia
}
return (