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 { invokeWebApiWrapperAsync } from '../../components/factory'
|
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
|
|
|
|
import {
|
|
|
|
|
EditableTable,
|
|
|
|
|
makeActionHandler,
|
|
|
|
|
makeColumn,
|
|
|
|
|
makeStringSorter
|
|
|
|
|
} from '../../components/Table'
|
|
|
|
|
import { AdminPermissionService } from '../../services/api'
|
2021-12-22 12:45:30 +05:00
|
|
|
|
import { arrayOrDefault } from '../../utils'
|
2021-12-30 10:25:42 +05:00
|
|
|
|
import { min1 } from '../../utils/validationRules'
|
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,
|
|
|
|
|
`Не удалось загрузить список прав`
|
|
|
|
|
)
|
|
|
|
|
|
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}
|
|
|
|
|
onRowAdd={makeActionHandler('insert', handlerProps)}
|
2022-01-11 16:03:59 +05:00
|
|
|
|
onRowEdit={makeActionHandler('put', handlerProps)}
|
2021-12-21 15:46:05 +05:00
|
|
|
|
onRowDelete={makeActionHandler('delete', handlerProps)}
|
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default PermissionController
|