import { Suspense, lazy, ElementType } from 'react';
import { Navigate, useRoutes, useLocation } from 'react-router-dom';
// layouts
import DashboardLayout from '@/layouts/dashboard';
import LogoOnlyLayout from '@/layouts/LogoOnlyLayout';
// components
import LoadingScreen from '@/components/LoadingScreen';
import GuestGuard from '@/guards/GuestGuard';
import { RegisterForm } from '@/sections/auth/register';
import Register from '@/pages/auth/Register';
import VerifyCode from '@/pages/auth/VerifyCode';
import { AuthProvider } from '@/contexts/LaravelAuthContext';
import AuthGuard from '@/guards/AuthGuard';
import useAuth from '@/hooks/useAuth';
import RoleBasedGuard from '@/guards/RoleBasedGuard';
// ----------------------------------------------------------------------
const Loadable = (Component: ElementType) => (props: any) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const { pathname } = useLocation();
const {user} = useAuth();
const formattedRoleName = user?.role.name;
return (
}>
);
};
export default function Router() {
return useRoutes([
{
path: 'auth',
children: [
{
path: 'login',
element: (
),
},
{
path: 'register',
element: (
),
},
{
path: 'reset-password',
element: (
),
},
{
path: 'forget-password',
element: (
),
},
{
path: 'verify',
element: (
),
},
// { path: 'login-unprotected', element: },
// { path: 'register-unprotected', element: },
// { path: 'reset-password', element: },
// { path: 'forget-password', element: },
// { path: 'verify', element: },
],
},
// {
// path: '/',
// element: ,
// },
{
path: '/',
element: (
),
children: [
{ element: , index: true },
{
path: 'dashboard',
element: (
),
},
{
path: '/detail/:id',
element: (
),
},
],
},
{
path: '/',
element: (
),
children: [
{ element: , index: true },
{
path: 'claim',
element: (
),
},
{
path: '/claim/detail/:id',
element: (
),
},
],
},
{
path: '/',
element: (
),
children: [
{ element: , index: true },
{
path: 'prescription-orders',
element: (
),
},
],
},
{
path: '*',
element: (
),
children: [
{ path: '404', element: },
{ path: '*', element: },
],
},
{ path: '*', element: },
]);
}
const Login = Loadable(lazy(() => import('@/pages/auth/Login')));
const ResetPassword = Loadable(lazy(() => import('@/pages/auth/ResetPassword')));
const ForgetPassword = Loadable(lazy(() => import('@/pages/auth/ForgetPassword')));
// Dashboard
const Dashboard = Loadable(lazy(() => import('@/pages/Dashboard')));
const Claim = Loadable(lazy(() => import('@/pages/Claim')));
const DashboardApotek = Loadable(lazy(() => import('@/pages/DashboardApotek')));
const NotFound = Loadable(lazy(() => import('@/pages/Page404')));
const DetailClaimReport = Loadable(lazy(()=> import('@/sections/dashboard/Detail')));
const DetailClaim = Loadable(lazy(()=> import('@/sections/claim/Detail')));