Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SharedRoutingFormResponseService {
private readonly slotsService: SlotsService_2024_09_04,
private readonly teamsEventTypesRepository: TeamsEventTypesRepository,
private readonly eventTypesRepository: EventTypesRepository_2024_06_14
) {}
) { }

async createRoutingFormResponseWithSlots(
routingFormId: string,
Expand Down Expand Up @@ -153,8 +153,24 @@ export class SharedRoutingFormResponseService {
}

private async extractEventTypeAndCrmParams(userId: number, routingUrl: URL) {
// Extract team and event type information
// TODO: Route action also has eventTypeId directly now and instead of using this brittle approach for getting event type by slug, we should get by eventTypeId
const urlParams = routingUrl.searchParams;

// Prefer direct eventTypeId lookup if available (more reliable than slug-based)
const eventTypeIdParam = urlParams.get("cal.eventTypeId");
if (eventTypeIdParam) {
const eventTypeId = parseInt(eventTypeIdParam, 10);
if (!isNaN(eventTypeId)) {
const eventType = await this.eventTypesRepository.getEventTypeById(eventTypeId);
if (eventType?.id) {
return {
eventTypeId: eventType.id,
crmParams: this.extractCrmParamsFromUrl(urlParams),
};
}
}
}

// Fall back to slug-based lookup for backward compatibility
const { teamId, eventTypeSlug } = this.extractTeamIdAndEventTypeSlugFromRedirectUrl(routingUrl);
const eventType = teamId
? await this.teamsEventTypesRepository.getEventTypeByTeamIdAndSlug(teamId, eventTypeSlug)
Expand All @@ -167,15 +183,20 @@ export class SharedRoutingFormResponseService {
);
}

// Extract CRM parameters from URL
const urlParams = routingUrl.searchParams;
const crmParams = {
return {
eventTypeId: eventType.id,
crmParams: this.extractCrmParamsFromUrl(routingUrl.searchParams),
};
}

private extractCrmParamsFromUrl(urlParams: URLSearchParams) {
return {
teamMemberEmail: urlParams.get("cal.crmContactOwnerEmail") || undefined,
routedTeamMemberIds: urlParams.get("cal.routedTeamMemberIds")
? urlParams
.get("cal.routedTeamMemberIds")!
.split(",")
.map((id) => parseInt(id))
.get("cal.routedTeamMemberIds")!
.split(",")
.map((id) => parseInt(id))
: undefined,
routingFormResponseId: urlParams.get("cal.routingFormResponseId")
? parseInt(urlParams.get("cal.routingFormResponseId")!)
Expand All @@ -187,11 +208,6 @@ export class SharedRoutingFormResponseService {
crmAppSlug: urlParams.get("cal.crmAppSlug") || undefined,
crmOwnerRecordType: urlParams.get("cal.crmContactOwnerRecordType") || undefined,
};

return {
eventTypeId: eventType.id,
crmParams,
};
}

private isEventTypeRedirectUrl(routingUrl: URL) {
Expand Down
1 change: 1 addition & 0 deletions packages/features/routing-forms/lib/getRoutedUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const _getRoutedUrl = async (context: Pick<GetServerSidePropsContext, "query" |
crmLookupDone: fetchCrm,
teamId: form?.teamId,
orgId: form.team?.parentId,
eventTypeId: decidedAction.eventTypeId ?? null,
}),
isEmbed: pageProps.isEmbed,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type GetUrlSearchParamsToForwardOptions = {
reroutingFormResponses?: FormResponseValueOnly;
teamId?: number | null;
orgId?: number | null;
eventTypeId?: number | null;
};

export function getUrlSearchParamsToForward({
Expand All @@ -51,6 +52,7 @@ export function getUrlSearchParamsToForward({
reroutingFormResponses,
teamId,
orgId,
eventTypeId,
}: GetUrlSearchParamsToForwardOptions) {
type Params = Record<string, string | string[]>;
const paramsFromResponse: Params = {};
Expand Down Expand Up @@ -138,6 +140,7 @@ export function getUrlSearchParamsToForward({
...(reroutingFormResponses
? { ["cal.reroutingFormResponses"]: JSON.stringify(reroutingFormResponses) }
: null),
...(eventTypeId ? { ["cal.eventTypeId"]: String(eventTypeId) } : null),
};

const allQueryURLSearchParams = new URLSearchParams();
Expand Down
Loading