summaryrefslogtreecommitdiff
path: root/src/pages/my/tempo/index.jsx
blob: f52fe96034ea485856fa037a32fd05cc0ee8c1b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Seo from '@/core/components/Seo';
import AppLayout from '@/core/components/layouts/AppLayout';
import BasicLayout from '@/core/components/layouts/BasicLayout';
import DesktopView from '@/core/components/views/DesktopView';
import MobileView from '@/core/components/views/MobileView';
import IsAuth from '@/lib/auth/components/IsAuth';
import InvoicesComponent from '@/lib/tempo/components/Tempo';
import { getAuth } from '~/libs/auth';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
export default function MyTempo() {
  const auth = getAuth();
  const router = useRouter();
  const [isLoading, setIsLoading] = useState(true);
  useEffect(() => {
    if (!auth) {
      const nextUrl = encodeURIComponent(router.asPath);
      router.push(`/login?next=${nextUrl}`);
    } else if (auth.tempoProgres === '' || auth.tempoProgres === 'rejected') {
      router.push('/pengajuan-tempo');
    } else {
      setIsLoading(false);
    }
  }, [auth]);

  if (isLoading || !auth) {
    return null; // Tidak render apa pun selama loading atau auth/tempo belum tersedia
  }
  return (
    <IsAuth>
      <Seo title='Tempo - Indoteknik.com' />

      <MobileView>
        <AppLayout title='Pembayaran Tempo'>
          <InvoicesComponent />
        </AppLayout>
      </MobileView>

      <DesktopView>
        <BasicLayout>
          <InvoicesComponent />
        </BasicLayout>
      </DesktopView>
    </IsAuth>
  );
}