fix: Handle account user lookup fields for queued form responses (#23811)
* Add constants for queued response id query string * Ignore eslint - app store imports * Return `routingFormResponseId` or `queuedFormResponseId` from URL params * Pass routingForm params to `getTeamMemberEmailForResponseOrContact` * Handle getting form responses for queued form responses * Type fix * add test * Add tests --------- Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
4 files changed
+318
-189
No files matched your search
@@ -1 +1,2 @@
|
||||
export const ROUTING_FORM_RESPONSE_ID_QUERY_STRING = "cal.routingFormResponseId";
|
||||
export const ROUTING_FORM_QUEUED_RESPONSE_ID_QUERY_STRING = "cal.queuedFormResponseId";
|
||||
@@ -125,6 +125,7 @@
|
||||
<div id="cal-booking-routingFormFullPrerender">
|
||||
<hr/>
|
||||
<a href="?only=ns:routingFormFullPrerender&debug=1&[email protected]">Routing Form - Prerender Headless Router itself queuing the form response</a>
|
||||
NOTE: Pass query param param.formId=FORM_UID_HERE to test with a particular routing form
|
||||
<p>1. As page is loading, we prerender the headless router for the email passed as param.email</p>
|
||||
<p>2. Whenever email changes and onblur happens, the prerender is triggered for the new email and previous prerendered modal is removed</p>
|
||||
<p>3. The prerender of the headless router queues the form response and doesn't really record it. When the actual booking is made, the form response is recorded from the queue</p>
|
||||
@@ -145,7 +146,8 @@
|
||||
});
|
||||
window.routingFormFullPrerender = {
|
||||
buildRouterUrl: ({skills, location, name, email, formId}) => {
|
||||
return `router?form=${formId}&skills=${skills}&Location=${location}&name=${name}&Email=${email}&Rating=5`;
|
||||
// Send `email` as well as `Email` because E2e Tests currently use `Email` and `email` is needed by contact owner lookup. It doesn't accept Uppercase Email
|
||||
return `router?form=${formId}&skills=${skills}&Location=${location}&name=${name}&Email=${email}&email=${email}&Rating=5`;
|
||||
},
|
||||
onFormSubmit: (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import type { ParsedUrlQuery } from "querystring";
|
||||
|
||||
/* eslint-disable */
|
||||
import { getCRMContactOwnerForRRLeadSkip } from "@calcom/app-store/_utils/CRMRoundRobinSkip";
|
||||
import { ROUTING_FORM_RESPONSE_ID_QUERY_STRING } from "@calcom/app-store/routing-forms/lib/constants";
|
||||
import {
|
||||
ROUTING_FORM_RESPONSE_ID_QUERY_STRING,
|
||||
ROUTING_FORM_QUEUED_RESPONSE_ID_QUERY_STRING,
|
||||
} from "@calcom/app-store/routing-forms/lib/constants";
|
||||
import { enabledAppSlugs } from "@calcom/app-store/routing-forms/lib/enabledApps";
|
||||
import type { AttributeRoutingConfig, LocalRoute } from "@calcom/app-store/routing-forms/types/types";
|
||||
import { zodRoutes as routesSchema } from "@calcom/app-store/routing-forms/zod";
|
||||
|
||||
/* eslint-enable */
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { RoutingFormResponseRepository } from "@calcom/lib/server/repository/formResponse";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
@@ -38,16 +45,25 @@ async function findUserByEmailWhoIsAHostOfEventType({
|
||||
});
|
||||
}
|
||||
|
||||
/** Returns the form response id or the queued response id */
|
||||
function getRoutingFormResponseIdFromQuery(query: ParsedUrlQuery) {
|
||||
const routingFormResponseIdAsNumber = Number(query[ROUTING_FORM_RESPONSE_ID_QUERY_STRING]);
|
||||
const routingFormResponseId = isNaN(routingFormResponseIdAsNumber) ? null : routingFormResponseIdAsNumber;
|
||||
return routingFormResponseId;
|
||||
|
||||
if (routingFormResponseId) return { routingFormResponseId, queuedFormResponseId: null };
|
||||
|
||||
const queuedFormResponseId = query[ROUTING_FORM_QUEUED_RESPONSE_ID_QUERY_STRING];
|
||||
if (queuedFormResponseId && typeof queuedFormResponseId === "string")
|
||||
return { queuedFormResponseId, routingFormResponseId: null };
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getAttributeRoutingConfig(
|
||||
data:
|
||||
| {
|
||||
routingFormResponseId: number;
|
||||
routingFormResponseId?: number | null;
|
||||
queuedFormResponseId?: string | null;
|
||||
eventTypeId: number;
|
||||
}
|
||||
| {
|
||||
@@ -57,20 +73,14 @@ async function getAttributeRoutingConfig(
|
||||
if ("route" in data) {
|
||||
return data.route.attributeRoutingConfig ?? null;
|
||||
}
|
||||
const { routingFormResponseId } = data;
|
||||
const { routingFormResponseId, queuedFormResponseId } = data;
|
||||
const routingFormResponseRepository = new RoutingFormResponseRepository(prisma);
|
||||
|
||||
const routingFormResponseQuery = await prisma.app_RoutingForms_FormResponse.findUnique({
|
||||
where: {
|
||||
id: routingFormResponseId,
|
||||
},
|
||||
include: {
|
||||
form: {
|
||||
select: {
|
||||
routes: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const routingFormResponseQuery = routingFormResponseId
|
||||
? await routingFormResponseRepository.findFormResponseIncludeForm({ routingFormResponseId })
|
||||
: queuedFormResponseId
|
||||
? await routingFormResponseRepository.findQueuedFormResponseIncludeForm({ queuedFormResponseId })
|
||||
: null;
|
||||
|
||||
if (!routingFormResponseQuery || !routingFormResponseQuery?.form.routes) return null;
|
||||
const parsedRoutes = routesSchema.safeParse(routingFormResponseQuery?.form.routes);
|
||||
@@ -196,12 +206,14 @@ async function getTeamMemberEmailForResponseOrContact({
|
||||
bookerEmail,
|
||||
eventData,
|
||||
routingFormResponseId,
|
||||
queuedFormResponseId,
|
||||
chosenRoute,
|
||||
crmAppSlug,
|
||||
}: {
|
||||
bookerEmail: string;
|
||||
eventData: EventData;
|
||||
routingFormResponseId?: number | null;
|
||||
queuedFormResponseId?: string | null;
|
||||
/**
|
||||
* If provided, we won't go look for the route from DB.
|
||||
*/
|
||||
@@ -216,11 +228,12 @@ async function getTeamMemberEmailForResponseOrContact({
|
||||
const eventTypeId = eventData.id;
|
||||
if (eventData.schedulingType !== SchedulingType.ROUND_ROBIN) return returnNullValue;
|
||||
|
||||
const attributeRoutingConfigGetterData = routingFormResponseId
|
||||
? { routingFormResponseId, eventTypeId }
|
||||
: chosenRoute
|
||||
? { route: chosenRoute }
|
||||
: null;
|
||||
const attributeRoutingConfigGetterData =
|
||||
routingFormResponseId || queuedFormResponseId
|
||||
? { routingFormResponseId, queuedFormResponseId, eventTypeId }
|
||||
: chosenRoute
|
||||
? { route: chosenRoute }
|
||||
: null;
|
||||
|
||||
// If we have found crmAppSlug, it means that the CRM App in the routing-form will handle the logic
|
||||
if (attributeRoutingConfigGetterData && crmAppSlug) {
|
||||
@@ -271,13 +284,15 @@ export async function getTeamMemberEmailForResponseOrContactUsingUrlQuery({
|
||||
|
||||
const crmAppSlug = getEnabledRoutingFormAppSlugFromQuery(query);
|
||||
|
||||
const routingFormResponseId = getRoutingFormResponseIdFromQuery(query);
|
||||
const routingFormResponseIdAndQueuedFormResponseId = getRoutingFormResponseIdFromQuery(query);
|
||||
|
||||
return await getTeamMemberEmailForResponseOrContact({
|
||||
bookerEmail: query.email,
|
||||
eventData,
|
||||
routingFormResponseId,
|
||||
chosenRoute,
|
||||
crmAppSlug,
|
||||
...(routingFormResponseIdAndQueuedFormResponseId
|
||||
? { ...routingFormResponseIdAndQueuedFormResponseId }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user