Добавлена страница управления правами

This commit is contained in:
Александр Сироткин 2021-12-21 15:46:05 +05:00
parent 7ffab81c33
commit 3c4b98366d
2 changed files with 74 additions and 9 deletions

View File

@ -0,0 +1,60 @@
import { useEffect, useState } from 'react'
import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal'
import {
EditableTable,
makeActionHandler,
makeColumn,
makeStringSorter
} from '../../components/Table'
import { AdminPermissionService } from '../../services/api'
const columns = [
makeColumn('Название', 'name', {
editable: true,
sorter: makeStringSorter('name'),
}),
makeColumn('Описание', 'description', {
editable: true,
sorter: makeStringSorter('description'),
}),
]
export const PermissionController = () => {
const [showLoader, setShowLoader] = useState(false)
const [permissions, setPermissions] = useState([])
const updateTable = () => invokeWebApiWrapperAsync(
async () => {
const permission = await AdminPermissionService.getAll()
setPermissions(permission ?? [])
},
setShowLoader,
`Не удалось загрузить список прав`
)
useEffect(updateTable, [])
const handlerProps = {
service: AdminPermissionService,
setLoader: setShowLoader,
errorMsg: `Не удалось выполнить операцию`,
onComplete: updateTable
}
return (
<LoaderPortal show={showLoader}>
<EditableTable
bordered
size={'small'}
columns={columns}
dataSource={permissions}
onRowAdd={makeActionHandler('insert', handlerProps)}
onRowEdit={makeActionHandler('update', handlerProps)}
onRowDelete={makeActionHandler('delete', handlerProps)}
/>
</LoaderPortal>
)
}
export default PermissionController

View File

@ -9,6 +9,7 @@ const DepositController = lazy(() => import('./DepositController'))
const UserController = lazy(() => import('./UserController')) const UserController = lazy(() => import('./UserController'))
const WellController = lazy(() => import('./WellController')) const WellController = lazy(() => import('./WellController'))
const RoleController = lazy(() => import('./RoleController')) const RoleController = lazy(() => import('./RoleController'))
const PermissionController = lazy(() => import('./PermissionController'))
const VisitLog = lazy(() => import('./VisitLog')) const VisitLog = lazy(() => import('./VisitLog'))
export const AdminPanel = () => { export const AdminPanel = () => {
@ -34,9 +35,12 @@ export const AdminPanel = () => {
<Link to={`${rootPath}/company`}>Компании</Link> <Link to={`${rootPath}/company`}>Компании</Link>
</PrivateMenuItem> </PrivateMenuItem>
<PrivateMenuItem key={'role'} permission={'role_editor'}> <PrivateMenuItem key={'role'} permission={'role_editor'}>
<Link to={`${rootPath}/role`}>Права</Link> <Link to={`${rootPath}/role`}>Роли</Link>
</PrivateMenuItem> </PrivateMenuItem>
<PrivateMenuItem key={'visit_log'} permission={'visit_log'}> <PrivateMenuItem key={'permission'} permission={'permission_editor'}>
<Link to={`${rootPath}/permission`}>Права</Link>
</PrivateMenuItem>
<PrivateMenuItem key={'visit_log'}>
<Link to={`${rootPath}/visit_log`}>Журнал посещений</Link> <Link to={`${rootPath}/visit_log`}>Журнал посещений</Link>
</PrivateMenuItem> </PrivateMenuItem>
</Menu> </Menu>
@ -51,7 +55,8 @@ export const AdminPanel = () => {
<PrivateRoute permission={ 'user_editor'} path={`${rootPath}/user` } component={ UserController} /> <PrivateRoute permission={ 'user_editor'} path={`${rootPath}/user` } component={ UserController} />
<PrivateRoute permission={ 'company_editor'} path={`${rootPath}/company` } component={ CompanyController} /> <PrivateRoute permission={ 'company_editor'} path={`${rootPath}/company` } component={ CompanyController} />
<PrivateRoute permission={ 'role_editor'} path={`${rootPath}/role` } component={ RoleController} /> <PrivateRoute permission={ 'role_editor'} path={`${rootPath}/role` } component={ RoleController} />
<PrivateRoute permission={ 'visit_log'} path={`${rootPath}/visit_log`} component={ VisitLog} /> <PrivateRoute permission={'permission_editor'} path={`${rootPath}/permission`} component={PermissionController} />
<PrivateRoute path={`${rootPath}/visit_log`} component={VisitLog} />
<Route path={'/'}> <Route path={'/'}>
<Redirect to={`${rootPath}/deposit`}/> <Redirect to={`${rootPath}/deposit`}/>
</Route> </Route>