Skip to content

Scheduling infrastructure for absolutely everyone.

feat: enable all users to create platform team (#17707)

Rajiv Sahalf743db9eaa21
diff --git a/packages/features/ee/platform/components/CreateANewPlatformForm.tsx b/packages/features/ee/platform/components/CreateANewPlatformForm.tsx
index d79a20c6619..cfa886215b7 100644
--- a/packages/features/ee/platform/components/CreateANewPlatformForm.tsx
+++ b/packages/features/ee/platform/components/CreateANewPlatformForm.tsx
@@ -5,6 +5,7 @@ import { useSession, signIn } from "next-auth/react";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
+import { uuid } from "short-uuid";
import { deriveOrgNameFromEmail } from "@calcom/ee/organizations/components/CreateANewOrganizationForm";
import { deriveSlugFromEmail } from "@calcom/ee/organizations/components/CreateANewOrganizationForm";
@@ -89,7 +90,7 @@ const CreateANewPlatformFormChild = ({ session }: { session: Ensure<SessionConte
setServerErrorMessage(null);
createOrganizationMutation.mutate({
...v,
- slug: `${v.name.toLocaleLowerCase()}_platform`,
+ slug: `${v.name.toLocaleLowerCase()}-platform-${uuid().substring(0, 20)}`,
});
}
}}>
diff --git a/packages/trpc/server/routers/viewer/organizations/create.handler.ts b/packages/trpc/server/routers/viewer/organizations/create.handler.ts
index 2ccacb2fd78..34ca79e53c2 100644
--- a/packages/trpc/server/routers/viewer/organizations/create.handler.ts
+++ b/packages/trpc/server/routers/viewer/organizations/create.handler.ts
@@ -99,6 +99,8 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
id: true,
role: true,
email: true,
+ completedOnboarding: true,
+ emailVerified: true,
teams: {
select: {
team: {
@@ -116,6 +118,7 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
if (!loggedInUser) throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized." });
const IS_USER_ADMIN = loggedInUser.role === UserPermissionRole.ADMIN;
+ const verifiedUser = loggedInUser.completedOnboarding && !!loggedInUser.emailVerified;
// We only allow creating an annual billing period if you are a system admin
const billingPeriod = (IS_USER_ADMIN ? billingPeriodRaw : BillingPeriod.MONTHLY) ?? BillingPeriod.MONTHLY;
@@ -131,7 +134,14 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
});
}
- if (isNotACompanyEmail(orgOwnerEmail)) {
+ if (isPlatform && !verifiedUser) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "You need to complete onboarding before creating a platform team",
+ });
+ }
+
+ if (isNotACompanyEmail(orgOwnerEmail) && !isPlatform) {
throw new TRPCError({ code: "BAD_REQUEST", message: "Use company email to create an organization" });
}