fix: skip duplicate CRM lookup when router already performed it (#27487)

When the routing form redirects to an event type, it now passes
cal.crmLookupDone=true to indicate that the CRM contact owner lookup
was already performed. The event type SSR checks for this flag and
skips the duplicate CRM lookup, improving performance.

This fixes the scenario where no CRM contact owner exists - previously
the lookup would be performed twice (once in the router, once in SSR),
but now it's only performed once.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Joe Au-YeungandDevin AI authored and GitHub committed 2026-02-02 14:28:34 +00:00
1 parent 4ad82d1a9f
commit 1d5228ef38
5 files changed
+86 -2

No files matched your search

@@ -249,6 +249,7 @@ const _getRoutedUrl = async (context: Pick<GetServerSidePropsContext, "query" |
crmContactOwnerEmail,
crmContactOwnerRecordType,
crmAppSlug,
crmLookupDone: fetchCrm,
teamId: form?.teamId,
orgId: form.team?.parentId,
}),
@@ -350,4 +350,74 @@ describe("getUrlSearchParamsToForward", () => {
expect(fromEntriesWithDuplicateKeys(result.entries())).toEqual(expectedParams);
});
});
describe("CRM Lookup Done", () => {
it("should add cal.crmLookupDone when crmLookupDone is true", () => {
const searchParams = new URLSearchParams("?query1=value1");
const expectedParams = {
query1: "value1",
"cal.routingFormResponseId": "1",
"cal.crmLookupDone": "true",
};
const result = getUrlSearchParamsToForward({
formResponse: {},
fields: [],
searchParams,
teamMembersMatchingAttributeLogic: null,
formResponseId: 1,
queuedFormResponseId: null,
attributeRoutingConfig: null,
crmLookupDone: true,
});
expect(fromEntriesWithDuplicateKeys(result.entries())).toEqual(expectedParams);
});
it("should not add cal.crmLookupDone when crmLookupDone is false", () => {
const searchParams = new URLSearchParams("?query1=value1");
const expectedParams = {
query1: "value1",
"cal.routingFormResponseId": "1",
};
const result = getUrlSearchParamsToForward({
formResponse: {},
fields: [],
searchParams,
teamMembersMatchingAttributeLogic: null,
formResponseId: 1,
queuedFormResponseId: null,
attributeRoutingConfig: null,
crmLookupDone: false,
});
expect(fromEntriesWithDuplicateKeys(result.entries())).toEqual(expectedParams);
});
it("should add both CRM contact owner email and crmLookupDone when both are provided", () => {
const searchParams = new URLSearchParams("?query1=value1");
const expectedParams = {
query1: "value1",
"cal.routingFormResponseId": "1",
"cal.crmContactOwnerEmail": "[email protected]",
"cal.crmContactOwnerRecordType": "Contact",
"cal.crmAppSlug": "salesforce",
"cal.crmLookupDone": "true",
};
const result = getUrlSearchParamsToForward({
formResponse: {},
fields: [],
searchParams,
teamMembersMatchingAttributeLogic: null,
formResponseId: 1,
queuedFormResponseId: null,
attributeRoutingConfig: null,
crmContactOwnerEmail: "[email protected]",
crmContactOwnerRecordType: "Contact",
crmAppSlug: "salesforce",
crmLookupDone: true,
});
expect(fromEntriesWithDuplicateKeys(result.entries())).toEqual(expectedParams);
});
});
});
@@ -30,6 +30,7 @@ type GetUrlSearchParamsToForwardOptions = {
crmContactOwnerEmail?: string | null;
crmContactOwnerRecordType?: string | null;
crmAppSlug?: string | null;
crmLookupDone?: boolean;
reroutingFormResponses?: FormResponseValueOnly;
teamId?: number | null;
orgId?: number | null;
@@ -46,6 +47,7 @@ export function getUrlSearchParamsToForward({
crmContactOwnerEmail,
crmContactOwnerRecordType,
crmAppSlug,
crmLookupDone,
reroutingFormResponses,
teamId,
orgId,
@@ -132,6 +134,7 @@ export function getUrlSearchParamsToForward({
...(crmContactOwnerEmail ? { ["cal.crmContactOwnerEmail"]: crmContactOwnerEmail } : null),
...(crmContactOwnerRecordType ? { ["cal.crmContactOwnerRecordType"]: crmContactOwnerRecordType } : null),
...(crmAppSlug ? { ["cal.crmAppSlug"]: crmAppSlug } : null),
...(crmLookupDone ? { ["cal.crmLookupDone"]: "true" } : null),
...(reroutingFormResponses
? { ["cal.reroutingFormResponses"]: JSON.stringify(reroutingFormResponses) }
: null),