forked from ddrilling/asb_cloud_front
61 lines
1.8 KiB
React
61 lines
1.8 KiB
React
|
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
|