Skip to content

Commit 5e29a7f

Browse files
feat: add option to ignore guests in HubSpot integration and update related schemas (calcom#25727)
Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com>
1 parent 97377c4 commit 5e29a7f

4 files changed

Lines changed: 46 additions & 8 deletions

File tree

apps/web/public/static/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4109,5 +4109,6 @@
41094109
"actor": "Actor",
41104110
"timestamp": "Timestamp",
41114111
"json": "JSON",
4112+
"hubspot_ignore_guests": "Do not create new records for guests added to the booking",
41124113
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
41134114
}
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import { usePathname } from "next/navigation";
22

3+
import { useAppContextWithSchema } from "@calcom/app-store/EventTypeAppContext";
34
import AppCard from "@calcom/app-store/_components/AppCard";
45
import useIsAppEnabled from "@calcom/app-store/_utils/useIsAppEnabled";
56
import type { EventTypeAppCardComponent } from "@calcom/app-store/types";
67
import { WEBAPP_URL } from "@calcom/lib/constants";
8+
import { useLocale } from "@calcom/lib/hooks/useLocale";
9+
import { Section } from "@calcom/ui/components/section";
10+
import { Switch } from "@calcom/ui/components/form";
711

8-
const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ app, eventType, onAppInstallSuccess }) {
9-
const pathname = usePathname();
12+
import type { appDataSchema } from "../zod";
1013

14+
const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
15+
app,
16+
eventType,
17+
onAppInstallSuccess,
18+
}) {
19+
const pathname = usePathname();
20+
const { t } = useLocale();
21+
const { getAppData, setAppData } = useAppContextWithSchema<typeof appDataSchema>();
1122
const { enabled, updateEnabled } = useIsAppEnabled(app);
1223

24+
const ignoreGuests = getAppData("ignoreGuests") ?? false;
25+
1326
return (
1427
<AppCard
1528
onAppInstallSuccess={onAppInstallSuccess}
@@ -20,9 +33,26 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
2033
updateEnabled(e);
2134
}}
2235
switchChecked={enabled}
23-
hideAppCardOptions
24-
/>
36+
hideSettingsIcon>
37+
<Section.Content>
38+
<Section.SubSection>
39+
<Section.SubSectionHeader
40+
icon="user-plus"
41+
title={t("hubspot_ignore_guests")}
42+
labelFor="ignore-guests">
43+
<Switch
44+
size="sm"
45+
labelOnLeading
46+
checked={ignoreGuests}
47+
onCheckedChange={(checked) => {
48+
setAppData("ignoreGuests", checked);
49+
}}
50+
/>
51+
</Section.SubSectionHeader>
52+
</Section.SubSection>
53+
</Section.Content>
54+
</AppCard>
2555
);
2656
};
2757

28-
export default EventTypeAppCard;
58+
export default EventTypeAppCard;

packages/app-store/hubspot/lib/CrmService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
SimplePublicObject,
77
SimplePublicObjectInput,
88
} from "@hubspot/api-client/lib/codegen/crm/objects/meetings";
9+
import type { z } from "zod";
910

1011
import { getLocation } from "@calcom/lib/CalEventParser";
1112
import getLabelValueMapFromResponses from "@calcom/lib/bookings/getLabelValueMapFromResponses";
@@ -20,6 +21,7 @@ import type { CRM, ContactCreateInput, Contact, CrmEvent } from "@calcom/types/C
2021
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
2122
import refreshOAuthTokens from "../../_utils/oauth/refreshOAuthTokens";
2223
import type { HubspotToken } from "../api/callback";
24+
import type { appDataSchema } from "../zod";
2325

2426
export default class HubspotCalendarService implements CRM {
2527
private url = "";
@@ -29,15 +31,18 @@ export default class HubspotCalendarService implements CRM {
2931
private client_id = "";
3032
private client_secret = "";
3133
private hubspotClient: hubspot.Client;
34+
private appOptions: z.infer<typeof appDataSchema>;
3235

33-
constructor(credential: CredentialPayload) {
36+
constructor(credential: CredentialPayload, appOptions?: z.infer<typeof appDataSchema>) {
3437
this.hubspotClient = new hubspot.Client();
3538

3639
this.integrationName = "hubspot_other_calendar";
3740

3841
this.auth = this.hubspotAuth(credential).then((r) => r);
3942

4043
this.log = logger.getSubLogger({ prefix: [`[[lib] ${this.integrationName}`] });
44+
45+
this.appOptions = appOptions || {};
4146
}
4247

4348
private getHubspotMeetingBody = (event: CalendarEvent): string => {
@@ -300,7 +305,7 @@ export default class HubspotCalendarService implements CRM {
300305
}
301306

302307
getAppOptions() {
303-
console.log("No options implemented");
308+
return this.appOptions;
304309
}
305310

306311
async handleAttendeeNoShow() {

packages/app-store/hubspot/zod.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { z } from "zod";
22

33
import { eventTypeAppCardZod } from "../eventTypeAppCardZod";
44

5-
export const appDataSchema = eventTypeAppCardZod;
5+
export const appDataSchema = eventTypeAppCardZod.extend({
6+
ignoreGuests: z.boolean().optional(),
7+
});
68

79
export const appKeysSchema = z.object({
810
client_id: z.string().min(1),

0 commit comments

Comments
 (0)