fix: org admin delete other teams (#11247)

* fix org-admin delete other teams

* Fix delete from teams to delete from orgs endpoint
pull/11314/head^2
alannnc 2023-09-12 09:19:17 -07:00 committed by GitHub
parent 75f9f045b8
commit 1c1625d3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 6 deletions

View File

@ -24,10 +24,9 @@ export default function OtherTeamList(props: Props) {
}
}
const deleteTeamMutation = trpc.viewer.teams.delete.useMutation({
const deleteTeamMutation = trpc.viewer.organizations.deleteTeam.useMutation({
async onSuccess() {
await utils.viewer.teams.list.invalidate();
await utils.viewer.teams.hasTeamPlan.invalidate();
await utils.viewer.organizations.listOtherTeams.invalidate();
},
async onError(err) {
showToast(err.message, "error");

View File

@ -5,6 +5,9 @@ import {
Avatar,
Button,
ButtonGroup,
ConfirmationDialogContent,
Dialog,
DialogTrigger,
Dropdown,
DropdownItem,
DropdownMenuContent,
@ -13,7 +16,7 @@ import {
showToast,
Tooltip,
} from "@calcom/ui";
import { Edit2, ExternalLink, Link as LinkIcon, MoreHorizontal } from "@calcom/ui/components/icon";
import { Edit2, ExternalLink, Link as LinkIcon, MoreHorizontal, Trash } from "@calcom/ui/components/icon";
import { useOrgBranding } from "../../../organizations/context/provider";
@ -119,6 +122,32 @@ export default function OtherTeamListItem(props: Props) {
</DropdownItem>
</DropdownMenuItem>
)}
<DropdownMenuItem>
<Dialog open={hideDropdown} onOpenChange={setHideDropdown}>
<DialogTrigger asChild>
<DropdownItem
color="destructive"
type="button"
StartIcon={Trash}
onClick={(e) => {
e.stopPropagation();
}}>
{t("disband_team")}
</DropdownItem>
</DialogTrigger>
<ConfirmationDialogContent
variety="danger"
title={t("disband_team")}
confirmBtnText={t("confirm_disband_team")}
isLoading={props.isLoading}
onConfirm={() => {
props.onActionSelect("disband");
}}>
{t("disband_team_confirmation_message")}
</ConfirmationDialogContent>
</Dialog>
</DropdownMenuItem>
</DropdownMenuContent>
</Dropdown>
</ButtonGroup>

View File

@ -106,9 +106,9 @@ const OtherTeamProfileView = () => {
const isBioEmpty = !team || !team.bio || !team.bio.replace("<p><br></p>", "").length;
const deleteTeamMutation = trpc.viewer.teams.delete.useMutation({
const deleteTeamMutation = trpc.viewer.organizations.deleteTeam.useMutation({
async onSuccess() {
await utils.viewer.teams.list.invalidate();
await utils.viewer.organizations.listOtherTeams.invalidate();
showToast(t("your_team_disbanded_successfully"), "success");
router.push(`${WEBAPP_URL}/teams`);
},

View File

@ -10,6 +10,7 @@ import { ZAdminVerifyInput } from "./adminVerify.schema";
import { ZBulkUsersDelete } from "./bulkDeleteUsers.schema.";
import { ZCreateInputSchema } from "./create.schema";
import { ZCreateTeamsSchema } from "./createTeams.schema";
import { ZDeleteTeamInputSchema } from "./deleteTeam.schema";
import { ZGetMembersInput } from "./getMembers.schema";
import { ZGetOtherTeamInputSchema } from "./getOtherTeam.handler";
import { ZGetUserInput } from "./getUser.schema";
@ -120,4 +121,8 @@ export const viewerOrganizationsRouter = router({
);
return handler(opts);
}),
deleteTeam: authedOrgAdminProcedure.input(ZDeleteTeamInputSchema).mutation(async (opts) => {
const handler = await importHandler(namespaced("deleteTeam"), () => import("./deleteTeam.handler"));
return handler(opts);
}),
});

View File

@ -0,0 +1,24 @@
import { prisma } from "@calcom/prisma";
import type { TDeleteTeamInputSchema } from "./deleteTeam.schema";
type DeleteOptions = {
input: TDeleteTeamInputSchema;
};
export const deleteTeamHandler = async ({ input }: DeleteOptions) => {
// delete all memberships
await prisma.membership.deleteMany({
where: {
teamId: input.teamId,
},
});
await prisma.team.delete({
where: {
id: input.teamId,
},
});
};
export default deleteTeamHandler;

View File

@ -0,0 +1,7 @@
import { z } from "zod";
export const ZDeleteTeamInputSchema = z.object({
teamId: z.number(),
});
export type TDeleteTeamInputSchema = z.infer<typeof ZDeleteTeamInputSchema>;