From 32c6ca0ad5665220923154568715ea00c919ebde Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Thu, 13 Jul 2023 08:59:12 -0300 Subject: [PATCH] fix: Creating a default availability for org owner [CAL-2142] (#10108) * Creating a default availability for org owner * Full width empty state --------- Co-authored-by: Shivam Kalra --- apps/web/pages/availability/index.tsx | 1 + .../viewer/organizations/create.handler.ts | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/web/pages/availability/index.tsx b/apps/web/pages/availability/index.tsx index bb54f081bd..22911c8818 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={} /> diff --git a/packages/trpc/server/routers/viewer/organizations/create.handler.ts b/packages/trpc/server/routers/viewer/organizations/create.handler.ts index d004180925..b2f5124e78 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,