perf: Remove circular dependencies - wip (#24586)

* wip

* refactor(emails): remove circular dependencies from packages/emails

- Extract renderEmail imports to use direct path (../src/renderEmail) instead of index
- Create utility files for shared types and functions:
  - lib/utils/team-invite-utils.ts: TeamInvite type and utility functions
  - lib/utils/booking-redirect-types.ts: IBookingRedirect type
  - lib/utils/email-types.ts: OrganizationCreation and EmailVerifyCode types
  - lib/utils/date-formatting.ts: getFormattedDate utility function
- Update all template files to import renderEmail directly from ../src/renderEmail
- Update React template components to import from utility files instead of class templates
- This eliminates all circular dependencies within packages/emails (reduced from 234 to 0 internal circular deps)

Co-Authored-By: Volnei Munhoz <[email protected]>

* refactor(trpc): remove circular dependency in routing-forms

- Extract ZFormByResponseIdInputSchema to separate schema file
- Create getResponseWithFormFields.schema.ts to break circular dependency
- Update imports in _router.ts and getResponseWithFormFields.handler.ts
- Fix eslint warnings by updating deprecated rule names
- This eliminates the circular dependency within packages/trpc (reduced from 1 to 0 internal circular deps)

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix(emails): correct TeamInvite type definition

- Make isExistingUserMovedToOrg required (not optional)
- Make prevLink and newLink non-optional (string | null)
- Add back JSDoc comment for isAutoJoin field
- This fixes type check errors in CI

Co-Authored-By: Volnei Munhoz <[email protected]>

* wip

* Fixes types folder

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Volnei MunhozandDevin AI authored and GitHub committed 2025-10-21 12:24:47 +00:00
1 parent 6aa21aceb8
commit d82f87aa2a
56 files changed
+190 -155

No files matched your search

@@ -0,0 +1,26 @@
import dayjs from "@calcom/dayjs";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
export function getFormattedDate(calEvent: CalendarEvent, attendee: Person): string {
const inviteeTimeFormat = calEvent.organizer.timeFormat || TimeFormat.TWELVE_HOUR;
const timezone = attendee.timeZone;
const locale = attendee.language.locale;
const t = attendee.language.translate;
const getFormattedRecipientTime = (time: string, format: string) => {
return dayjs(time).tz(timezone).locale(locale).format(format);
};
const getInviteeStart = (format: string) => {
return getFormattedRecipientTime(calEvent.startTime, format);
};
const getInviteeEnd = (format: string) => {
return getFormattedRecipientTime(calEvent.endTime, format);
};
return `${getInviteeStart(inviteeTimeFormat)} - ${getInviteeEnd(inviteeTimeFormat)}, ${t(
getInviteeStart("dddd").toLowerCase()
)}, ${t(getInviteeStart("MMMM").toLowerCase())} ${getInviteeStart("D, YYYY")}`;
}
@@ -0,0 +1,59 @@
import type { TFunction } from "i18next";
import { APP_NAME } from "@calcom/lib/constants";
export type TeamInvite = {
language: TFunction;
from: string;
to: string;
teamName: string;
joinLink: string;
isCalcomMember: boolean;
/**
* We ideally should have a separate email for auto-join(when a user is automatically accepted into a team/org), but we don't have one yet.
*/
isAutoJoin: boolean;
isOrg: boolean;
parentTeamName: string | undefined;
isExistingUserMovedToOrg: boolean;
prevLink: string | null;
newLink: string | null;
};
export function getTypeOfInvite(teamInviteEvent: TeamInvite) {
if (teamInviteEvent.isOrg) {
return "TO_ORG";
}
if (teamInviteEvent.parentTeamName) {
return "TO_SUBTEAM";
}
if (teamInviteEvent.isAutoJoin) {
throw new Error("Auto-join is not supported for regular teams");
}
return "TO_REGULAR_TEAM";
}
export const getSubject = (teamInviteEvent: TeamInvite) => {
const typeOfInvite = getTypeOfInvite(teamInviteEvent);
const type = teamInviteEvent.isAutoJoin ? "added" : "invited";
const variables = {
user: teamInviteEvent.from,
team: teamInviteEvent.teamName,
appName: APP_NAME,
parentTeamName: teamInviteEvent.parentTeamName,
entity: teamInviteEvent.language(teamInviteEvent.isOrg ? "organization" : "team").toLowerCase(),
};
if (typeOfInvite === "TO_ORG") {
return teamInviteEvent.language(`email_team_invite|subject|${type}_to_org`, variables);
}
if (typeOfInvite === "TO_SUBTEAM") {
return teamInviteEvent.language(`email_team_invite|subject|${type}_to_subteam`, variables);
}
return teamInviteEvent.language(`email_team_invite|subject|${type}_to_regular_team`, variables);
};