🚚 Move new-frontend to frontend (#652)
This commit is contained in:
37
frontend/src/routes/_layout.tsx
Normal file
37
frontend/src/routes/_layout.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Flex, Spinner } from '@chakra-ui/react'
|
||||
import { Outlet, createFileRoute, redirect } from '@tanstack/react-router'
|
||||
|
||||
import Sidebar from '../components/Common/Sidebar'
|
||||
import UserMenu from '../components/Common/UserMenu'
|
||||
import useAuth, { isLoggedIn } from '../hooks/useAuth'
|
||||
|
||||
export const Route = createFileRoute('/_layout')({
|
||||
component: Layout,
|
||||
beforeLoad: async () => {
|
||||
if (!isLoggedIn()) {
|
||||
throw redirect({
|
||||
to: '/login',
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
function Layout() {
|
||||
const { isLoading } = useAuth()
|
||||
|
||||
return (
|
||||
<Flex maxW="large" h="auto" position="relative">
|
||||
<Sidebar />
|
||||
{isLoading ? (
|
||||
<Flex justify="center" align="center" height="100vh" width="full">
|
||||
<Spinner size="xl" color="ui.main" />
|
||||
</Flex>
|
||||
) : (
|
||||
<Outlet />
|
||||
)}
|
||||
<UserMenu />
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
|
||||
export default Layout
|
||||
Reference in New Issue
Block a user