6129444c5c
* Wip * WIP * Removed concole log * Add relations to workspace init (#2511) * Add relations to workspace init * remove logs * update prefill * add missing isSystem * comment relation fields * Migrate v2 core models to graphql schema (#2509) * migrate v2 core models to graphql schema * Migrate to new workspace member schema * Continue work * migrated-main * Finished accountOwner nested field integration on companies * Introduce bug * Fix --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com> Co-authored-by: Weiko <corentin@twenty.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { useRecoilValue } from 'recoil';
|
|
|
|
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
|
import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
|
|
import { Toggle } from '@/ui/input/components/Toggle';
|
|
import { useUpdateAllowImpersonationMutation } from '~/generated/graphql';
|
|
|
|
export const ToggleField = () => {
|
|
const { enqueueSnackBar } = useSnackBar();
|
|
|
|
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
|
|
|
const [updateAllowImpersonation] = useUpdateAllowImpersonationMutation();
|
|
|
|
const handleChange = async (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={currentWorkspaceMember?.allowImpersonation}
|
|
onChange={handleChange}
|
|
/>
|
|
);
|
|
};
|