Roles: useDataFetching + DataGrid

This commit is contained in:
cracklesparkle
2024-06-24 17:48:52 +09:00
parent c2688855c3
commit 85f97e9e0e

View File

@ -10,19 +10,14 @@ import { GridColDef } from '@mui/x-data-grid'
interface IRoleCard { interface IRoleCard {
id: number id: number
name: string name: string
description: string
} }
interface Props { interface Props {
showModal: boolean; showModal: boolean;
} }
function Roles() { function Roles() {
const [roles, setRoles] = useState<any>(null)
const getRoles = async () => {
await RoleService.getRoles().then(response => {
setRoles(response.data)
})
}
const [showModal, setShowModal] = useState<Props>({ showModal: false }); const [showModal, setShowModal] = useState<Props>({ showModal: false });
const cards = useDataFetching<IRoleCard[]>(`${import.meta.env.VITE_API_AUTH_URL}/auth/roles/`, []) const cards = useDataFetching<IRoleCard[]>(`${import.meta.env.VITE_API_AUTH_URL}/auth/roles/`, [])
@ -33,13 +28,18 @@ function Roles() {
]; ];
return ( return (
<Box> <Box sx={{
<Button onClick={() => getRoles()}> display: 'flex',
Get roles flexDirection: 'column',
alignItems: 'flex-start',
gap: '16px'
}}>
<Button onClick={() => console.log("TODO: Add")}>
Добавить роль
</Button> </Button>
{roles && {cards &&
<DataTable rows={roles} columns={columns} /> <DataTable rows={cards} columns={columns} />
} }
</Box> </Box>
) )