Bug - teams being double created without slugs (#7571)

pull/7573/head^2
Joe Au-Yeung 2023-03-07 18:02:05 -05:00 committed by GitHub
parent b0da827483
commit 163444a0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -10,7 +10,7 @@ import { trpc } from "@calcom/trpc/react";
import { Avatar, Button, Form, ImageUploader, TextField } from "@calcom/ui"; import { Avatar, Button, Form, ImageUploader, TextField } from "@calcom/ui";
import { FiArrowRight } from "@calcom/ui/components/icon"; import { FiArrowRight } from "@calcom/ui/components/icon";
import { NewTeamFormValues } from "../lib/types"; import type { NewTeamFormValues } from "../lib/types";
const querySchema = z.object({ const querySchema = z.object({
returnTo: z.string(), returnTo: z.string(),
@ -140,10 +140,14 @@ export const CreateANewTeamForm = () => {
{t("cancel")} {t("cancel")}
</Button> </Button>
<Button <Button
disabled={createTeamMutation.isLoading} disabled={
newTeamFormMethods.formState.isSubmitting ||
createTeamMutation.isError ||
createTeamMutation.isLoading
}
color="primary" color="primary"
type="submit"
EndIcon={FiArrowRight} EndIcon={FiArrowRight}
type="submit"
className="w-full justify-center"> className="w-full justify-center">
{t("continue")} {t("continue")}
</Button> </Button>

View File

@ -92,6 +92,25 @@ export const viewerTeamsRouter = router({
if (nameCollisions) throw new TRPCError({ code: "BAD_REQUEST", message: "Team name already taken." }); if (nameCollisions) throw new TRPCError({ code: "BAD_REQUEST", message: "Team name already taken." });
// Ensure that the user is not duplicating a requested team
const duplicatedRequest = await ctx.prisma.team.findFirst({
where: {
members: {
some: {
userId: ctx.user.id,
},
},
metadata: {
path: ["requestedSlug"],
equals: slug,
},
},
});
if (duplicatedRequest) {
return duplicatedRequest;
}
const createTeam = await ctx.prisma.team.create({ const createTeam = await ctx.prisma.team.create({
data: { data: {
name, name,