summaryrefslogtreecommitdiff
path: root/src/pages/daftar-merchant/index.jsx
blob: 36fedafca8e680173810ef489c94ab316a9be11a (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 BasicLayout from '@/core/components/layouts/BasicLayout';
import CreateMerchant from '@/lib/merchant/components/Merchant';
import ErrorMerchant from '@/lib/merchant/components/AccountSwitch';
import getMerchantProgresApi from '@/lib/merchant/api/getMerchantProgresApi';
import useAuth from '@/core/hooks/useAuth';
import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
export default function DaftarMerchant() {
  const router = useRouter();
  const auth = useAuth();
  const [isLoading, setIsLoading] = useState(true);
  useEffect(() => {
    const loadData = async () => {
      setIsLoading(true);
      try {
        const data = await getMerchantProgresApi();
        switch (data) {
          case 'draft':
            router.push(`/daftar-merchant/review`);
            break;
          case 'approve':
            router.push(`/daftar-merchant/approve`);
            break;
          case 'reject':
            router.push(`/daftar-merchant/reject`);
            break;
        }
      } catch (error) {
        console.error('Error loading profile:', error);
        handleIsError(true); // Jika ada error, panggil fungsi error handler
      }
      setIsLoading(false);
    };

    loadData();
  }, []);
  if (auth == false) {
    router.push(`/login?next=${encodeURIComponent('/daftar-merchant')}`);
  }
  if (!auth || isLoading) {
    return;
  }
  return (
    <>
      <Seo title='Daftar Merchant - Indoteknik.com' />

      <BasicLayout>
        {auth && auth?.company ? <CreateMerchant /> : <ErrorMerchant />}
      </BasicLayout>
    </>
  );
}