Scheduling infrastructure for absolutely everyone.
feat: add option to ignore guests in HubSpot integration and update related schemas (#25727)
Pallav5e29a7fa2ada
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.jsonindex d89bd841509..2198bf1ccc4 100644--- a/apps/web/public/static/locales/en/common.json+++ b/apps/web/public/static/locales/en/common.json@@ -4109,5 +4109,6 @@"actor": "Actor","timestamp": "Timestamp","json": "JSON",+ "hubspot_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 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"}diff --git a/packages/app-store/hubspot/components/EventTypeAppCardInterface.tsx b/packages/app-store/hubspot/components/EventTypeAppCardInterface.tsxindex 84f8ca21101..767b5a55eeb 100644--- a/packages/app-store/hubspot/components/EventTypeAppCardInterface.tsx+++ b/packages/app-store/hubspot/components/EventTypeAppCardInterface.tsx@@ -1,15 +1,28 @@import { usePathname } from "next/navigation";+import { useAppContextWithSchema } from "@calcom/app-store/EventTypeAppContext";import AppCard from "@calcom/app-store/_components/AppCard";import useIsAppEnabled from "@calcom/app-store/_utils/useIsAppEnabled";import type { EventTypeAppCardComponent } from "@calcom/app-store/types";import { WEBAPP_URL } from "@calcom/lib/constants";+import { useLocale } from "@calcom/lib/hooks/useLocale";+import { Section } from "@calcom/ui/components/section";+import { Switch } from "@calcom/ui/components/form";-const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ app, eventType, onAppInstallSuccess }) {- const pathname = usePathname();+import type { appDataSchema } from "../zod";+const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({+ app,+ eventType,+ onAppInstallSuccess,+}) {+ const pathname = usePathname();+ const { t } = useLocale();+ const { getAppData, setAppData } = useAppContextWithSchema<typeof appDataSchema>();const { enabled, updateEnabled } = useIsAppEnabled(app);+ const ignoreGuests = getAppData("ignoreGuests") ?? false;+return (<AppCardonAppInstallSuccess={onAppInstallSuccess}@@ -20,9 +33,26 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({updateEnabled(e);}}switchChecked={enabled}- hideAppCardOptions- />+ hideSettingsIcon>+ <Section.Content>+ <Section.SubSection>+ <Section.SubSectionHeader+ icon="user-plus"+ title={t("hubspot_ignore_guests")}+ labelFor="ignore-guests">+ <Switch+ size="sm"+ labelOnLeading+ checked={ignoreGuests}+ onCheckedChange={(checked) => {+ setAppData("ignoreGuests", checked);+ }}+ />+ </Section.SubSectionHeader>+ </Section.SubSection>+ </Section.Content>+ </AppCard>);};-export default EventTypeAppCard;+export default EventTypeAppCard;\ No newline at end of filediff --git a/packages/app-store/hubspot/lib/CrmService.ts b/packages/app-store/hubspot/lib/CrmService.tsindex 3468d23f7cf..438b390753b 100644--- a/packages/app-store/hubspot/lib/CrmService.ts+++ b/packages/app-store/hubspot/lib/CrmService.ts@@ -6,6 +6,7 @@ import type {SimplePublicObject,SimplePublicObjectInput,} from "@hubspot/api-client/lib/codegen/crm/objects/meetings";+import type { z } from "zod";import { getLocation } from "@calcom/lib/CalEventParser";import getLabelValueMapFromResponses from "@calcom/lib/bookings/getLabelValueMapFromResponses";@@ -20,6 +21,7 @@ import type { CRM, ContactCreateInput, Contact, CrmEvent } from "@calcom/types/Cimport getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";import refreshOAuthTokens from "../../_utils/oauth/refreshOAuthTokens";import type { HubspotToken } from "../api/callback";+import type { appDataSchema } from "../zod";export default class HubspotCalendarService implements CRM {private url = "";@@ -29,8 +31,9 @@ export default class HubspotCalendarService implements CRM {private client_id = "";private client_secret = "";private hubspotClient: hubspot.Client;+ private appOptions: z.infer<typeof appDataSchema>;- constructor(credential: CredentialPayload) {+ constructor(credential: CredentialPayload, appOptions?: z.infer<typeof appDataSchema>) {this.hubspotClient = new hubspot.Client();this.integrationName = "hubspot_other_calendar";@@ -38,6 +41,8 @@ export default class HubspotCalendarService implements CRM {this.auth = this.hubspotAuth(credential).then((r) => r);this.log = logger.getSubLogger({ prefix: [`[[lib] ${this.integrationName}`] });++ this.appOptions = appOptions || {};}private getHubspotMeetingBody = (event: CalendarEvent): string => {@@ -300,7 +305,7 @@ export default class HubspotCalendarService implements CRM {}getAppOptions() {- console.log("No options implemented");+ return this.appOptions;}async handleAttendeeNoShow() {diff --git a/packages/app-store/hubspot/zod.ts b/packages/app-store/hubspot/zod.tsindex 8cfdc5ee228..64732e0740c 100644--- a/packages/app-store/hubspot/zod.ts+++ b/packages/app-store/hubspot/zod.ts@@ -2,7 +2,9 @@ import { z } from "zod";import { eventTypeAppCardZod } from "../eventTypeAppCardZod";-export const appDataSchema = eventTypeAppCardZod;+export const appDataSchema = eventTypeAppCardZod.extend({+ ignoreGuests: z.boolean().optional(),+});export const appKeysSchema = z.object({client_id: z.string().min(1),