fix: hide hidden fields on booking page (#13843)

* fix: hide hidden fields on booking page

* fix: only display for organizer

* fix: hide response

* chore: fix type err

* fix: type err

* fix: unit tests
This commit is contained in:
Udit Takkar authored and GitHub committed 2024-03-13 11:54:11 -04:00
1 parent 5109075494
commit 76b33165e5
9 files changed
+57 -17

No files matched your search

@@ -193,6 +193,22 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
},
});
const userId = session?.user?.id;
const isLoggedInUserHost =
userId &&
(eventType.users.some((user) => user.id === userId) ||
eventType.hosts.some(({ user }) => user.id === userId));
if (!isLoggedInUserHost) {
// Removing hidden fields from responses
for (const key in bookingInfo.responses) {
const field = eventTypeRaw.bookingFields.find((field) => field.name === key);
if (field && !!field.hidden) {
delete bookingInfo.responses[key];
}
}
}
return {
props: {
themeBasis: eventType.team ? eventType.team.slug : eventType.users[0]?.username,
+29 -10
View File
@@ -293,6 +293,7 @@ export function expectWebhookToHaveBeenCalledWith(
? parsedBody.payload.metadata.videoCallUrl
: parsedBody.payload.metadata.videoCallUrl;
}
if (data.payload) {
if (data.payload.metadata !== undefined) {
expect(parsedBody.payload.metadata).toEqual(expect.objectContaining(data.payload.metadata));
@@ -808,11 +809,20 @@ export function expectBookingRequestedWebhookToHaveBeenFired({
// In a Pending Booking Request, we don't send the video call url
},
responses: {
name: { label: "your_name", value: booker.name },
email: { label: "email_address", value: booker.email },
name: {
label: "your_name",
value: booker.name,
isHidden: false,
},
email: {
label: "email_address",
value: booker.email,
isHidden: false,
},
location: {
label: "location",
value: { optionValue: "", value: location },
isHidden: false,
},
},
},
@@ -861,11 +871,12 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
...(videoCallUrl ? { videoCallUrl } : null),
},
responses: {
name: { label: "your_name", value: booker.name },
email: { label: "email_address", value: booker.email },
name: { label: "your_name", value: booker.name, isHidden: false },
email: { label: "email_address", value: booker.email, isHidden: false },
location: {
label: "location",
value: { optionValue: "", value: location },
isHidden: false,
},
},
},
@@ -877,8 +888,14 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
// FIXME: File this bug and link ticket here. This is a bug in the code. metadata must be sent here like other BOOKING_CREATED webhook
metadata: null,
responses: {
name: { label: "name", value: booker.name },
email: { label: "email", value: booker.email },
name: {
label: "name",
value: booker.name,
},
email: {
label: "email",
value: booker.email,
},
location: {
label: "location",
value: { optionValue: "", value: location },
@@ -912,11 +929,12 @@ export function expectBookingRescheduledWebhookToHaveBeenFired({
...(videoCallUrl ? { videoCallUrl } : null),
},
responses: {
name: { label: "your_name", value: booker.name },
email: { label: "email_address", value: booker.email },
name: { label: "your_name", value: booker.name, isHidden: false },
email: { label: "email_address", value: booker.email, isHidden: false },
location: {
label: "location",
value: { optionValue: "", value: location },
isHidden: false,
},
},
},
@@ -943,11 +961,12 @@ export function expectBookingPaymentIntiatedWebhookToHaveBeenFired({
// In a Pending Booking Request, we don't send the video call url
},
responses: {
name: { label: "your_name", value: booker.name },
email: { label: "email_address", value: booker.email },
name: { label: "your_name", value: booker.name, isHidden: false },
email: { label: "email_address", value: booker.email, isHidden: false },
location: {
label: "location",
value: { optionValue: "", value: location },
isHidden: false,
},
},
},
@@ -5,9 +5,9 @@ import type { CalendarEvent } from "@calcom/types/Calendar";
import { Info } from "./Info";
export function UserFieldsResponses(props: { calEvent: CalendarEvent; t: TFunction }) {
const { t } = props;
const labelValueMap = getLabelValueMapFromResponses(props.calEvent);
export function UserFieldsResponses(props: { calEvent: CalendarEvent; t: TFunction; isOrganizer?: boolean }) {
const { t, isOrganizer = false } = props;
const labelValueMap = getLabelValueMapFromResponses(props.calEvent, isOrganizer);
if (!labelValueMap) return null;
return (
@@ -25,6 +25,7 @@ export const BaseScheduledEmail = (
t: TFunction;
locale: string;
timeFormat: TimeFormat | undefined;
isOrganizer?: boolean;
} & Partial<React.ComponentProps<typeof BaseEmailHtml>>
) => {
const { t, timeZone, locale, timeFormat: timeFormat_ } = props;
@@ -85,7 +86,7 @@ export const BaseScheduledEmail = (
<Info label={t("description")} description={props.calEvent.description} withSpacer formatted />
<Info label={t("additional_notes")} description={props.calEvent.additionalNotes} withSpacer />
{props.includeAppsStatus && <AppsStatus calEvent={props.calEvent} t={t} />}
<UserFieldsResponses t={t} calEvent={props.calEvent} />
<UserFieldsResponses t={t} calEvent={props.calEvent} isOrganizer={props.isOrganizer} />
{props.calEvent.paymentInfo?.amount && (
<Info
label={props.calEvent.paymentInfo.paymentOption === "HOLD" ? t("no_show_fee") : t("price")}
@@ -1,5 +1,5 @@
import { BaseEmailHtml } from "../components";
import { OrganizerScheduledEmail } from "./OrganizerScheduledEmail";
import type { OrganizerScheduledEmail } from "./OrganizerScheduledEmail";
export const OrganizerPaymentRefundFailedEmail = (
props: React.ComponentProps<typeof OrganizerScheduledEmail>
@@ -41,6 +41,7 @@ export const OrganizerScheduledEmail = (
title={t(title)}
includeAppsStatus
timeFormat={timeFormat}
isOrganizer
subtitle={
<>
{props.attendeeCancelled
@@ -55,11 +55,13 @@ export const getCalEventResponses = ({
calEventUserFieldsResponses[field.name] = {
label,
value: backwardCompatibleResponses[field.name],
isHidden: !!field.hidden,
};
}
calEventResponses[field.name] = {
label,
value: backwardCompatibleResponses[field.name],
isHidden: !!field.hidden,
};
});
} else {
@@ -4,7 +4,7 @@ import { TITLE_FIELD } from "@calcom/features/bookings/lib/SystemField";
import type { bookingResponse } from "@calcom/features/bookings/lib/getBookingResponsesSchema";
import type { CalendarEvent } from "@calcom/types/Calendar";
export default function getLabelValueMapFromResponses(calEvent: CalendarEvent) {
export default function getLabelValueMapFromResponses(calEvent: CalendarEvent, isOrganizer = false) {
const { customInputs, userFieldsResponses, responses, eventTypeId } = calEvent;
const isDynamicEvent = !eventTypeId;
@@ -16,7 +16,7 @@ export default function getLabelValueMapFromResponses(calEvent: CalendarEvent) {
}
for (const [, value] of Object.entries(userFieldsResponses)) {
if (!value.label) {
if (!value.label || (!isOrganizer && value.isHidden)) {
continue;
}
labelValueMap[value.label] = value.value;
+1
View File
@@ -142,6 +142,7 @@ export type CalEventResponses = Record<
{
label: string;
value: z.infer<typeof bookingResponse>;
isHidden?: boolean;
}
>;