2022-09-12 22:04:33 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { showToast, Switch } from "@calcom/ui";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
const DisableTeamImpersonation = ({
|
|
|
|
teamId,
|
|
|
|
memberId,
|
|
|
|
disabled,
|
|
|
|
}: {
|
|
|
|
teamId: number;
|
|
|
|
memberId: number;
|
|
|
|
disabled: boolean;
|
|
|
|
}) => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const query = trpc.viewer.teams.getMembershipbyUser.useQuery({ teamId, memberId });
|
2022-09-12 22:04:33 +00:00
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const mutation = trpc.viewer.teams.updateMembership.useMutation({
|
2022-09-12 22:04:33 +00:00
|
|
|
onSuccess: async () => {
|
|
|
|
showToast(t("your_user_profile_updated_successfully"), "success");
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.teams.getMembershipbyUser.invalidate();
|
2022-09-12 22:04:33 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
if (query.isLoading) return <></>;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="flex flex-col justify-between sm:flex-row">
|
|
|
|
<div>
|
|
|
|
<div className="flex flex-row items-center">
|
|
|
|
<h2
|
|
|
|
className={classNames(
|
|
|
|
"font-cal mb-0.5 text-sm font-semibold leading-6",
|
2023-04-05 18:14:46 +00:00
|
|
|
disabled ? "text-muted " : "text-emphasis "
|
2022-09-12 22:04:33 +00:00
|
|
|
)}>
|
|
|
|
{t("user_impersonation_heading")}
|
|
|
|
</h2>
|
|
|
|
</div>
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className={classNames("text-sm leading-5 ", disabled ? "text-gray-300" : "text-default")}>
|
2022-09-12 22:04:33 +00:00
|
|
|
{t("team_impersonation_description")}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="mt-5 sm:mt-0 sm:self-center">
|
|
|
|
<Switch
|
|
|
|
disabled={disabled}
|
2022-12-05 12:03:36 +00:00
|
|
|
defaultChecked={!query.data?.disableImpersonation}
|
2022-09-12 22:04:33 +00:00
|
|
|
onCheckedChange={(isChecked) => {
|
2022-12-05 12:03:36 +00:00
|
|
|
mutation.mutate({ teamId, memberId, disableImpersonation: !isChecked });
|
2022-09-12 22:04:33 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DisableTeamImpersonation;
|