refactor(web): remove typescript
This commit is contained in:
@@ -6,7 +6,6 @@ import Stack from '@mui/material/Stack';
|
||||
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
||||
import * as React from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
|
||||
import Container from 'components/Container';
|
||||
import Form from 'components/Form';
|
||||
import PageTitle from 'components/PageTitle';
|
||||
@@ -15,31 +14,21 @@ import TextField from 'components/TextField';
|
||||
import * as URLS from 'config/urls';
|
||||
import { UPDATE_ROLE } from 'graphql/mutations/update-role.ee';
|
||||
import {
|
||||
RoleWithComputedPermissions,
|
||||
getPermissions,
|
||||
getRoleWithComputedPermissions,
|
||||
} from 'helpers/computePermissions.ee';
|
||||
import useFormatMessage from 'hooks/useFormatMessage';
|
||||
import useRole from 'hooks/useRole.ee';
|
||||
|
||||
type EditRoleParams = {
|
||||
roleId: string;
|
||||
};
|
||||
|
||||
export default function EditRole(): React.ReactElement {
|
||||
export default function EditRole() {
|
||||
const formatMessage = useFormatMessage();
|
||||
const [updateRole, { loading }] = useMutation(UPDATE_ROLE);
|
||||
const navigate = useNavigate();
|
||||
const { roleId } = useParams<EditRoleParams>();
|
||||
const { roleId } = useParams();
|
||||
const { role, loading: roleLoading } = useRole(roleId);
|
||||
const enqueueSnackbar = useEnqueueSnackbar();
|
||||
|
||||
const handleRoleUpdate = async (
|
||||
roleData: Partial<RoleWithComputedPermissions>
|
||||
) => {
|
||||
const handleRoleUpdate = async (roleData) => {
|
||||
try {
|
||||
const newPermissions = getPermissions(roleData.computedPermissions);
|
||||
|
||||
await updateRole({
|
||||
variables: {
|
||||
input: {
|
||||
@@ -50,22 +39,18 @@ export default function EditRole(): React.ReactElement {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
enqueueSnackbar(formatMessage('editRole.successfullyUpdated'), {
|
||||
variant: 'success',
|
||||
SnackbarProps: {
|
||||
'data-test': 'snackbar-edit-role-success',
|
||||
},
|
||||
});
|
||||
|
||||
navigate(URLS.ROLES);
|
||||
} catch (error) {
|
||||
throw new Error('Failed while updating!');
|
||||
}
|
||||
};
|
||||
|
||||
const roleWithComputedPermissions = getRoleWithComputedPermissions(role);
|
||||
|
||||
return (
|
||||
<Container sx={{ py: 3, display: 'flex', justifyContent: 'center' }}>
|
||||
<Grid container item xs={12} sm={10} md={9}>
|
Reference in New Issue
Block a user