Bug - teams being double created without slugs (#7571)
parent
b0da827483
commit
163444a0f9
|
@ -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>
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue