MSP-3125 fix style
This commit is contained in:
1 parent
654490c748
commit
602f703f5d
29 files changed
+151
-229
No files matched your search
@@ -1,8 +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 '../../types/roles.type.ts';
|
||||
|
||||
function AdminPermission({children}: PropsWithChildren) {
|
||||
const AdminPermission = ({children}: PropsWithChildren) => {
|
||||
const {hasPermission} = useRole();
|
||||
|
||||
if (hasPermission(PermissionKeys.admin_view)) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {useState} from 'react';
|
||||
import {ConfigProvider} from "antd";
|
||||
import {Context} from "../store";
|
||||
import Routers from "./Routers";
|
||||
import {lightTheme} from "../constants/theme.ts";
|
||||
import {ConfigProvider} from 'antd';
|
||||
import {Context} from '../store';
|
||||
import Routers from './Routers';
|
||||
import {lightTheme} from '../constants/theme.ts';
|
||||
import './app.scss'
|
||||
|
||||
function App() {
|
||||
const App = () => {
|
||||
const [themes, setTheme] = useState(lightTheme);
|
||||
|
||||
return (
|
||||
@@ -20,4 +20,3 @@ function App() {
|
||||
}
|
||||
|
||||
export default App
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
const ErrorPage = () => {
|
||||
|
||||
return (
|
||||
<div className='error-page'>
|
||||
<div>Извините, ошибка</div>
|
||||
</div>
|
||||
);
|
||||
<section className="error-page">
|
||||
<p>Извините, ошибка</p>
|
||||
</section>
|
||||
)
|
||||
};
|
||||
|
||||
export default ErrorPage;
|
||||
@@ -3,4 +3,4 @@
|
||||
border: none;
|
||||
display: flex;
|
||||
justify-content: end
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
import {useContext} from "react";
|
||||
import {Segmented, theme} from "antd";
|
||||
import {Context} from "../../store";
|
||||
import {darkTheme, lightTheme} from "../../constants/theme.ts";
|
||||
import {useContext} from 'react';
|
||||
import {Segmented, theme} from 'antd';
|
||||
import {Context} from '../../store';
|
||||
import {darkTheme, lightTheme} from '../../constants/theme.ts';
|
||||
import './header.scss'
|
||||
|
||||
const options = [
|
||||
{label: 'Light', value: 'light' },
|
||||
{label: 'Dark', value: 'dark'},
|
||||
{label: "Light", value: "light"},
|
||||
{label: "Dark", value: "dark"},
|
||||
];
|
||||
|
||||
function Header() {
|
||||
const Header = () => {
|
||||
const {setTheme} = useContext(Context)
|
||||
const { useToken } = theme;
|
||||
const { token } = useToken();
|
||||
const {useToken} = theme;
|
||||
const {token} = useToken();
|
||||
|
||||
return <header className='header' style={{
|
||||
backgroundColor: token.colorBgLayout
|
||||
}}><Segmented onChange={(v) => setTheme(v === 'light' ? lightTheme : darkTheme)} options={options}/></header>;
|
||||
return <header className="header" style={{backgroundColor: token.colorBgLayout}}>
|
||||
<Segmented onChange={(v) => setTheme(v === "light" ? lightTheme : darkTheme)} options={options}/>
|
||||
</header>;
|
||||
}
|
||||
|
||||
export default Header;
|
||||
export default Header;
|
||||
@@ -1,16 +1,16 @@
|
||||
import {useEffect, useState} from "react";
|
||||
import {useEffect, useState} from 'react';
|
||||
import {Navigate, Outlet, useNavigate} from 'react-router-dom';
|
||||
import {Menu} from 'antd';
|
||||
import Header from "../Header";
|
||||
import useRole from "../../hooks/useRole.tsx";
|
||||
import {PermissionKeys} from "../../types/roles.type.ts";
|
||||
import {MenuItemKeys, menuKeys} from "../../types/layout.type.ts";
|
||||
import {routePaths} from "../../constants/routes.ts";
|
||||
import {StateProfileStatus} from "../../redusers/ProfileSlice.ts";
|
||||
import {useAppSelector} from "../../hooks/redux.ts";
|
||||
import Header from '../Header';
|
||||
import useRole from '../../hooks/useRole.tsx';
|
||||
import {PermissionKeys} from '../../types/roles.type.ts';
|
||||
import {MenuItemKeys, menuKeys} from '../../types/layout.type.ts';
|
||||
import {routePaths} from '../../constants/routes.ts';
|
||||
import {StateProfileStatus} from '../../redusers/ProfileSlice.ts';
|
||||
import {useAppSelector} from '../../hooks/redux.ts';
|
||||
import './layout.scss'
|
||||
|
||||
function Layout() {
|
||||
const Layout = () => {
|
||||
const {hasPermission} = useRole();
|
||||
const navigate = useNavigate();
|
||||
const {status} = useAppSelector((state) => state.profileReducer);
|
||||
@@ -19,32 +19,31 @@ function Layout() {
|
||||
const [selectedMenuKeys, setSelectedMenuKeys] = useState<MenuItemKeys[]>([]);
|
||||
|
||||
const hideItem = (permission: PermissionKeys | PermissionKeys[]) => {
|
||||
|
||||
if (Array.isArray(permission)) {
|
||||
const result = permission.reduce((acc, currentValue) => {
|
||||
const isHasPermission = hasPermission(currentValue);
|
||||
return isHasPermission || acc;
|
||||
}, false);
|
||||
return result ? '' : 'hide-item';
|
||||
return result ? "" : "hide-item";
|
||||
}
|
||||
return hasPermission(permission) ? '' : 'hide-item';
|
||||
return hasPermission(permission) ? "" : "hide-item";
|
||||
};
|
||||
|
||||
const menuItems = [
|
||||
{
|
||||
label: 'Profile',
|
||||
key: 'users',
|
||||
label: "Profile",
|
||||
key: "users",
|
||||
className: hideItem(PermissionKeys.user_view),
|
||||
},
|
||||
{
|
||||
label: 'Profile2',
|
||||
key: 'roles',
|
||||
label: "Profile2",
|
||||
key: "roles",
|
||||
className: hideItem(PermissionKeys.user_view),
|
||||
}
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
const menuKey = location.pathname.split('/')[1] as MenuItemKeys;
|
||||
const menuKey = location.pathname.split("/")[1] as MenuItemKeys;
|
||||
|
||||
const menuItem = menuKeys[menuKey];
|
||||
|
||||
@@ -65,11 +64,13 @@ function Layout() {
|
||||
default:
|
||||
}
|
||||
};
|
||||
|
||||
if (status === StateProfileStatus.rejected) {
|
||||
return <Navigate to={routePaths.error} replace/>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='layout'>
|
||||
<section className="layout">
|
||||
<Header/>
|
||||
<Menu
|
||||
onOpenChange={(keys) => setOpenKeys(keys)}
|
||||
@@ -81,8 +82,8 @@ function Layout() {
|
||||
items={menuItems}
|
||||
/>
|
||||
<Outlet/>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default Layout;
|
||||
export default Layout;
|
||||
@@ -1,4 +1,4 @@
|
||||
.layout {
|
||||
min-height: calc(100vh - 96px);
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import {Button, theme} from 'antd';
|
||||
import {PermissionKeys} from "../../types/roles.type.ts";
|
||||
import useRole from "../../hooks/useRole.tsx";
|
||||
import './main.scss'
|
||||
|
||||
const Main = () => {
|
||||
const {hasPermission} = useRole();
|
||||
const { useToken } = theme;
|
||||
const { token } = useToken();
|
||||
|
||||
const isPageAvailable = hasPermission(PermissionKeys.user_view);
|
||||
|
||||
return (
|
||||
<div className='main' style={{
|
||||
backgroundColor: token.colorBgLayout
|
||||
}}>
|
||||
{isPageAvailable && <Button ghost type='primary'>
|
||||
Border
|
||||
</Button>}
|
||||
<div>Проверка шрифтов</div>
|
||||
<Button type='primary'>Primary</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Main;
|
||||
@@ -1,5 +0,0 @@
|
||||
.main {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
import {Navigate, Outlet, useLocation} from 'react-router-dom';
|
||||
import {LocalStorage} from "../../utils/localStorageUtils.ts";
|
||||
import {localStorageKeys} from "../../constants/localStorageKeys.ts";
|
||||
import {routePaths} from "../../constants/routes.ts";
|
||||
import {LocalStorage} from '../../utils/localStorageUtils.ts';
|
||||
import {localStorageKeys} from '../../constants/localStorageKeys.ts';
|
||||
import {routePaths} from '../../constants/routes.ts';
|
||||
|
||||
function PrivateRoute() {
|
||||
const PrivateRoute = () => {
|
||||
const location = useLocation();
|
||||
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN);
|
||||
|
||||
if (!userToken) {
|
||||
LocalStorage.set('redirectUrl', location.pathname)
|
||||
LocalStorage.set("redirectUrl", location.pathname)
|
||||
return (
|
||||
<Navigate
|
||||
to={routePaths.login}
|
||||
// state={{ from: location.pathname }}
|
||||
replace
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import {Route, Routes} from 'react-router-dom';
|
||||
import {App} from 'antd';
|
||||
import HomePages from "../../pages/HomePage";
|
||||
import ErrorPage from "../ErrorPage";
|
||||
import PrivateRoute from "../PrivateRoute";
|
||||
import LoginPage from "../../pages/LoginPage";
|
||||
import Layout from "../Layout";
|
||||
|
||||
function Routers() {
|
||||
import HomePages from '../../pages/HomePage';
|
||||
import ErrorPage from '../ErrorPage';
|
||||
import PrivateRoute from '../PrivateRoute';
|
||||
import LoginPage from '../../pages/LoginPage';
|
||||
import Layout from '../Layout';
|
||||
|
||||
const Routers = () => {
|
||||
return (
|
||||
<App>
|
||||
<Routes>
|
||||
@@ -24,4 +23,3 @@ function Routers() {
|
||||
}
|
||||
|
||||
export default Routers
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
#root {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.app {
|
||||
min-height: 100vh;
|
||||
}
|
||||
.ant-space-item {
|
||||
width: 100%;
|
||||
}
|
||||
Reference in new issue
Block a user