Scheduling infrastructure for absolutely everyone.
fix: circular dependencies (#20378)
Udit Takkar596e9b4e5a19
diff --git a/apps/web/playwright/apps/conferencing/conferencingApps.e2e.ts b/apps/web/playwright/apps/conferencing/conferencingApps.e2e.tsindex 890670dfdf5..dc88624d570 100644--- a/apps/web/playwright/apps/conferencing/conferencingApps.e2e.ts+++ b/apps/web/playwright/apps/conferencing/conferencingApps.e2e.ts@@ -1,11 +1,5 @@import { test } from "../../lib/fixtures";--export type TApp = {- slug: string;- type: string;- organizerInputPlaceholder?: string;- label: string;-};+import type { TApp } from "./types";const APP: TApp = {slug: "around",diff --git a/apps/web/playwright/apps/conferencing/types.ts b/apps/web/playwright/apps/conferencing/types.tsnew file mode 100644index 00000000000..a33c137d011--- /dev/null+++ b/apps/web/playwright/apps/conferencing/types.ts@@ -0,0 +1,6 @@+export type TApp = {+ slug: string;+ type: string;+ organizerInputPlaceholder?: string;+ label: string;+};diff --git a/apps/web/playwright/availability.e2e.ts b/apps/web/playwright/availability.e2e.tsindex f4fb63c534a..03fb165f930 100644--- a/apps/web/playwright/availability.e2e.ts+++ b/apps/web/playwright/availability.e2e.ts@@ -3,7 +3,8 @@ import { expect } from "@playwright/test";import dayjs from "@calcom/dayjs";import { test } from "./lib/fixtures";-import { localize, submitAndWaitForResponse } from "./lib/testUtils";+import { localize } from "./lib/localize";+import { submitAndWaitForResponse } from "./lib/testUtils";test.describe.configure({ mode: "parallel" });diff --git a/apps/web/playwright/fixtures/apps.ts b/apps/web/playwright/fixtures/apps.tsindex bda5c11c701..955474a4f70 100644--- a/apps/web/playwright/fixtures/apps.ts+++ b/apps/web/playwright/fixtures/apps.ts@@ -1,6 +1,6 @@import { expect, type Page } from "@playwright/test";-import type { TApp } from "../apps/conferencing/conferencingApps.e2e";+import type { TApp } from "../apps/conferencing/types";import {bookTimeSlot,gotoBookingPage,diff --git a/apps/web/playwright/fixtures/eventTypes.ts b/apps/web/playwright/fixtures/eventTypes.tsindex 3124dd821cd..6a76220d886 100644--- a/apps/web/playwright/fixtures/eventTypes.ts+++ b/apps/web/playwright/fixtures/eventTypes.ts@@ -1,6 +1,6 @@import { expect, type Page } from "@playwright/test";-import { localize } from "../lib/testUtils";+import { localize } from "../lib/localize";export function createEventTypeFixture(page: Page) {return {diff --git a/apps/web/playwright/fixtures/regularBookings.ts b/apps/web/playwright/fixtures/regularBookings.tsindex 61ea24c4f1f..b587a5947e2 100644--- a/apps/web/playwright/fixtures/regularBookings.ts+++ b/apps/web/playwright/fixtures/regularBookings.ts@@ -2,7 +2,8 @@ import { expect, type Page } from "@playwright/test";import type { MembershipRole } from "@calcom/prisma/enums";-import { localize, submitAndWaitForResponse } from "../lib/testUtils";+import { localize } from "../lib/localize";+import { submitAndWaitForResponse } from "../lib/testUtils";import type { createUsersFixture } from "./users";export const scheduleSuccessfullyText = "This meeting is scheduled";diff --git a/apps/web/playwright/fixtures/workflows.ts b/apps/web/playwright/fixtures/workflows.tsindex cdd64156e66..228297dde78 100644--- a/apps/web/playwright/fixtures/workflows.ts+++ b/apps/web/playwright/fixtures/workflows.ts@@ -4,7 +4,7 @@ import { expect, type Page } from "@playwright/test";import prisma from "@calcom/prisma";import { WorkflowTriggerEvents } from "@calcom/prisma/enums";-import { localize } from "../lib/testUtils";+import { localize } from "../lib/localize";type CreateWorkflowProps = {name?: string;diff --git a/apps/web/playwright/lib/localize.ts b/apps/web/playwright/lib/localize.tsnew file mode 100644index 00000000000..2afc3d46d3e--- /dev/null+++ b/apps/web/playwright/lib/localize.ts@@ -0,0 +1,11 @@+import { loadJSON } from "./loadJSON";++// Provide an standalone localize utility not managed by next-i18n+export async function localize(locale: string) {+ const localeModule = `../../public/static/locales/${locale}/common.json`;+ const localeMap = loadJSON(localeModule);+ return (message: string) => {+ if (message in localeMap) return localeMap[message];+ throw "No locale found for the given entry message";+ };+}diff --git a/apps/web/playwright/lib/testUtils.ts b/apps/web/playwright/lib/testUtils.tsindex 257507345c6..84762de8c42 100644--- a/apps/web/playwright/lib/testUtils.ts+++ b/apps/web/playwright/lib/testUtils.ts@@ -14,7 +14,6 @@ import { BookingStatus, SchedulingType } from "@calcom/prisma/enums";import type { createEmailsFixture } from "../fixtures/emails";import type { Fixtures } from "./fixtures";-import { loadJSON } from "./loadJSON";type Request = IncomingMessage & { body?: unknown };type RequestHandlerOptions = { req: Request; res: ServerResponse };@@ -178,16 +177,6 @@ export async function expectSlotNotAllowedToBook(page: Page) {await expect(page.locator("[data-testid=slot-not-allowed-to-book]")).toBeVisible();}-// Provide an standalone localize utility not managed by next-i18n-export async function localize(locale: string) {- const localeModule = `../../public/static/locales/${locale}/common.json`;- const localeMap = loadJSON(localeModule);- return (message: string) => {- if (message in localeMap) return localeMap[message];- throw "No locale found for the given entry message";- };-}-export const createNewEventType = async (page: Page, args: { eventTitle: string }) => {await page.click("[data-testid=new-event-type]");const eventTitle = args.eventTitle;diff --git a/apps/web/playwright/login.e2e.ts b/apps/web/playwright/login.e2e.tsindex 9f089080c7c..3a898e56299 100644--- a/apps/web/playwright/login.e2e.ts+++ b/apps/web/playwright/login.e2e.ts@@ -2,7 +2,7 @@ import { expect } from "@playwright/test";import { login } from "./fixtures/users";import { test } from "./lib/fixtures";-import { localize } from "./lib/testUtils";+import { localize } from "./lib/localize";test.describe.configure({ mode: "parallel" });diff --git a/apps/web/playwright/managed-event-types.e2e.ts b/apps/web/playwright/managed-event-types.e2e.tsindex 93276ce49ca..b14d4718cfb 100644--- a/apps/web/playwright/managed-event-types.e2e.ts+++ b/apps/web/playwright/managed-event-types.e2e.ts@@ -2,9 +2,9 @@ import type { Locator, Page } from "@playwright/test";import { expect } from "@playwright/test";import { test } from "./lib/fixtures";+import { localize } from "./lib/localize";import {bookTimeSlot,- localize,submitAndWaitForResponse,selectFirstAvailableTimeSlotNextMonth,setupManagedEvent,diff --git a/apps/web/playwright/out-of-office.e2e.ts b/apps/web/playwright/out-of-office.e2e.tsindex 94ab0b575c7..1e6cc250d3f 100644--- a/apps/web/playwright/out-of-office.e2e.ts+++ b/apps/web/playwright/out-of-office.e2e.ts@@ -8,7 +8,8 @@ import prisma from "@calcom/prisma";import { MembershipRole } from "@calcom/prisma/enums";import { test } from "./lib/fixtures";-import { submitAndWaitForResponse, localize } from "./lib/testUtils";+import { localize } from "./lib/localize";+import { submitAndWaitForResponse } from "./lib/testUtils";test.describe.configure({ mode: "parallel" });test.afterEach(async ({ users }) => {diff --git a/apps/web/playwright/signup.e2e.ts b/apps/web/playwright/signup.e2e.tsindex 61ddd70226d..189ad760efb 100644--- a/apps/web/playwright/signup.e2e.ts+++ b/apps/web/playwright/signup.e2e.ts@@ -6,7 +6,8 @@ import { APP_NAME, IS_PREMIUM_USERNAME_ENABLED, IS_MAILHOG_ENABLED } from "@calcimport prisma from "@calcom/prisma";import { test } from "./lib/fixtures";-import { getEmailsReceivedByUser, localize } from "./lib/testUtils";+import { localize } from "./lib/localize";+import { getEmailsReceivedByUser } from "./lib/testUtils";import { expectInvitationEmailToBeReceived } from "./team/expects";test.describe.configure({ mode: "parallel" });diff --git a/apps/web/playwright/team/team-invitation.e2e.ts b/apps/web/playwright/team/team-invitation.e2e.tsindex 2b18d0b6db5..f32d580e32f 100644--- a/apps/web/playwright/team/team-invitation.e2e.ts+++ b/apps/web/playwright/team/team-invitation.e2e.ts@@ -5,7 +5,8 @@ import { prisma } from "@calcom/prisma";import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";import { test } from "../lib/fixtures";-import { getInviteLink, localize } from "../lib/testUtils";+import { localize } from "../lib/localize";+import { getInviteLink } from "../lib/testUtils";import { expectInvitationEmailToBeReceived } from "./expects";test.describe.configure({ mode: "parallel" });diff --git a/packages/features/bookings/lib/getBookingToDelete.ts b/packages/features/bookings/lib/getBookingToDelete.tsnew file mode 100644index 00000000000..b6b9ae31c15--- /dev/null+++ b/packages/features/bookings/lib/getBookingToDelete.ts@@ -0,0 +1,104 @@+import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";+import prisma, { bookingMinimalSelect } from "@calcom/prisma";+import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";++export async function getBookingToDelete(id: number | undefined, uid: string | undefined) {+ return await prisma.booking.findUniqueOrThrow({+ where: {+ id,+ uid,+ },+ select: {+ ...bookingMinimalSelect,+ recurringEventId: true,+ userId: true,+ user: {+ select: {+ id: true,+ username: true,+ credentials: { select: credentialForCalendarServiceSelect }, // Not leaking at the moment, be careful with+ email: true,+ timeZone: true,+ timeFormat: true,+ name: true,+ destinationCalendar: true,+ },+ },+ location: true,+ references: {+ select: {+ uid: true,+ type: true,+ externalCalendarId: true,+ credentialId: true,+ thirdPartyRecurringEventId: true,+ delegationCredentialId: true,+ },+ },+ payment: true,+ paid: true,+ eventType: {+ select: {+ slug: true,+ owner: {+ select: {+ id: true,+ hideBranding: true,+ },+ },+ team: {+ select: {+ id: true,+ name: true,+ parentId: true,+ },+ },+ parentId: true,+ parent: {+ select: {+ teamId: true,+ },+ },+ userId: true,+ recurringEvent: true,+ title: true,+ eventName: true,+ description: true,+ requiresConfirmation: true,+ price: true,+ currency: true,+ length: true,+ seatsPerTimeSlot: true,+ bookingFields: true,+ seatsShowAttendees: true,+ metadata: true,+ schedulingType: true,+ hosts: {+ select: {+ user: true,+ },+ },+ workflows: {+ select: {+ workflow: {+ select: workflowSelect,+ },+ },+ },+ },+ },+ uid: true,+ id: true,+ eventTypeId: true,+ destinationCalendar: true,+ smsReminderNumber: true,+ workflowReminders: true,+ seatsReferences: true,+ responses: true,+ iCalUID: true,+ iCalSequence: true,+ },+ });+}++export type BookingToDelete = Awaited<ReturnType<typeof getBookingToDelete>>;diff --git a/packages/features/bookings/lib/handleCancelBooking.ts b/packages/features/bookings/lib/handleCancelBooking.tsindex 2703c35ec05..ac5c6d1230f 100644--- a/packages/features/bookings/lib/handleCancelBooking.ts+++ b/packages/features/bookings/lib/handleCancelBooking.ts@@ -6,7 +6,6 @@ import { DailyLocationType } from "@calcom/app-store/locations";import dayjs from "@calcom/dayjs";import { sendCancelledEmailsAndSMS } from "@calcom/emails";import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";-import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";import { sendCancelledReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";@@ -25,133 +24,22 @@ import { safeStringify } from "@calcom/lib/safeStringify";import { getTranslation } from "@calcom/lib/server/i18n";import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";-import prisma, { bookingMinimalSelect } from "@calcom/prisma";+import prisma from "@calcom/prisma";import type { WebhookTriggerEvents } from "@calcom/prisma/enums";import { BookingStatus } from "@calcom/prisma/enums";-import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";import { bookingMetadataSchema, EventTypeMetaDataSchema, bookingCancelInput } from "@calcom/prisma/zod-utils";import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";import type { CalendarEvent } from "@calcom/types/Calendar";import { getAllCredentials } from "./getAllCredentialsForUsersOnEvent/getAllCredentials";+import { getBookingToDelete } from "./getBookingToDelete";+import type { CustomRequest, AppRouterRequest } from "./handleCancelBooking/types";import { handleInternalNote } from "./handleInternalNote";import cancelAttendeeSeat from "./handleSeats/cancel/cancelAttendeeSeat";const log = logger.getSubLogger({ prefix: ["handleCancelBooking"] });-async function getBookingToDelete(id: number | undefined, uid: string | undefined) {- return await prisma.booking.findUniqueOrThrow({- where: {- id,- uid,- },- select: {- ...bookingMinimalSelect,- recurringEventId: true,- userId: true,- user: {- select: {- id: true,- username: true,- credentials: { select: credentialForCalendarServiceSelect }, // Not leaking at the moment, be careful with- email: true,- timeZone: true,- timeFormat: true,- name: true,- destinationCalendar: true,- },- },- location: true,- references: {- select: {- uid: true,- type: true,- externalCalendarId: true,- credentialId: true,- thirdPartyRecurringEventId: true,- delegationCredentialId: true,- },- },- payment: true,- paid: true,- eventType: {- select: {- slug: true,- owner: {- select: {- id: true,- hideBranding: true,- },- },- team: {- select: {- id: true,- name: true,- parentId: true,- },- },- parentId: true,- parent: {- select: {- teamId: true,- },- },- userId: true,- recurringEvent: true,- title: true,- eventName: true,- description: true,- requiresConfirmation: true,- price: true,- currency: true,- length: true,- seatsPerTimeSlot: true,- bookingFields: true,- seatsShowAttendees: true,- metadata: true,- schedulingType: true,- hosts: {- select: {- user: true,- },- },- workflows: {- select: {- workflow: {- select: workflowSelect,- },- },- },- },- },- uid: true,- id: true,- eventTypeId: true,- destinationCalendar: true,- smsReminderNumber: true,- workflowReminders: true,- seatsReferences: true,- responses: true,- iCalUID: true,- iCalSequence: true,- },- });-}--export type BookingToDelete = Awaited<ReturnType<typeof getBookingToDelete>>;--export type AppRouterRequest = { appDirRequestBody: unknown };-export type CustomRequest = (NextApiRequest | AppRouterRequest) & {- userId?: number;- bookingToDelete?: BookingToDelete;- platformClientId?: string;- platformRescheduleUrl?: string;- platformCancelUrl?: string;- platformBookingUrl?: string;- arePlatformEmailsEnabled?: boolean;-};-export type HandleCancelBookingResponse = {success: boolean;message: string;diff --git a/packages/features/bookings/lib/handleCancelBooking/types.ts b/packages/features/bookings/lib/handleCancelBooking/types.tsnew file mode 100644index 00000000000..4b82de8c3c7--- /dev/null+++ b/packages/features/bookings/lib/handleCancelBooking/types.ts@@ -0,0 +1,14 @@+import type { NextApiRequest } from "next";++import type { BookingToDelete } from "../getBookingToDelete";++export type AppRouterRequest = { appDirRequestBody: unknown };+export type CustomRequest = (NextApiRequest | AppRouterRequest) & {+ userId?: number;+ bookingToDelete?: BookingToDelete;+ platformClientId?: string;+ platformRescheduleUrl?: string;+ platformCancelUrl?: string;+ platformBookingUrl?: string;+ arePlatformEmailsEnabled?: boolean;+};diff --git a/packages/features/bookings/lib/handleInternalNote.ts b/packages/features/bookings/lib/handleInternalNote.tsindex 0471ec16487..33ed3efe703 100644--- a/packages/features/bookings/lib/handleInternalNote.ts+++ b/packages/features/bookings/lib/handleInternalNote.ts@@ -1,7 +1,7 @@import { HttpError } from "@calcom/lib/http-error";import prisma from "@calcom/prisma";-import { type BookingToDelete } from "./handleCancelBooking";+import type { BookingToDelete } from "./getBookingToDelete";type InternalNote = {id: number;diff --git a/packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.ts b/packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.tsindex d446e6a0ba5..d769c39a47a 100644--- a/packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.ts+++ b/packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.ts@@ -18,7 +18,7 @@ import { bookingCancelAttendeeSeatSchema } from "@calcom/prisma/zod-utils";import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";import type { CalendarEvent } from "@calcom/types/Calendar";-import type { AppRouterRequest, CustomRequest } from "../../handleCancelBooking";+import type { AppRouterRequest, CustomRequest } from "../../handleCancelBooking/types";async function cancelAttendeeSeat(req: CustomRequest,diff --git a/packages/features/ee/teams/components/DeleteBulkTeamMembers.tsx b/packages/features/ee/teams/components/DeleteBulkTeamMembers.tsxindex ae284448b9d..9db7eb315ea 100644--- a/packages/features/ee/teams/components/DeleteBulkTeamMembers.tsx+++ b/packages/features/ee/teams/components/DeleteBulkTeamMembers.tsx@@ -1,10 +1,11 @@import { DataTableSelectionBar } from "@calcom/features/data-table";import { useLocale } from "@calcom/lib/hooks/useLocale";import { trpc } from "@calcom/trpc/react";+import type { RouterOutputs } from "@calcom/trpc/react";import { Dialog, DialogTrigger, ConfirmationDialogContent } from "@calcom/ui/components/dialog";import { showToast } from "@calcom/ui/components/toast";-import type { User } from "./MemberList";+export type User = RouterOutputs["viewer"]["teams"]["listMembers"]["members"][number];interface Props {users: User[];