summaryrefslogtreecommitdiff
path: root/src/pages/my/tempo/index.jsx
blob: 6ca5c7186e80a4e84f77665965e1ba1a84a458c7 (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
47
48
49
50
51
52
53
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(() => {
    setIsLoading(true);
    if (!auth) {
      const nextUrl = encodeURIComponent(router.asPath);
      router.push(`/login?next=${nextUrl}`);
    } else {
      if (
        !auth.partnerTempo &&
        (!auth.partnerTempo || auth.tempoProgres === 'review')
      ) {
        setIsLoading(true);
        router.push('/pengajuan-tempo');
      }
      setIsLoading(false);
    }
  }, [auth]);

  if (isLoading && !auth) {
    return null;
  } else {
    return (
      <IsAuth>
        <Seo title='Tempo - Indoteknik.com' />

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

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