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 <shivamkalra98@gmail.com>
pull/9993/head
Leo Giovanetti 2023-07-13 08:59:12 -03:00 committed by GitHub
parent e79b4168f2
commit 32c6ca0ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -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>

View File

@ -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,