Skip to content

Commit d022fb1

Browse files
committed
Merge branch 'fix-custom-event-redirect-routing-forms' of https://github.com/calcom/cal.com into fix-custom-event-redirect-routing-forms
2 parents 672f5ca + f7bbb69 commit d022fb1

File tree

9 files changed

+54
-269
lines changed

9 files changed

+54
-269
lines changed

packages/app-store/routing-forms/__tests__/TestFormDialog.test.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,6 @@ describe("TestFormDialog", () => {
256256

257257
it("submits the form and shows test results for Event Type", async () => {
258258
mockEventTypeRedirectUrlMatchingRoute();
259-
mockFindTeamMembersMatchingAttributeLogicResponse({
260-
result: {
261-
users: [{ email: "[email protected]" }],
262-
},
263-
checkedFallback: false,
264-
});
265259
render(
266260
<TestFormRenderer
267261
isMobile={true}

packages/app-store/routing-forms/components/_components/TestForm.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { showToast } from "@calcom/ui/components/toast";
1616

1717
import { TRPCClientError } from "@trpc/react-query";
1818

19-
import { getAbsoluteEventTypeRedirectUrl } from "../../getEventTypeRedirectUrl";
2019
import { findMatchingRoute } from "../../lib/processRoute";
2120
import { substituteVariables } from "../../lib/substituteVariables";
2221
import type { SingleFormComponentProps } from "../../types/shared";
@@ -93,7 +92,6 @@ export const TestForm = ({
9392
const { t } = useLocale();
9493
const [response, setResponse] = useState<FormResponse>({});
9594
const [chosenRoute, setChosenRoute] = useState<NonRouterRoute | null>(null);
96-
const [eventTypeUrlWithoutParams, setEventTypeUrlWithoutParams] = useState("");
9795
const searchParams = useCompatSearchParams();
9896
const [membersMatchResult, setMembersMatchResult] = useState<MembersMatchResultType | null>(null);
9997
const [showResults, setShowResults] = useState(false);
@@ -129,7 +127,6 @@ export const TestForm = ({
129127

130128
function testRouting() {
131129
const route = findMatchingRoute({ form, response });
132-
let eventTypeRedirectUrl: string | null = null;
133130

134131
// Create a copy of the route with substituted variables for display
135132
let displayRoute = route;
@@ -142,22 +139,14 @@ export const TestForm = ({
142139
value: substitutedUrl,
143140
},
144141
};
145-
146-
if ("team" in form) {
147-
eventTypeRedirectUrl = getAbsoluteEventTypeRedirectUrl({
148-
eventTypeRedirectUrl: substitutedUrl,
149-
form,
150-
allURLSearchParams: new URLSearchParams(),
151-
});
152-
setEventTypeUrlWithoutParams(eventTypeRedirectUrl);
153-
}
154142
}
155143

156144
setChosenRoute(displayRoute || null);
157145
setShowResults(true);
158146

159147
if (!route) return;
160148

149+
// Custom Event Type Redirect URL has eventTypeId=0. Also, findTeamMembersMatchingAttributeLogicMutation can't work without eventTypeId
161150
if (supportsTeamMembersMatchingLogic && route.action.eventTypeId) {
162151
findTeamMembersMatchingAttributeLogicMutation.mutate({
163152
formId: form.id,

packages/app-store/routing-forms/lib/reportingUtils.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/app-store/routing-forms/pages/routing-link/[...appPages].tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ function RoutingForm({ form, profile, ...restProps }: Props) {
137137
if (decidedAction.type === "customPageMessage") {
138138
setCustomPageMessage(decidedAction.value);
139139
} else if (decidedAction.type === "eventTypeRedirectUrl") {
140-
const eventTypeUrlWithResolvedVariables = substituteVariables(
141-
decidedAction.value,
142-
chosenRouteWithFormResponse.response,
143-
fields
144-
);
140+
const eventTypeUrlWithResolvedVariables = substituteVariables(decidedAction.value, response, fields);
145141
router.push(
146142
getAbsoluteEventTypeRedirectUrlWithEmbedSupport({
147143
form,

packages/app-store/routing-forms/trpc/_router.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ZFormQueryInputSchema } from "./formQuery.schema";
99
import { ZGetAttributesForTeamInputSchema } from "./getAttributesForTeam.schema";
1010
import { ZGetIncompleteBookingSettingsInputSchema } from "./getIncompleteBookingSettings.schema";
1111
import { forms } from "./procedures/forms";
12-
import { ZReportInputSchema } from "./report.schema";
1312
import { ZSaveIncompleteBookingSettingsInputSchema } from "./saveIncompleteBookingSettings.schema";
1413

1514
// eslint-disable-next-line @typescript-eslint/ban-types
@@ -76,11 +75,6 @@ const appRoutingForms = router({
7675
return handler({ ctx, input });
7776
}),
7877

79-
report: authedProcedure.input(ZReportInputSchema).query(async ({ ctx, input }) => {
80-
const handler = await getHandler("report", () => import("./report.handler"));
81-
return handler({ ctx, input });
82-
}),
83-
8478
getAttributesForTeam: authedProcedure
8579
.input(ZGetAttributesForTeamInputSchema)
8680
.query(async ({ ctx, input }) => {

packages/app-store/routing-forms/trpc/report.handler.ts

Lines changed: 0 additions & 182 deletions
This file was deleted.

packages/lib/server/service/routingForm/responseData/ensureStringOrStringArray.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/lib/server/service/routingForm/responseData/getHumanReadableFieldResponseValue.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
11
import type { Field, FormResponse } from "@calcom/app-store/routing-forms/types/types";
22

3-
import { ensureStringOrStringArray } from "./ensureStringOrStringArray";
4-
import { getLabelsFromOptionIds } from "./getLabelsFromOptionIds";
3+
/**
4+
* Ensures a value is either a string or string array.
5+
* Converts numbers to strings.
6+
*
7+
* @param value - The value to normalize
8+
* @returns String or string array
9+
*/
10+
11+
function ensureStringOrStringArray(value: string | number | (string | number)[]): string | string[] {
12+
if (typeof value === "string") {
13+
return value;
14+
} else if (value instanceof Array) {
15+
return value.map((v) => v.toString());
16+
}
17+
return [value.toString()];
18+
}
19+
20+
/**
21+
* Get labels from option IDs for fields with options (select, multiselect, radio).
22+
* Handles legacy cases where the value might already be a label.
23+
*
24+
* @param options - The field options array
25+
* @param optionIds - The option ID(s) to get labels for
26+
* @returns The label(s) corresponding to the option ID(s)
27+
*/
28+
29+
function getLabelsFromOptionIds({
30+
options,
31+
optionIds,
32+
}: {
33+
options: NonNullable<Field["options"]>;
34+
optionIds: string | string[];
35+
}) {
36+
if (optionIds instanceof Array) {
37+
const labels = optionIds.map((optionId) => {
38+
const foundOption = options.find((option) => option.id === optionId);
39+
// It would mean that the optionId is actually a label which is why it isn't matching any option id.
40+
// Fallback to optionId(i.e. label) which was the case with legacy options
41+
if (!foundOption) {
42+
return optionId;
43+
}
44+
return foundOption.label;
45+
});
46+
return labels;
47+
} else {
48+
const foundOption = options.find((option) => option.id === optionIds);
49+
if (!foundOption) {
50+
return [optionIds];
51+
}
52+
return [foundOption.label];
53+
}
54+
}
555

656
/**
757
* Get the human-readable value for a field response.

packages/lib/server/service/routingForm/responseData/getLabelsFromOptionIds.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)