Добавлена страница типов компаний

This commit is contained in:
Александр Сироткин 2022-01-13 17:35:32 +05:00
parent f90856f712
commit bc827117ab
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,62 @@
import { useEffect, useState } from 'react'
import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal'
import { EditableTable, makeColumn, makeActionHandler, makeStringSorter } from '../../components/Table'
import { AdminCompanyTypeService } from '../../services/api'
import { arrayOrDefault } from '../../utils'
import { min1 } from '../../utils/validationRules'
const columns = [
makeColumn('Название', 'caption', {
width: 200,
editable: true,
sorter: makeStringSorter('caption'),
formItemRules: min1,
}),
]
const pagination = {
defaultPageSize: 16,
showSizeChanger: true,
}
export const CompanyTypeController = () => {
const [companyTypes, setCompanyTypes] = useState([])
const [showLoader, setShowLoader] = useState(false)
const updateTable = () => invokeWebApiWrapperAsync(
async() => {
const companyTypes = await AdminCompanyTypeService.getAll()
setCompanyTypes(arrayOrDefault(companyTypes))
},
setShowLoader,
`Не удалось загрузить список типов компаний`
)
useEffect(updateTable, [])
const handlerProps = {
service: AdminCompanyTypeService,
setLoader: setShowLoader,
errorMsg: `Не удалось выполнить операцию`,
onComplete: updateTable,
}
return (
<LoaderPortal show={showLoader}>
<EditableTable
bordered
size={'small'}
columns={columns}
dataSource={companyTypes}
pagination={pagination}
onRowAdd={makeActionHandler('insert', handlerProps)}
onRowEdit={makeActionHandler('put', handlerProps)}
onRowDelete={makeActionHandler('delete', handlerProps)}
/>
</LoaderPortal>
)
}
export default CompanyTypeController

View File

@ -10,6 +10,7 @@ const DepositController = lazy(() => import('./DepositController'))
const UserController = lazy(() => import('./UserController'))
const WellController = lazy(() => import('./WellController'))
const RoleController = lazy(() => import('./RoleController'))
const CompanyTypeController = lazy(() => import('./CompanyTypeController'))
const PermissionController = lazy(() => import('./PermissionController'))
const VisitLog = lazy(() => import('./VisitLog'))
@ -35,6 +36,9 @@ export const AdminPanel = () => {
<PrivateMenuItem key={'company'} permission={'company_editor'}>
<Link to={`${rootPath}/company`}>Компании</Link>
</PrivateMenuItem>
<PrivateMenuItem key={'company_type'}>
<Link to={`${rootPath}/company_type`}>Типы компаний</Link>
</PrivateMenuItem>
<PrivateMenuItem key={'role'} permission={'role_editor'}>
<Link to={`${rootPath}/role`}>Роли</Link>
</PrivateMenuItem>
@ -55,6 +59,7 @@ export const AdminPanel = () => {
<PrivateRoute permission={ 'well_editor'} path={`${rootPath}/well` } component={ WellController} />
<PrivateRoute permission={ 'user_editor'} path={`${rootPath}/user` } component={ UserController} />
<PrivateRoute permission={ 'company_editor'} path={`${rootPath}/company` } component={ CompanyController} />
<PrivateRoute path={`${rootPath}/company_type`} component={CompanyTypeController} />
<PrivateRoute permission={ 'role_editor'} path={`${rootPath}/role` } component={ RoleController} />
<PrivateRoute permission={'permission_editor'} path={`${rootPath}/permission`} component={PermissionController} />
<PrivateRoute path={`${rootPath}/visit_log`} component={VisitLog} />