* Fix impersonate * align core typeorm config with metadata config + add allowImpersonation to workspace * move allowImpersonation to workspace * remove allowImpersonation from workspaceMember workspace table
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { useRecoilState } from 'recoil';
|
|
|
|
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
|
import { Toggle } from '@/ui/input/components/Toggle';
|
|
import { useUpdateWorkspaceMutation } from '~/generated/graphql';
|
|
|
|
export const ToggleImpersonate = () => {
|
|
const { enqueueSnackBar } = useSnackBar();
|
|
|
|
const [currentWorkspace, setCurrentWorkspace] = useRecoilState(
|
|
currentWorkspaceState,
|
|
);
|
|
|
|
const [updateWorkspace] = useUpdateWorkspaceMutation();
|
|
|
|
const handleChange = async (value: boolean) => {
|
|
try {
|
|
if (!currentWorkspace?.id) {
|
|
throw new Error('User is not logged in');
|
|
}
|
|
await updateWorkspace({
|
|
variables: {
|
|
input: {
|
|
allowImpersonation: value,
|
|
},
|
|
},
|
|
});
|
|
setCurrentWorkspace({
|
|
...currentWorkspace,
|
|
allowImpersonation: value,
|
|
});
|
|
} catch (err: any) {
|
|
enqueueSnackBar(err?.message, {
|
|
variant: 'error',
|
|
});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Toggle
|
|
value={currentWorkspace?.allowImpersonation}
|
|
onChange={handleChange}
|
|
/>
|
|
);
|
|
};
|