Co-authored-by: zomars <zomars@me.com>
pull/9550/head
Leo Giovanetti 2023-06-15 13:55:45 -03:00 committed by GitHub
parent 9177fe86dc
commit 6880f88dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 11 deletions

View File

@ -4,6 +4,8 @@ import { useState } from "react";
import InviteLinkSettingsModal from "@calcom/ee/teams/components/InviteLinkSettingsModal"; import InviteLinkSettingsModal from "@calcom/ee/teams/components/InviteLinkSettingsModal";
import MemberInvitationModal from "@calcom/ee/teams/components/MemberInvitationModal"; import MemberInvitationModal from "@calcom/ee/teams/components/MemberInvitationModal";
import { useOrgBrandingValues } from "@calcom/features/ee/organizations/hooks";
import { subdomainSuffix } from "@calcom/features/ee/organizations/lib/orgDomains";
import classNames from "@calcom/lib/classNames"; import classNames from "@calcom/lib/classNames";
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage"; import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
@ -105,6 +107,7 @@ export default function TeamListItem(props: Props) {
const acceptInvite = () => acceptOrLeave(true); const acceptInvite = () => acceptOrLeave(true);
const declineInvite = () => acceptOrLeave(false); const declineInvite = () => acceptOrLeave(false);
const orgBranding = useOrgBrandingValues();
const isOwner = props.team.role === MembershipRole.OWNER; const isOwner = props.team.role === MembershipRole.OWNER;
const isInvitee = !props.team.accepted; const isInvitee = !props.team.accepted;
@ -124,7 +127,11 @@ export default function TeamListItem(props: Props) {
<div className="ms-3 inline-block truncate"> <div className="ms-3 inline-block truncate">
<span className="text-default text-sm font-bold">{team.name}</span> <span className="text-default text-sm font-bold">{team.name}</span>
<span className="text-muted block text-xs"> <span className="text-muted block text-xs">
{team.slug ? `${process.env.NEXT_PUBLIC_WEBSITE_URL}/team/${team.slug}` : "Unpublished team"} {team.slug
? orgBranding
? `${orgBranding.slug}.${subdomainSuffix()}/${team.slug}`
: `${process.env.NEXT_PUBLIC_WEBSITE_URL}/team/${team.slug}`
: "Unpublished team"}
</span> </span>
</div> </div>
</div> </div>

View File

@ -49,15 +49,24 @@ export const createTeamsHandler = async ({ ctx, input }: CreateTeamsOptions) =>
const duplicatedSlugs = existingSlugs.filter((slug) => teamNames.includes(slug)); const duplicatedSlugs = existingSlugs.filter((slug) => teamNames.includes(slug));
await prisma.team.createMany({ await prisma.$transaction(
data: teamNames.flatMap((name) => { teamNames.flatMap((name) => {
if (!duplicatedSlugs.includes(name)) { if (!duplicatedSlugs.includes(name)) {
return { name, parentId: orgId, slug: slugify(name) }; return prisma.team.create({
data: {
name,
parentId: orgId,
slug: slugify(name),
members: {
create: { userId: ctx.user.id, role: MembershipRole.OWNER, accepted: true },
},
},
});
} else { } else {
return []; return [];
} }
}), })
}); );
return { duplicatedSlugs }; return { duplicatedSlugs };
}; };

View File

@ -1,4 +1,5 @@
import { prisma } from "@calcom/prisma"; import { prisma } from "@calcom/prisma";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import type { TrpcSessionUser } from "../../../trpc"; import type { TrpcSessionUser } from "../../../trpc";
@ -23,7 +24,12 @@ export const listHandler = async ({ ctx }: ListOptions) => {
orderBy: { role: "desc" }, orderBy: { role: "desc" },
}); });
return memberships.map(({ team, ...membership }) => ({ return memberships
.filter((mmship) => {
const metadata = teamMetadataSchema.parse(mmship.team.metadata);
return !metadata?.isOrganization;
})
.map(({ team, ...membership }) => ({
role: membership.role, role: membership.role,
accepted: membership.accepted, accepted: membership.accepted,
...team, ...team,