* Icon and IconName * Button and ButtonGroup * UserAvatar * AvatarGroup * Avatar * WizardLayout * Dialogs * EmptyScreen * showToast and TextField * Editor * Skeleton * Skeleton * TopBanner and showToast * Button again * more * perf: Remove app-store reference from @calcom/ui * more * Fixing types * Icon * Fixed casing * dropdown * more * Select * more * Badge * List * more * Divider * more * fix * fix type check * refactor * fix * fix * fix * fix * fix * fix * fix * fix type check * fix * fix * fix * fix * more * more * more * more * add index file to components/command * fix * fix * fix * fix imports * fix * fix * fix * fix * fix * fix * fix * fix build errors * fix build errors * fix --------- Co-authored-by: Keith Williams <[email protected]>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { useState } from "react";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
import { SettingsToggle } from "@calcom/ui/components/form";
|
|
|
|
const DisableTeamImpersonation = ({
|
|
teamId,
|
|
memberId,
|
|
disabled,
|
|
}: {
|
|
teamId: number;
|
|
memberId: number;
|
|
disabled: boolean;
|
|
}) => {
|
|
const { t } = useLocale();
|
|
|
|
const utils = trpc.useUtils();
|
|
|
|
const query = trpc.viewer.teams.getMembershipbyUser.useQuery({ teamId, memberId });
|
|
|
|
const mutation = trpc.viewer.teams.updateMembership.useMutation({
|
|
onSuccess: async () => {
|
|
showToast(t("your_user_profile_updated_successfully"), "success");
|
|
await utils.viewer.teams.getMembershipbyUser.invalidate();
|
|
},
|
|
});
|
|
const [allowImpersonation, setAllowImpersonation] = useState(!query.data?.disableImpersonation ?? true);
|
|
if (query.isPending) return <></>;
|
|
|
|
return (
|
|
<>
|
|
<SettingsToggle
|
|
toggleSwitchAtTheEnd={true}
|
|
title={t("user_impersonation_heading")}
|
|
disabled={disabled || mutation?.isPending}
|
|
description={t("team_impersonation_description")}
|
|
checked={allowImpersonation}
|
|
onCheckedChange={(_allowImpersonation) => {
|
|
setAllowImpersonation(_allowImpersonation);
|
|
mutation.mutate({ teamId, memberId, disableImpersonation: !_allowImpersonation });
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default DisableTeamImpersonation;
|