feat: booking with phone number (#14461)
Co-authored-by: Omar López <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
85 files changed
+2078
-274
No files matched your search
@@ -14,6 +14,7 @@ import getPaymentAppData from "@calcom/lib/getPaymentAppData";
|
||||
import { useCopy } from "@calcom/lib/hooks/useCopy";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useGetTheme } from "@calcom/lib/hooks/useTheme";
|
||||
import isSmsCalEmail from "@calcom/lib/isSmsCalEmail";
|
||||
import { getEveryFreqFor } from "@calcom/lib/recurringStrings";
|
||||
import { BookingStatus, SchedulingType } from "@calcom/prisma/enums";
|
||||
import { bookingMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
@@ -322,7 +323,7 @@ function BookingListItem(booking: BookingItemProps) {
|
||||
const urlSearchParams = new URLSearchParams({
|
||||
allRemainingBookings: isTabRecurring.toString(),
|
||||
});
|
||||
if (booking.attendees[0]) urlSearchParams.set("email", booking.attendees[0].email);
|
||||
if (booking.attendees[0].email) urlSearchParams.set("email", booking.attendees[0].email);
|
||||
return `/booking/${booking.uid}?${urlSearchParams.toString()}`;
|
||||
};
|
||||
|
||||
@@ -356,6 +357,7 @@ function BookingListItem(booking: BookingItemProps) {
|
||||
email: attendee.email,
|
||||
id: attendee.id,
|
||||
noShow: attendee.noShow || false,
|
||||
phoneNumber: attendee.phoneNumber,
|
||||
};
|
||||
});
|
||||
return (
|
||||
@@ -730,6 +732,7 @@ const FirstAttendee = ({
|
||||
type AttendeeProps = {
|
||||
name?: string;
|
||||
email: string;
|
||||
phoneNumber: string | null;
|
||||
id: number;
|
||||
noShow: boolean;
|
||||
};
|
||||
@@ -740,7 +743,7 @@ type NoShowProps = {
|
||||
};
|
||||
|
||||
const Attendee = (attendeeProps: AttendeeProps & NoShowProps) => {
|
||||
const { email, name, bookingUid, isBookingInPast, noShow: noShowAttendee } = attendeeProps;
|
||||
const { email, name, bookingUid, isBookingInPast, noShow: noShowAttendee, phoneNumber } = attendeeProps;
|
||||
const { t } = useLocale();
|
||||
|
||||
const [noShow, setNoShow] = useState(noShowAttendee);
|
||||
@@ -784,38 +787,43 @@ const Attendee = (attendeeProps: AttendeeProps & NoShowProps) => {
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem className="focus:outline-none">
|
||||
<DropdownItem
|
||||
StartIcon="mail"
|
||||
href={`mailto:${email}`}
|
||||
onClick={(e) => {
|
||||
setOpenDropdown(false);
|
||||
e.stopPropagation();
|
||||
}}>
|
||||
<a href={`mailto:${email}`}>{t("email")}</a>
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
{!isSmsCalEmail(email) && (
|
||||
<DropdownMenuItem className="focus:outline-none">
|
||||
<DropdownItem
|
||||
StartIcon="mail"
|
||||
href={`mailto:${email}`}
|
||||
onClick={(e) => {
|
||||
setOpenDropdown(false);
|
||||
e.stopPropagation();
|
||||
}}>
|
||||
<a href={`mailto:${email}`}>{t("email")}</a>
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
|
||||
<DropdownMenuItem className="focus:outline-none">
|
||||
<DropdownItem
|
||||
StartIcon={isCopied ? "clipboard-check" : "clipboard"}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
copyToClipboard(email);
|
||||
const isEmailCopied = isSmsCalEmail(email);
|
||||
copyToClipboard(isEmailCopied ? email : phoneNumber ?? "");
|
||||
setOpenDropdown(false);
|
||||
showToast(t("email_copied"), "success");
|
||||
showToast(isEmailCopied ? t("email_copied") : t("phone_number_copied"), "success");
|
||||
}}>
|
||||
{!isCopied ? t("copy") : t("copied")}
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
|
||||
{isBookingInPast && (
|
||||
<DropdownMenuItem className="focus:outline-none">
|
||||
{noShow ? (
|
||||
<DropdownItem
|
||||
data-testid="unmark-no-show"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setOpenDropdown(false);
|
||||
toggleNoShow({ attendee: { noShow: false, email }, bookingUid });
|
||||
e.preventDefault();
|
||||
}}
|
||||
StartIcon="eye">
|
||||
{t("unmark_as_no_show")}
|
||||
@@ -824,9 +832,9 @@ const Attendee = (attendeeProps: AttendeeProps & NoShowProps) => {
|
||||
<DropdownItem
|
||||
data-testid="mark-no-show"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setOpenDropdown(false);
|
||||
toggleNoShow({ attendee: { noShow: true, email }, bookingUid });
|
||||
e.preventDefault();
|
||||
}}
|
||||
StartIcon="eye-off">
|
||||
{t("mark_as_no_show")}
|
||||
|
||||
+15
-4
@@ -39,6 +39,11 @@ export const getEventTypesFromDB = async (id: number) => {
|
||||
bookingFields: true,
|
||||
disableGuests: true,
|
||||
timeZone: true,
|
||||
profile: {
|
||||
select: {
|
||||
organizationId: true,
|
||||
},
|
||||
},
|
||||
teamId: true,
|
||||
owner: {
|
||||
select: userSelect,
|
||||
@@ -82,11 +87,13 @@ export const getEventTypesFromDB = async (id: number) => {
|
||||
}
|
||||
|
||||
const metadata = EventTypeMetaDataSchema.parse(eventType.metadata);
|
||||
const { profile, ...restEventType } = eventType;
|
||||
const isOrgTeamEvent = !!eventType?.team && !!profile?.organizationId;
|
||||
|
||||
return {
|
||||
isDynamic: false,
|
||||
...eventType,
|
||||
bookingFields: getBookingFieldsWithSystemFields(eventType),
|
||||
...restEventType,
|
||||
bookingFields: getBookingFieldsWithSystemFields({ ...eventType, isOrgTeamEvent }),
|
||||
metadata,
|
||||
};
|
||||
};
|
||||
@@ -101,7 +108,7 @@ export const handleSeatsEventTypeOnBooking = async (
|
||||
bookingInfo: Partial<
|
||||
Prisma.BookingGetPayload<{
|
||||
include: {
|
||||
attendees: { select: { name: true; email: true } };
|
||||
attendees: { select: { name: true; email: true; phoneNumber: true } };
|
||||
seatsReferences: { select: { referenceUid: true } };
|
||||
user: {
|
||||
select: {
|
||||
@@ -123,6 +130,7 @@ export const handleSeatsEventTypeOnBooking = async (
|
||||
attendee: {
|
||||
email: string;
|
||||
name: string;
|
||||
phoneNumber: string | null;
|
||||
};
|
||||
id: number;
|
||||
data: Prisma.JsonValue;
|
||||
@@ -141,6 +149,7 @@ export const handleSeatsEventTypeOnBooking = async (
|
||||
select: {
|
||||
name: true,
|
||||
email: true,
|
||||
phoneNumber: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -158,7 +167,9 @@ export const handleSeatsEventTypeOnBooking = async (
|
||||
if (!eventType.seatsShowAttendees && !isHost) {
|
||||
if (seatAttendee) {
|
||||
const attendee = bookingInfo?.attendees?.find((a) => {
|
||||
return a.email === seatAttendee?.attendee?.email;
|
||||
return (
|
||||
a.email === seatAttendee?.attendee?.email || a.phoneNumber === seatAttendee?.attendee?.phoneNumber
|
||||
);
|
||||
});
|
||||
bookingInfo["attendees"] = attendee ? [attendee] : [];
|
||||
} else {
|
||||
|
||||
@@ -42,6 +42,7 @@ import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery";
|
||||
import useTheme from "@calcom/lib/hooks/useTheme";
|
||||
import isSmsCalEmail from "@calcom/lib/isSmsCalEmail";
|
||||
import { getEveryFreqFor } from "@calcom/lib/recurringStrings";
|
||||
import { getIs24hClockFromLocalStorage, isBrowserLocale24h } from "@calcom/lib/timeFormat";
|
||||
import { localStorage } from "@calcom/lib/webstorage";
|
||||
@@ -144,7 +145,7 @@ export default function Success(props: PageProps) {
|
||||
|
||||
const attendees = bookingInfo?.attendees;
|
||||
|
||||
const isGmail = !!attendees.find((attendee) => attendee.email.includes("gmail.com"));
|
||||
const isGmail = !!attendees.find((attendee) => attendee?.email?.includes("gmail.com"));
|
||||
|
||||
const [is24h, setIs24h] = useState(
|
||||
props?.userTimeFormat ? props.userTimeFormat === 24 : isBrowserLocale24h()
|
||||
@@ -551,7 +552,14 @@ export default function Success(props: PageProps) {
|
||||
{attendee.name && (
|
||||
<p data-testid={`attendee-name-${attendee.name}`}>{attendee.name}</p>
|
||||
)}
|
||||
<p data-testid={`attendee-email-${attendee.email}`}>{attendee.email}</p>
|
||||
{attendee.phoneNumber && (
|
||||
<p data-testid={`attendee-phone-${attendee.phoneNumber}`}>
|
||||
{attendee.phoneNumber}
|
||||
</p>
|
||||
)}
|
||||
{!isSmsCalEmail(attendee.email) && (
|
||||
<p data-testid={`attendee-email-${attendee.email}`}>{attendee.email}</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -137,13 +137,19 @@ export async function bookFirstEvent(page: Page) {
|
||||
await bookEventOnThisPage(page);
|
||||
}
|
||||
|
||||
export const bookTimeSlot = async (page: Page, opts?: { name?: string; email?: string; title?: string }) => {
|
||||
export const bookTimeSlot = async (
|
||||
page: Page,
|
||||
opts?: { name?: string; email?: string; title?: string; attendeePhoneNumber?: string }
|
||||
) => {
|
||||
// --- fill form
|
||||
await page.fill('[name="name"]', opts?.name ?? testName);
|
||||
await page.fill('[name="email"]', opts?.email ?? testEmail);
|
||||
if (opts?.title) {
|
||||
await page.fill('[name="title"]', opts.title);
|
||||
}
|
||||
if (opts?.attendeePhoneNumber) {
|
||||
await page.fill('[name="attendeePhoneNumber"]', opts.attendeePhoneNumber ?? "+918888888888");
|
||||
}
|
||||
await page.press('[name="email"]', "Enter");
|
||||
};
|
||||
|
||||
|
||||
@@ -80,6 +80,63 @@ test.describe("Bookings", () => {
|
||||
// TODO: Assert whether the user received an email
|
||||
});
|
||||
|
||||
test("Can create a booking for Collective EventType with only phone number", async ({
|
||||
page,
|
||||
users,
|
||||
orgs,
|
||||
}) => {
|
||||
const org = await orgs.create({
|
||||
name: "TestOrg",
|
||||
});
|
||||
const teamMatesObj = [
|
||||
{ name: "teammate-1" },
|
||||
{ name: "teammate-2" },
|
||||
{ name: "teammate-3" },
|
||||
{ name: "teammate-4" },
|
||||
];
|
||||
|
||||
const owner = await users.create(
|
||||
{
|
||||
username: "pro-user",
|
||||
name: "pro-user",
|
||||
organizationId: org.id,
|
||||
roleInOrganization: MembershipRole.MEMBER,
|
||||
},
|
||||
{
|
||||
hasTeam: true,
|
||||
teammates: teamMatesObj,
|
||||
schedulingType: SchedulingType.COLLECTIVE,
|
||||
}
|
||||
);
|
||||
const { team } = await owner.getFirstTeamMembership();
|
||||
const teamEvent = await owner.getFirstTeamEvent(team.id);
|
||||
await owner.apiLogin();
|
||||
|
||||
await markPhoneNumberAsRequiredAndEmailAsOptional(page, teamEvent.id);
|
||||
|
||||
await expectPageToBeNotFound({ page, url: `/team/${team.slug}/${teamEvent.slug}` });
|
||||
await doOnOrgDomain(
|
||||
{
|
||||
orgSlug: org.slug,
|
||||
page,
|
||||
},
|
||||
async () => {
|
||||
await bookTeamEvent({
|
||||
page,
|
||||
team,
|
||||
event: teamEvent,
|
||||
opts: { attendeePhoneNumber: "+918888888888" },
|
||||
});
|
||||
// All the teammates should be in the booking
|
||||
for (const teammate of teamMatesObj.concat([{ name: owner.name || "" }])) {
|
||||
await expect(page.getByText(teammate.name, { exact: true })).toBeVisible();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// TODO: Assert whether the user received an email
|
||||
});
|
||||
|
||||
test("Can create a booking for Round Robin EventType", async ({ page, users, orgs }) => {
|
||||
const org = await orgs.create({
|
||||
name: "TestOrg",
|
||||
@@ -130,6 +187,69 @@ test.describe("Bookings", () => {
|
||||
// TODO: Assert whether the user received an email
|
||||
});
|
||||
|
||||
test("Can create a booking for Round Robin EventType with both phone number and email required", async ({
|
||||
page,
|
||||
users,
|
||||
orgs,
|
||||
}) => {
|
||||
const org = await orgs.create({
|
||||
name: "TestOrg",
|
||||
});
|
||||
const teamMatesObj = [
|
||||
{ name: "teammate-1" },
|
||||
{ name: "teammate-2" },
|
||||
{ name: "teammate-3" },
|
||||
{ name: "teammate-4" },
|
||||
];
|
||||
const owner = await users.create(
|
||||
{
|
||||
username: "pro-user",
|
||||
name: "pro-user",
|
||||
organizationId: org.id,
|
||||
roleInOrganization: MembershipRole.MEMBER,
|
||||
},
|
||||
{
|
||||
hasTeam: true,
|
||||
teammates: teamMatesObj,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
}
|
||||
);
|
||||
|
||||
const { team } = await owner.getFirstTeamMembership();
|
||||
const teamEvent = await owner.getFirstTeamEvent(team.id);
|
||||
await owner.apiLogin();
|
||||
|
||||
await markPhoneNumberAsRequiredField(page, teamEvent.id);
|
||||
|
||||
await expectPageToBeNotFound({ page, url: `/team/${team.slug}/${teamEvent.slug}` });
|
||||
|
||||
await doOnOrgDomain(
|
||||
{
|
||||
orgSlug: org.slug,
|
||||
page,
|
||||
},
|
||||
async () => {
|
||||
await bookTeamEvent({
|
||||
page,
|
||||
team,
|
||||
event: teamEvent,
|
||||
teamMatesObj,
|
||||
opts: { attendeePhoneNumber: "+918888888888" },
|
||||
});
|
||||
|
||||
// Since all the users have the same leastRecentlyBooked value
|
||||
// Anyone of the teammates could be the Host of the booking.
|
||||
const chosenUser = await page.getByTestId("booking-host-name").textContent();
|
||||
expect(chosenUser).not.toBeNull();
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
expect(teamMatesObj.concat([{ name: owner.name! }]).some(({ name }) => name === chosenUser)).toBe(
|
||||
true
|
||||
);
|
||||
}
|
||||
);
|
||||
// TODO: Assert whether the user received an email
|
||||
});
|
||||
|
||||
test("Can access booking page with event slug and team page in lowercase/uppercase/mixedcase", async ({
|
||||
page,
|
||||
orgs,
|
||||
@@ -485,6 +605,7 @@ async function bookTeamEvent({
|
||||
team,
|
||||
event,
|
||||
teamMatesObj,
|
||||
opts,
|
||||
}: {
|
||||
page: Page;
|
||||
team: {
|
||||
@@ -493,6 +614,7 @@ async function bookTeamEvent({
|
||||
};
|
||||
event: { slug: string; title: string; schedulingType: SchedulingType | null };
|
||||
teamMatesObj?: { name: string }[];
|
||||
opts?: { attendeePhoneNumber?: string };
|
||||
}) {
|
||||
// Note that even though the default way to access a team booking in an organization is to not use /team in the URL, but it isn't testable with playwright as the rewrite is taken care of by Next.js config which can't handle on the fly org slug's handling
|
||||
// So, we are using /team in the URL to access the team booking
|
||||
@@ -501,7 +623,7 @@ async function bookTeamEvent({
|
||||
await page.goto(`/team/${team.slug}/${event.slug}`);
|
||||
|
||||
await selectFirstAvailableTimeSlotNextMonth(page);
|
||||
await bookTimeSlot(page);
|
||||
await bookTimeSlot(page, opts);
|
||||
await expect(page.getByTestId("success-page")).toBeVisible();
|
||||
|
||||
// The title of the booking
|
||||
@@ -526,3 +648,34 @@ async function expectPageToBeNotFound({ page, url }: { page: Page; url: string }
|
||||
await page.goto(`${url}`);
|
||||
await expect(page.getByTestId(`404-page`)).toBeVisible();
|
||||
}
|
||||
|
||||
const markPhoneNumberAsRequiredAndEmailAsOptional = async (page: Page, eventId: number) => {
|
||||
// Make phone as required
|
||||
await markPhoneNumberAsRequiredField(page, eventId);
|
||||
|
||||
// Make email as not required
|
||||
await page.locator('[data-testid="field-email"] [data-testid="edit-field-action"]').click();
|
||||
const emailRequiredFiled = await page.locator('[data-testid="field-required"]');
|
||||
await emailRequiredFiled.locator("> :nth-child(2)").click();
|
||||
await page.getByTestId("field-add-save").click();
|
||||
|
||||
const submitPromise = page.waitForResponse("/api/trpc/eventTypes/update?batch=1");
|
||||
await page.locator("[data-testid=update-eventtype]").click();
|
||||
const response = await submitPromise;
|
||||
expect(response.status()).toBe(200);
|
||||
};
|
||||
|
||||
const markPhoneNumberAsRequiredField = async (page: Page, eventId: number) => {
|
||||
await page.goto(`/event-types/${eventId}?tabName=advanced`);
|
||||
|
||||
await page.locator('[data-testid="field-attendeePhoneNumber"] [data-testid="toggle-field"]').click();
|
||||
await page.locator('[data-testid="field-attendeePhoneNumber"] [data-testid="edit-field-action"]').click();
|
||||
const phoneRequiredFiled = await page.locator('[data-testid="field-required"]');
|
||||
await phoneRequiredFiled.locator("> :nth-child(1)").click();
|
||||
await page.getByTestId("field-add-save").click();
|
||||
|
||||
const submitPromise = page.waitForResponse("/api/trpc/eventTypes/update?batch=1");
|
||||
await page.locator("[data-testid=update-eventtype]").click();
|
||||
const response = await submitPromise;
|
||||
expect(response.status()).toBe(200);
|
||||
};
|
||||
@@ -44,6 +44,7 @@
|
||||
"event_request_cancelled": "Your scheduled event was canceled",
|
||||
"organizer": "Organizer",
|
||||
"need_to_reschedule_or_cancel": "Need to reschedule or cancel?",
|
||||
"you_can_view_booking_details_with_this_url":"You can view the booking details from this url {{url}} and add the event to your calendar",
|
||||
"no_options_available": "No options available",
|
||||
"cancellation_reason": "Reason for cancellation (optional)",
|
||||
"cancellation_reason_placeholder": "Why are you cancelling?",
|
||||
@@ -181,7 +182,7 @@
|
||||
"org_upgrade_banner_description": "Thank you for trialing our Organization plan. We noticed your Organization \"{{teamName}}\" needs to be upgraded.",
|
||||
"org_upgraded_successfully": "Your Organization was upgraded successfully!",
|
||||
"use_link_to_reset_password": "Use the link below to reset your password",
|
||||
"hey_there": "Hey there,",
|
||||
"hey_there": "Hey there",
|
||||
"forgot_your_password_calcom": "Forgot your password? - {{appName}}",
|
||||
"delete_webhook_confirmation_message": "Are you sure you want to delete this webhook? You will no longer receive {{appName}} meeting data at a specified URL, in real-time, when an event is scheduled or canceled.",
|
||||
"confirm_delete_webhook": "Yes, delete webhook",
|
||||
@@ -1904,6 +1905,7 @@
|
||||
"not_enough_seats": "Not enough seats",
|
||||
"form_builder_field_already_exists": "A field with this name already exists",
|
||||
"show_on_booking_page": "Show on booking page",
|
||||
"visit_cancelled_booking": "You can visit the canceled booking page",
|
||||
"get_started_zapier_templates": "Get started with Zapier templates",
|
||||
"team_is_unpublished": "{{team}} is unpublished",
|
||||
"org_is_unpublished_description": "This organization link is currently not available. Please contact the organization owner or ask them to publish it.",
|
||||
@@ -2459,6 +2461,7 @@
|
||||
"add_emails": "Add Emails",
|
||||
"add_email_description": "Add an email address to replace your primary or to use as an alternative email on your event types.",
|
||||
"confirm_email": "Confirm your email",
|
||||
"confirming_your_booking_sms":"$t(hey_there) {{name}}, confirming your booking on {{date}}.",
|
||||
"scheduler_first_name": "The first name of the person booking",
|
||||
"scheduler_last_name": "The last name of the person booking",
|
||||
"scheduler_name": "Scheduler Name",
|
||||
@@ -2549,6 +2552,7 @@
|
||||
"team_select_info": "triggers for all team event types and all team members' personal event types",
|
||||
"no_show_updated": "No-show status updated for attendees",
|
||||
"email_copied": "Email copied",
|
||||
"phone_number_copied": "Phone Number Copied",
|
||||
"USER_PENDING_MEMBER_OF_THE_ORG": "User is a pending member of the organization",
|
||||
"USER_ALREADY_INVITED_OR_MEMBER": "User is already invited or a member",
|
||||
"USER_MEMBER_OF_OTHER_ORGANIZATION": "User is member of an organization that this team is not a part of.",
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Payment, Prisma, PaymentOption, Booking } from "@prisma/client";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import "vitest-fetch-mock";
|
||||
|
||||
import { sendAwaitingPaymentEmail } from "@calcom/emails";
|
||||
import { sendAwaitingPaymentEmailAndSMS } from "@calcom/emails";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
||||
@@ -64,7 +64,7 @@ export function getMockPaymentService() {
|
||||
paymentData: Payment
|
||||
): Promise<void> {
|
||||
// TODO: App implementing PaymentService is supposed to send email by itself at the moment.
|
||||
await sendAwaitingPaymentEmail({
|
||||
await sendAwaitingPaymentEmailAndSMS({
|
||||
...event,
|
||||
paymentInfo: {
|
||||
link: createPaymentLink(/*{
|
||||
|
||||
@@ -27,6 +27,7 @@ import type { SchedulingType, SMSLockState, TimeUnit } from "@calcom/prisma/enum
|
||||
import type { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { userMetadataType } from "@calcom/prisma/zod-utils";
|
||||
import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
|
||||
import type { AppMeta } from "@calcom/types/App";
|
||||
import type { NewCalendarEventType } from "@calcom/types/Calendar";
|
||||
import type { EventBusyDate, IntervalLimit } from "@calcom/types/Calendar";
|
||||
@@ -34,6 +35,8 @@ import type { EventBusyDate, IntervalLimit } from "@calcom/types/Calendar";
|
||||
import { getMockPaymentService } from "./MockPaymentService";
|
||||
import type { getMockRequestDataForBooking } from "./getMockRequestDataForBooking";
|
||||
|
||||
type Fields = z.infer<typeof eventTypeBookingFields>;
|
||||
|
||||
logger.settings.minLevel = 1;
|
||||
const log = logger.getSubLogger({ prefix: ["[bookingScenario]"] });
|
||||
|
||||
@@ -179,6 +182,7 @@ type WhiteListedBookingProps = {
|
||||
status: BookingStatus;
|
||||
attendees?: {
|
||||
email: string;
|
||||
phoneNumber?: string;
|
||||
bookingSeat?: AttendeeBookingSeatInput | null;
|
||||
}[];
|
||||
references?: (Omit<ReturnType<typeof getMockBookingReference>, "credentialId"> & {
|
||||
@@ -1708,10 +1712,19 @@ export function mockCrmApp(
|
||||
};
|
||||
}
|
||||
|
||||
export function getBooker({ name, email }: { name: string; email: string }) {
|
||||
export function getBooker({
|
||||
name,
|
||||
email,
|
||||
attendeePhoneNumber,
|
||||
}: {
|
||||
name: string;
|
||||
email: string;
|
||||
attendeePhoneNumber?: string;
|
||||
}) {
|
||||
return {
|
||||
name,
|
||||
email,
|
||||
attendeePhoneNumber,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1770,8 +1783,11 @@ export function getMockBookingReference(
|
||||
}
|
||||
|
||||
export function getMockBookingAttendee(
|
||||
attendee: Omit<Attendee, "bookingId"> & {
|
||||
attendee: Omit<Attendee, "bookingId" | "phoneNumber" | "email" | "noShow"> & {
|
||||
bookingSeat?: AttendeeBookingSeatInput;
|
||||
phoneNumber?: string | null;
|
||||
email: string;
|
||||
noShow?: boolean;
|
||||
}
|
||||
) {
|
||||
return {
|
||||
@@ -1781,6 +1797,8 @@ export function getMockBookingAttendee(
|
||||
email: attendee.email,
|
||||
locale: attendee.locale,
|
||||
bookingSeat: attendee.bookingSeat || null,
|
||||
phoneNumber: attendee.phoneNumber ?? undefined,
|
||||
noShow: attendee.noShow ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1823,3 +1841,89 @@ export const replaceDates = (dates: string[], replacement: Record<string, string
|
||||
return date.replace(/(.*)T/, (_, group1) => `${replacement[group1]}T`);
|
||||
});
|
||||
};
|
||||
|
||||
export const getDefaultBookingFields = ({
|
||||
emailField,
|
||||
bookingFields = [],
|
||||
}: {
|
||||
emailField?: Fields[number];
|
||||
bookingFields: Fields;
|
||||
}) => {
|
||||
return [
|
||||
{
|
||||
name: "name",
|
||||
type: "name",
|
||||
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||
editable: "system",
|
||||
required: true,
|
||||
defaultLabel: "your_name",
|
||||
},
|
||||
!!emailField
|
||||
? emailField
|
||||
: {
|
||||
name: "email",
|
||||
type: "email",
|
||||
label: "",
|
||||
hidden: false,
|
||||
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||
editable: "system",
|
||||
required: true,
|
||||
placeholder: "",
|
||||
defaultLabel: "email_address",
|
||||
},
|
||||
{
|
||||
name: "location",
|
||||
type: "radioInput",
|
||||
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||
editable: "system",
|
||||
required: false,
|
||||
defaultLabel: "location",
|
||||
getOptionsAt: "locations",
|
||||
optionsInputs: {
|
||||
phone: { type: "phone", required: true, placeholder: "" },
|
||||
attendeeInPerson: { type: "address", required: true, placeholder: "" },
|
||||
},
|
||||
hideWhenJustOneOption: true,
|
||||
},
|
||||
{
|
||||
name: "title",
|
||||
type: "text",
|
||||
hidden: true,
|
||||
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||
editable: "system-but-optional",
|
||||
required: true,
|
||||
defaultLabel: "what_is_this_meeting_about",
|
||||
defaultPlaceholder: "",
|
||||
},
|
||||
{
|
||||
name: "notes",
|
||||
type: "textarea",
|
||||
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||
editable: "system-but-optional",
|
||||
required: false,
|
||||
defaultLabel: "additional_notes",
|
||||
defaultPlaceholder: "share_additional_notes",
|
||||
},
|
||||
{
|
||||
name: "guests",
|
||||
type: "multiemail",
|
||||
hidden: false,
|
||||
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||
editable: "system-but-optional",
|
||||
required: false,
|
||||
defaultLabel: "additional_guests",
|
||||
defaultPlaceholder: "email",
|
||||
},
|
||||
{
|
||||
name: "rescheduleReason",
|
||||
type: "textarea",
|
||||
views: [{ id: "reschedule", label: "Reschedule View" }],
|
||||
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||
editable: "system-but-optional",
|
||||
required: false,
|
||||
defaultLabel: "reason_for_reschedule",
|
||||
defaultPlaceholder: "reschedule_placeholder",
|
||||
},
|
||||
...bookingFields,
|
||||
] as Fields;
|
||||
};
|
||||
@@ -427,6 +427,16 @@ export async function expectBookingToBeInDatabase(
|
||||
);
|
||||
}
|
||||
|
||||
export function expectSMSToBeTriggered({ sms, toNumber }: { sms: Fixtures["sms"]; toNumber: string }) {
|
||||
expect(sms.get()).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
to: toNumber,
|
||||
}),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
export function expectSuccessfulBookingCreationEmails({
|
||||
emails,
|
||||
organizer,
|
||||
@@ -818,7 +828,7 @@ export function expectBookingRequestedEmails({
|
||||
}: {
|
||||
emails: Fixtures["emails"];
|
||||
organizer: { email: string; name: string };
|
||||
booker: { email: string; name: string };
|
||||
booker?: { email: string; name: string };
|
||||
}) {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
@@ -829,14 +839,16 @@ export function expectBookingRequestedEmails({
|
||||
`${organizer.email}`
|
||||
);
|
||||
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
titleTag: "booking_submitted_subject",
|
||||
to: `${booker.email}`,
|
||||
noIcs: true,
|
||||
},
|
||||
`${booker.email}`
|
||||
);
|
||||
if (booker) {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
titleTag: "booking_submitted_subject",
|
||||
to: `${booker.email}`,
|
||||
noIcs: true,
|
||||
},
|
||||
`${booker.email}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function expectBookingRequestRescheduledEmails({
|
||||
@@ -898,13 +910,17 @@ export function expectBookingRequestedWebhookToHaveBeenFired({
|
||||
subscriberUrl,
|
||||
paidEvent,
|
||||
eventType,
|
||||
isEmailHidden = false,
|
||||
isAttendeePhoneNumberHidden = false,
|
||||
}: {
|
||||
organizer: { email: string; name: string };
|
||||
booker: { email: string; name: string };
|
||||
booker: { email: string; name: string; attendeePhoneNumber?: string };
|
||||
subscriberUrl: string;
|
||||
location: string;
|
||||
paidEvent?: boolean;
|
||||
eventType: InputEventType;
|
||||
isEmailHidden?: boolean;
|
||||
isAttendeePhoneNumberHidden?: boolean;
|
||||
}) {
|
||||
// There is an inconsistency in the way we send the data to the webhook for paid events and unpaid events. Fix that and then remove this if statement.
|
||||
if (!paidEvent) {
|
||||
@@ -925,8 +941,17 @@ export function expectBookingRequestedWebhookToHaveBeenFired({
|
||||
email: {
|
||||
label: "email_address",
|
||||
value: booker.email,
|
||||
isHidden: false,
|
||||
isHidden: isEmailHidden,
|
||||
},
|
||||
...(booker.attendeePhoneNumber
|
||||
? {
|
||||
attendeePhoneNumber: {
|
||||
label: "phone_number",
|
||||
value: booker.attendeePhoneNumber,
|
||||
isHidden: isAttendeePhoneNumberHidden,
|
||||
},
|
||||
}
|
||||
: null),
|
||||
location: {
|
||||
label: "location",
|
||||
value: { optionValue: "", value: location },
|
||||
@@ -947,6 +972,14 @@ export function expectBookingRequestedWebhookToHaveBeenFired({
|
||||
responses: {
|
||||
name: { label: "name", value: booker.name },
|
||||
email: { label: "email", value: booker.email },
|
||||
...(booker.attendeePhoneNumber
|
||||
? {
|
||||
attendeePhoneNumber: {
|
||||
label: "phone_number",
|
||||
value: booker.attendeePhoneNumber,
|
||||
},
|
||||
}
|
||||
: null),
|
||||
location: {
|
||||
label: "location",
|
||||
value: { optionValue: "", value: location },
|
||||
@@ -963,13 +996,17 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
|
||||
subscriberUrl,
|
||||
paidEvent,
|
||||
videoCallUrl,
|
||||
isEmailHidden = false,
|
||||
isAttendeePhoneNumberHidden = false,
|
||||
}: {
|
||||
organizer: { email: string; name: string };
|
||||
booker: { email: string; name: string };
|
||||
booker: { email: string; name: string; attendeePhoneNumber?: string };
|
||||
subscriberUrl: string;
|
||||
location: string;
|
||||
paidEvent?: boolean;
|
||||
videoCallUrl?: string | null;
|
||||
isEmailHidden?: boolean;
|
||||
isAttendeePhoneNumberHidden?: boolean;
|
||||
}) {
|
||||
if (!paidEvent) {
|
||||
expectWebhookToHaveBeenCalledWith(subscriberUrl, {
|
||||
@@ -980,7 +1017,16 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
|
||||
},
|
||||
responses: {
|
||||
name: { label: "your_name", value: booker.name, isHidden: false },
|
||||
email: { label: "email_address", value: booker.email, isHidden: false },
|
||||
email: { label: "email_address", value: booker.email, isHidden: isEmailHidden },
|
||||
...(booker.attendeePhoneNumber
|
||||
? {
|
||||
attendeePhoneNumber: {
|
||||
label: "phone_number",
|
||||
value: booker.attendeePhoneNumber,
|
||||
isHidden: isAttendeePhoneNumberHidden,
|
||||
},
|
||||
}
|
||||
: null),
|
||||
location: {
|
||||
label: "location",
|
||||
value: { optionValue: "", value: location },
|
||||
@@ -1004,6 +1050,14 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
|
||||
label: "email",
|
||||
value: booker.email,
|
||||
},
|
||||
...(booker.attendeePhoneNumber
|
||||
? {
|
||||
attendeePhoneNumber: {
|
||||
label: "phone_number",
|
||||
value: booker.attendeePhoneNumber,
|
||||
},
|
||||
}
|
||||
: null),
|
||||
location: {
|
||||
label: "location",
|
||||
value: { optionValue: "", value: location },
|
||||
|
||||
@@ -33,6 +33,7 @@ export function getMockRequestDataForBooking({
|
||||
email: string;
|
||||
name: string;
|
||||
location?: { optionValue: ""; value: string };
|
||||
attendeePhoneNumber?: string;
|
||||
smsReminderNumber?: string;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user