add project structure
This commit is contained in:
1 parent
07fc6c0b6c
commit
6eaf18285a
28 files changed
+1309
-648
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { PropsWithChildren } from 'react'
|
||||
|
||||
import useRole from '../../hooks/useRole.tsx'
|
||||
import { PermissionKeys } from '../../types/roles.type.ts'
|
||||
import { useRole } from '@hooks/useRole.tsx'
|
||||
|
||||
import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
const AdminPermission = ({ children }: PropsWithChildren) => {
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { ConfigProvider } from 'antd'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { lightTheme } from '../constants/theme.ts'
|
||||
import { Context } from '../store'
|
||||
import Routers from './Routers'
|
||||
import { lightTheme } from '@constants/theme.ts'
|
||||
|
||||
import { Context } from '@stores/index.tsx'
|
||||
|
||||
import Routers from '@routes/Routers'
|
||||
|
||||
import './app.scss'
|
||||
|
||||
const App = () => {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Segmented, theme } from 'antd'
|
||||
import { useContext } from 'react'
|
||||
|
||||
import { darkTheme, lightTheme } from '../../constants/theme.ts'
|
||||
import { Context } from '../../store'
|
||||
import { darkTheme, lightTheme } from '@constants/theme.ts'
|
||||
|
||||
import { Context } from '@stores/index.tsx'
|
||||
|
||||
import './header.scss'
|
||||
|
||||
const options = [
|
||||
|
||||
@@ -2,13 +2,19 @@ import { Menu } from 'antd'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Navigate, Outlet, useNavigate } from 'react-router-dom'
|
||||
|
||||
import { routePaths } from '../../constants/routes.ts'
|
||||
import { useAppSelector } from '../../hooks/redux.ts'
|
||||
import useRole from '../../hooks/useRole.tsx'
|
||||
import { StateProfileStatus } from '../../redusers/ProfileSlice.ts'
|
||||
import { MenuItemKeys, menuKeys } from '../../types/layout.type.ts'
|
||||
import { PermissionKeys } from '../../types/roles.type.ts'
|
||||
import Header from '../Header'
|
||||
import Header from '@components/Header'
|
||||
|
||||
import { useAppSelector } from '@hooks/redux.ts'
|
||||
import { useRole } from '@hooks/useRole.tsx'
|
||||
|
||||
import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
import { MenuItemKeys, menuKeys } from './layout.type.ts'
|
||||
|
||||
import './layout.scss'
|
||||
|
||||
const Layout = () => {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { MenuProps } from 'antd'
|
||||
|
||||
export enum MenuItemKeys {
|
||||
users = 'users',
|
||||
roles = 'roles'
|
||||
}
|
||||
|
||||
type MenuItem = {
|
||||
key: MenuItemKeys
|
||||
parent: string[]
|
||||
}
|
||||
export const menuKeys: Record<MenuItemKeys, MenuItem> = {
|
||||
[MenuItemKeys.users]: {
|
||||
key: MenuItemKeys.users,
|
||||
parent: ['sessionManagement']
|
||||
},
|
||||
[MenuItemKeys.roles]: {
|
||||
key: MenuItemKeys.roles,
|
||||
parent: ['sessionManagement']
|
||||
}
|
||||
}
|
||||
|
||||
export type MenuItemType = Required<MenuProps>['items'][number]
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Navigate, Outlet, useLocation } from 'react-router-dom'
|
||||
|
||||
import { localStorageKeys } from '../../constants/localStorageKeys.ts'
|
||||
import { routePaths } from '../../constants/routes.ts'
|
||||
import { LocalStorage } from '../../utils/localStorageUtils.ts'
|
||||
|
||||
const PrivateRoute = () => {
|
||||
const location = useLocation()
|
||||
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN)
|
||||
|
||||
if (!userToken) {
|
||||
LocalStorage.set('redirectUrl', location.pathname)
|
||||
return <Navigate to={routePaths.login} replace />
|
||||
}
|
||||
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export default PrivateRoute
|
||||
@@ -1,26 +0,0 @@
|
||||
import { App } from 'antd'
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
|
||||
import HomePages from '../../pages/HomePage'
|
||||
import LoginPage from '../../pages/LoginPage'
|
||||
import ErrorPage from '../ErrorPage'
|
||||
import Layout from '../Layout'
|
||||
import PrivateRoute from '../PrivateRoute'
|
||||
|
||||
const Routers = () => {
|
||||
return (
|
||||
<App>
|
||||
<Routes>
|
||||
<Route element={<PrivateRoute />}>
|
||||
<Route path="/" element={<Layout />}>
|
||||
<Route index element={<HomePages />} />
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/error" element={<ErrorPage />} />
|
||||
</Routes>
|
||||
</App>
|
||||
)
|
||||
}
|
||||
|
||||
export default Routers
|
||||
Reference in new issue
Block a user