Only show smsReminderNumber when workflow has ATTENDEE_NUMBER as action (#7567)

* fix smsReminderNumber booking field

* fix sms reminder booking field when updating steps

* code clean up

* use removeSmsReminderFieldForBooking

* Add smsReminderNumber at correct position

* Fix comments

* code clean up

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-03-10 01:09:42 +05:30
1 parent 95c1c81b3b
commit dbf74890a5
3 files changed
+71 -48

No files matched your search

@@ -218,14 +218,6 @@ export const ensureBookingInputsHaveSystemFields = ({
},
];
// Backward Compatibility for SMS Reminder Number
if (smsNumberSources.length) {
systemBeforeFields.push({
...getSmsReminderNumberField(),
sources: smsNumberSources,
});
}
// These fields should be added after other user fields
const systemAfterFields: typeof bookingFields = [
{
@@ -282,6 +274,18 @@ export const ensureBookingInputsHaveSystemFields = ({
bookingFields = missingSystemBeforeFields.concat(bookingFields);
// Backward Compatibility for SMS Reminder Number
// Note: We still need workflows in `getBookingFields` due to Backward Compatibility. If we do a one time entry for all event-types, we can remove workflows from `getBookingFields`
// Also, note that even if Workflows don't explicity add smsReminderNumber field to bookingFields, it would be added as a side effect of this backward compatibility logic
if (smsNumberSources.length && !bookingFields.find((f) => f.name !== SMS_REMINDER_NUMBER_FIELD)) {
const indexForLocation = bookingFields.findIndex((f) => f.name === "location");
// Add the SMS Reminder Number field after `location` field always
bookingFields.splice(indexForLocation + 1, 0, {
...getSmsReminderNumberField(),
sources: smsNumberSources,
});
}
// Backward Compatibility: If we are migrating from old system, we need to map `customInputs` to `bookingFields`
if (handleMigration) {
customInputs.forEach((input) => {
@@ -1,9 +1,9 @@
import { z } from "zod";
import type { z } from "zod";
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
import { prisma } from "@calcom/prisma";
import { EventType } from "@calcom/prisma/client";
import { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
import type { EventType } from "@calcom/prisma/client";
import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
type Field = z.infer<typeof eventTypeBookingFields>[number];
@@ -51,6 +51,7 @@ export async function upsertBookingField(
) {
const eventType = await getEventType(eventTypeId);
let fieldFound = false;
const newFields = eventType.bookingFields.map((f) => {
if (f.name === fieldToAdd.name) {
fieldFound = true;