feat: Salesforce - add option to ignore guests (#17956)
* Enable option to ignore guests * Ignore guests in CRM Manager
This commit is contained in:
@@ -2826,6 +2826,7 @@
|
||||
"single_select": "Single Select",
|
||||
"multi_select": "Multi Select",
|
||||
"group_meeting": "Group Meeting",
|
||||
"salesforce_ignore_guests": "Do not create new records for guests added to the booking",
|
||||
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
|
||||
const sendNoShowAttendeeDataField = getAppData("sendNoShowAttendeeDataField") ?? "";
|
||||
const onBookingWriteToRecord = getAppData("onBookingWriteToRecord") ?? false;
|
||||
const onBookingWriteToRecordFields = getAppData("onBookingWriteToRecordFields") ?? {};
|
||||
const ignoreGuests = getAppData("ignoreGuests") ?? false;
|
||||
|
||||
const { t } = useLocale();
|
||||
|
||||
@@ -135,6 +136,16 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<Switch
|
||||
label={t("salesforce_ignore_guests")}
|
||||
labelOnLeading
|
||||
checked={ignoreGuests}
|
||||
onCheckedChange={(checked) => {
|
||||
setAppData("ignoreGuests", checked);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{createEventOnSelectedOption.value === SalesforceRecordEnum.CONTACT ? (
|
||||
<div>
|
||||
<Switch
|
||||
|
||||
@@ -35,6 +35,7 @@ export const appDataSchema = eventTypeAppCardZod.extend({
|
||||
sendNoShowAttendeeDataField: z.string().optional(),
|
||||
onBookingWriteToRecord: z.boolean().optional(),
|
||||
onBookingWriteToRecordFields: z.record(z.string(), writeToRecordEntry).optional(),
|
||||
ignoreGuests: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const appKeysSchema = z.object({
|
||||
|
||||
@@ -29,17 +29,18 @@ export default class CrmManager {
|
||||
|
||||
public async createEvent(event: CalendarEvent, appOptions?: any) {
|
||||
const crmService = await this.getCrmService(this.credential);
|
||||
const { skipContactCreation } = crmService?.getAppOptions() || {};
|
||||
const { skipContactCreation = false, ignoreGuests = false } = crmService?.getAppOptions() || {};
|
||||
const eventAttendees = ignoreGuests ? [event.attendees[0]] : event.attendees;
|
||||
// First see if the attendees already exist in the crm
|
||||
let contacts = (await this.getContacts({ emails: event.attendees.map((a) => a.email) })) || [];
|
||||
let contacts = (await this.getContacts({ emails: eventAttendees.map((a) => a.email) })) || [];
|
||||
// Ensure that all attendees are in the crm
|
||||
if (contacts.length == event.attendees.length) {
|
||||
if (contacts.length == eventAttendees.length) {
|
||||
return await crmService?.createEvent(event, contacts);
|
||||
}
|
||||
|
||||
if (skipContactCreation) return;
|
||||
// Figure out which contacts to create
|
||||
const contactsToCreate = event.attendees.filter(
|
||||
const contactsToCreate = eventAttendees.filter(
|
||||
(attendee) => !contacts.some((contact) => contact.email === attendee.email)
|
||||
);
|
||||
const createdContacts = await this.createContacts(
|
||||
|
||||
Reference in New Issue
Block a user