2021-12-21 15:46:05 +05:00
|
|
|
|
import { useEffect, useState } from 'react'
|
2021-12-29 12:00:02 +05:00
|
|
|
|
|
2021-12-21 15:46:05 +05:00
|
|
|
|
import {
|
|
|
|
|
EditableTable,
|
|
|
|
|
makeActionHandler,
|
|
|
|
|
makeColumn,
|
|
|
|
|
makeStringSorter
|
2022-02-07 14:58:38 +05:00
|
|
|
|
} from '@components/Table'
|
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync } from '@components/factory'
|
|
|
|
|
import { AdminPermissionService } from '@api'
|
|
|
|
|
import { arrayOrDefault } from '@utils'
|
|
|
|
|
import { min1 } from '@utils/validationRules'
|
|
|
|
|
import { hasPermission } from '@utils/permissions'
|
2021-12-21 15:46:05 +05:00
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
makeColumn('Название', 'name', {
|
|
|
|
|
editable: true,
|
|
|
|
|
sorter: makeStringSorter('name'),
|
2021-12-30 10:25:42 +05:00
|
|
|
|
isRequired: true,
|
|
|
|
|
formItemRules: min1,
|
2021-12-21 15:46:05 +05:00
|
|
|
|
}),
|
|
|
|
|
makeColumn('Описание', 'description', {
|
|
|
|
|
editable: true,
|
|
|
|
|
sorter: makeStringSorter('description'),
|
|
|
|
|
}),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
export const PermissionController = () => {
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
|
|
|
|
const [permissions, setPermissions] = useState([])
|
|
|
|
|
|
2021-12-21 20:35:45 +05:00
|
|
|
|
const updateTable = async () => invokeWebApiWrapperAsync(
|
2021-12-21 15:46:05 +05:00
|
|
|
|
async () => {
|
|
|
|
|
const permission = await AdminPermissionService.getAll()
|
2021-12-22 12:45:30 +05:00
|
|
|
|
setPermissions(arrayOrDefault(permission))
|
2021-12-21 15:46:05 +05:00
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2022-02-07 17:44:46 +05:00
|
|
|
|
`Не удалось загрузить список прав`,
|
|
|
|
|
'Получение списка прав'
|
2021-12-21 15:46:05 +05:00
|
|
|
|
)
|
|
|
|
|
|
2021-12-21 20:35:45 +05:00
|
|
|
|
useEffect(() => updateTable(), [])
|
2021-12-21 15:46:05 +05:00
|
|
|
|
|
|
|
|
|
const handlerProps = {
|
|
|
|
|
service: AdminPermissionService,
|
|
|
|
|
setLoader: setShowLoader,
|
|
|
|
|
errorMsg: `Не удалось выполнить операцию`,
|
|
|
|
|
onComplete: updateTable
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
|
|
|
|
<EditableTable
|
|
|
|
|
bordered
|
|
|
|
|
size={'small'}
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={permissions}
|
2022-01-12 23:58:14 +05:00
|
|
|
|
pagination={{ showSizeChanger: true }}
|
2022-02-07 17:44:46 +05:00
|
|
|
|
onRowAdd={hasPermission('AdminPermission.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление права')}
|
|
|
|
|
onRowEdit={hasPermission('AdminPermission.edit') && makeActionHandler('put', handlerProps, null, 'Редактирование права')}
|
|
|
|
|
onRowDelete={hasPermission('AdminPermission.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление права')}
|
2021-12-21 15:46:05 +05:00
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default PermissionController
|