Files
calendar/packages/features/ee/teams/components/DisableTeamImpersonation.tsx
T
19634073e9 refactor: improve team members page performance (#16155)
* fix: simplify workflow page and improve load time

* chore: use new endpoint

* chore: save progress

* refactor: code

* refactor: remove not requried code

* chore: remove schema

* chore: fix typ

* chore: improve

* chore: change name

* chore: remove unused

* chore: remove page

* refactor: teams page

* feat: add auto scroll

* chore: create validate unique invite

* fix: auth check

* fix: optimistic update

* chore

* fix: add loading

* fix: improvements

* chore: remove

* chore

* chore: fix teams page

* fix: team profile page

* fix: appearance page

* fix: sso view

* fix: type err

* feat: defer loading connected Apps

* fix: type err

* fix: type error

* fix: type err

* fix: connectedApps type

* chore: move

* chore: missing export

* feat: add search by name

* fix: display role change

* fix: use setInfiniteData

* chore: save progress

* test: add unit tests for loading members

* fix: test

* chore: update name

* fix: bugs and improvements

* chore: change variable name

* test: add tests for checkCanAccessMembers

* refactor: performance

---------

Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
2024-08-29 13:32:54 +05:30

49 lines
1.4 KiB
TypeScript

import { useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { showToast, SettingsToggle } from "@calcom/ui";
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;