f111440e00
* feat: wip impersonate user * feat: add ability to impersonate an user * fix: remove console.log * fix: unused import
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { useRecoilValue } from 'recoil';
|
|
|
|
import { currentUserState } from '@/auth/states/currentUserState';
|
|
import { Toggle } from '@/ui/input/toggle/components/Toggle';
|
|
import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
|
|
import { useUpdateAllowImpersonationMutation } from '~/generated/graphql';
|
|
|
|
export function ToggleField() {
|
|
const { enqueueSnackBar } = useSnackBar();
|
|
|
|
const currentUser = useRecoilValue(currentUserState);
|
|
|
|
const [updateAllowImpersonation] = useUpdateAllowImpersonationMutation();
|
|
|
|
async function handleChange(value: boolean) {
|
|
try {
|
|
const { data, errors } = await updateAllowImpersonation({
|
|
variables: {
|
|
allowImpersonation: value,
|
|
},
|
|
});
|
|
|
|
if (errors || !data?.allowImpersonation) {
|
|
throw new Error('Error while updating user');
|
|
}
|
|
} catch (err: any) {
|
|
enqueueSnackBar(err?.message, {
|
|
variant: 'error',
|
|
});
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Toggle
|
|
value={currentUser?.workspaceMember?.allowImpersonation}
|
|
onChange={handleChange}
|
|
/>
|
|
);
|
|
}
|