* 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 <keithwillcode@gmail.com>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { useSession } from "next-auth/react";
|
|
import type { Dispatch } from "react";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc";
|
|
import { Dialog, ConfirmationDialogContent } from "@calcom/ui/components/dialog";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
|
|
import type { UserTableAction, UserTableState } from "./types";
|
|
|
|
export function DeleteMemberModal({
|
|
state,
|
|
dispatch,
|
|
}: {
|
|
state: UserTableState;
|
|
dispatch: Dispatch<UserTableAction>;
|
|
}) {
|
|
const { t } = useLocale();
|
|
const { data: session } = useSession();
|
|
const utils = trpc.useUtils();
|
|
const removeMemberMutation = trpc.viewer.teams.removeMember.useMutation({
|
|
onSuccess() {
|
|
utils.viewer.organizations.listMembers.invalidate();
|
|
utils.viewer.teams.get.invalidate();
|
|
utils.viewer.eventTypes.invalidate();
|
|
|
|
showToast(t("success"), "success");
|
|
|
|
// Close the modal after successful deletion
|
|
dispatch({ type: "CLOSE_MODAL" });
|
|
},
|
|
async onError(err) {
|
|
showToast(err.message, "error");
|
|
},
|
|
});
|
|
return (
|
|
<Dialog
|
|
open={state.deleteMember.showModal}
|
|
onOpenChange={(open) =>
|
|
!open &&
|
|
dispatch({
|
|
type: "CLOSE_MODAL",
|
|
})
|
|
}>
|
|
<ConfirmationDialogContent
|
|
variety="danger"
|
|
title={t("remove_member")}
|
|
confirmBtnText={t("confirm_remove_member")}
|
|
onConfirm={() => {
|
|
// Shouldn't ever happen just for type safety
|
|
if (!session?.user.org?.id || !state?.deleteMember?.user?.id) return;
|
|
|
|
removeMemberMutation.mutate({
|
|
teamIds: [session?.user.org.id],
|
|
memberIds: [state?.deleteMember?.user.id],
|
|
isOrg: true,
|
|
});
|
|
}}>
|
|
{t("remove_member_confirmation_message")}
|
|
</ConfirmationDialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|