Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Creating a default availability for org owner [CAL-2142] (#10108)

Leo Giovanetti32c6ca0ad566
diff --git a/apps/web/pages/availability/index.tsx b/apps/web/pages/availability/index.tsx
index bb54f081bdf..22911c88183 100644
--- a/apps/web/pages/availability/index.tsx
+++ b/apps/web/pages/availability/index.tsx
@@ -95,6 +95,7 @@ export function AvailabilityList({ schedules }: RouterOutputs["viewer"]["availab
Icon={Clock}
headline={t("new_schedule_heading")}
description={t("new_schedule_description")}
+ className="w-full"
buttonRaw={<NewScheduleButton />}
/>
</div>
diff --git a/packages/trpc/server/routers/viewer/organizations/create.handler.ts b/packages/trpc/server/routers/viewer/organizations/create.handler.ts
index d0041809259..b2f5124e787 100644
--- a/packages/trpc/server/routers/viewer/organizations/create.handler.ts
+++ b/packages/trpc/server/routers/viewer/organizations/create.handler.ts
@@ -4,6 +4,7 @@ import { totp } from "otplib";
import { sendOrganizationEmailVerification } from "@calcom/emails";
import { hashPassword } from "@calcom/features/auth/lib/hashPassword";
import { subdomainSuffix } from "@calcom/features/ee/organizations/lib/orgDomains";
+import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
import { IS_PRODUCTION, IS_TEAM_BILLING_ENABLED, RESERVED_SUBDOMAINS } from "@calcom/lib/constants";
import { getTranslation } from "@calcom/lib/server/i18n";
import { prisma } from "@calcom/prisma";
@@ -47,7 +48,7 @@ const vercelCreateDomain = async (domain: string) => {
return true;
};
-export const createHandler = async ({ input }: CreateOptions) => {
+export const createHandler = async ({ input, ctx }: CreateOptions) => {
const { slug, name, adminEmail, adminUsername, check } = input;
const userCollisions = await prisma.user.findUnique({
@@ -77,6 +78,9 @@ export const createHandler = async ({ input }: CreateOptions) => {
const emailDomain = adminEmail.split("@")[1];
+ const t = await getTranslation(ctx.user.locale ?? "en", "common");
+ const availability = getAvailabilityFromSchedule(DEFAULT_SCHEDULE);
+
if (check === false) {
const createOwnerOrg = await prisma.user.create({
data: {
@@ -84,6 +88,21 @@ export const createHandler = async ({ input }: CreateOptions) => {
email: adminEmail,
emailVerified: new Date(),
password: hashedPassword,
+ // Default schedule
+ schedules: {
+ create: {
+ name: t("default_schedule_name"),
+ availability: {
+ createMany: {
+ data: availability.map((schedule) => ({
+ days: schedule.days,
+ startTime: schedule.startTime,
+ endTime: schedule.endTime,
+ })),
+ },
+ },
+ },
+ },
organization: {
create: {
name,