refactor: rewrite useRoles with RQ

This commit is contained in:
Rıdvan Akca
2024-03-14 16:33:08 +03:00
parent 29341f81e1
commit 9218091c33
6 changed files with 67 additions and 22 deletions

View File

@@ -4,24 +4,32 @@ import Stack from '@mui/material/Stack';
import DeleteIcon from '@mui/icons-material/Delete';
import IconButton from '@mui/material/IconButton';
import Button from '@mui/material/Button';
import { Divider, Typography } from '@mui/material';
import useRoles from 'hooks/useRoles.ee';
import useFormatMessage from 'hooks/useFormatMessage';
import ControlledAutocomplete from 'components/ControlledAutocomplete';
import TextField from 'components/TextField';
import { Divider, Typography } from '@mui/material';
function generateRoleOptions(roles) {
return roles?.map(({ name: label, id: value }) => ({ label, value }));
}
function RoleMappingsFieldArray() {
const formatMessage = useFormatMessage();
const { control } = useFormContext();
const { roles, loading: rolesLoading } = useRoles();
const { data, isLoading: isRolesLoading } = useRoles();
const roles = data?.data;
const { fields, append, remove } = useFieldArray({
control,
name: 'roleMappings',
});
const handleAppendMapping = () => append({ roleId: '', remoteRoleName: '' });
const handleRemoveMapping = (index) => () => remove(index);
return (
<>
{fields.length === 0 && (
@@ -60,7 +68,7 @@ function RoleMappingsFieldArray() {
label={formatMessage('roleMappingsForm.role')}
/>
)}
loading={rolesLoading}
loading={isRolesLoading}
required
/>
</Stack>