Skip to content

Commit 4a88b33

Browse files
joeauyeungShaik-SirajuddinShaik-Sirajuddinsean-brydon
authored
refactor: Add crm type to app credentials (calcom#14147)
* fix timezone display on booking page to reflect event availability timezone * migrate fetching event owner's schedule to server side * migrate fetching event owner's schedule to server side * fix e2e test errors * Add WEBAPP_URL_FOR_OAUTH to salesforce auth * In event manager constructor include "_crm" credentials as calendar creds * Change crm apps to type to end with `_crm` * Move sendgrid out of CRM * Add zoho bigin to CRM apps * When getting apps, use slug * Add `crm` variants * Hubspot Oauth use `WEBAPP_URL_FOR_OAUTH` * Refactor creating credentials * Fix empty CRM page * Use credentials with `_crm` * Abstract getAppCategoryTitle * Add integration.handler changes * Fix tests * Type fix --------- Co-authored-by: Shaik-Sirajuddin <sirajuddinshaik30gmail.com> Co-authored-by: Shaik-Sirajuddin <[email protected]> Co-authored-by: Shaik-Sirajuddin <[email protected]> Co-authored-by: sean-brydon <[email protected]>
1 parent a1a2a14 commit 4a88b33

File tree

21 files changed

+96
-44
lines changed

21 files changed

+96
-44
lines changed

apps/web/pages/apps/installed/[category].tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useReducer } from "react";
44

5+
import getAppCategoryTitle from "@calcom/app-store/_utils/getAppCategoryTitle";
56
import DisconnectIntegrationModal from "@calcom/features/apps/components/DisconnectIntegrationModal";
67
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
78
import { useLocale } from "@calcom/lib/hooks/useLocale";
@@ -57,11 +58,13 @@ const IntegrationsContainer = ({
5758
customLoader={<SkeletonLoader />}
5859
success={({ data }) => {
5960
if (!data.items.length) {
61+
const emptyHeaderCategory = getAppCategoryTitle(variant || "other", true);
62+
6063
return (
6164
<EmptyScreen
6265
Icon={emptyIcon[variant || "other"]}
6366
headline={t("no_category_apps", {
64-
category: (variant && t(variant).toLowerCase()) || t("other").toLowerCase(),
67+
category: emptyHeaderCategory,
6568
})}
6669
description={t(`no_category_apps_description_${variant || "other"}`)}
6770
buttonRaw={

apps/web/playwright/payment-apps.e2e.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test.describe("Payment app", () => {
1717
await prisma.credential.create({
1818
data: {
1919
type: "alby_payment",
20+
appId: "alby",
2021
userId: user.id,
2122
key: {
2223
account_id: "random",
@@ -57,6 +58,7 @@ test.describe("Payment app", () => {
5758
await prisma.credential.create({
5859
data: {
5960
type: "stripe_payment",
61+
appId: "stripe",
6062
userId: user.id,
6163
key: {
6264
scope: "read_write",
@@ -101,6 +103,7 @@ test.describe("Payment app", () => {
101103
await prisma.credential.create({
102104
data: {
103105
type: "paypal_payment",
106+
appId: "paypal",
104107
userId: user.id,
105108
key: {
106109
client_id: "randomString",
@@ -147,6 +150,7 @@ test.describe("Payment app", () => {
147150
await prisma.credential.create({
148151
data: {
149152
type: "alby_payment",
153+
appId: "alby",
150154
userId: user.id,
151155
key: {},
152156
},
@@ -173,6 +177,7 @@ test.describe("Payment app", () => {
173177
await prisma.credential.create({
174178
data: {
175179
type: "paypal_payment",
180+
appId: "paypal",
176181
userId: user.id,
177182
key: {},
178183
},
@@ -234,6 +239,7 @@ test.describe("Payment app", () => {
234239
data: [
235240
{
236241
type: "paypal_payment",
242+
appId: "paypal",
237243
userId: user.id,
238244
key: {
239245
client_id: "randomString",
@@ -243,6 +249,7 @@ test.describe("Payment app", () => {
243249
},
244250
{
245251
type: "stripe_payment",
252+
appId: "stripe",
246253
userId: user.id,
247254
key: {
248255
scope: "read_write",
@@ -279,6 +286,7 @@ test.describe("Payment app", () => {
279286
data: [
280287
{
281288
type: "paypal_payment",
289+
appId: "paypal",
282290
userId: user.id,
283291
key: {
284292
client_id: "randomString",
@@ -288,6 +296,7 @@ test.describe("Payment app", () => {
288296
},
289297
{
290298
type: "stripe_payment",
299+
appId: "stripe",
291300
userId: user.id,
292301
key: {
293302
scope: "read_write",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { AppCategories } from "@calcom/prisma/enums";
2+
3+
/**
4+
* Handles if the app category should be full capitalized ex. CRM
5+
*
6+
* @param {App["variant"]} variant - The variant of the app.
7+
* @param {boolean} [returnLowerCase] - Optional flag to return the title in lowercase.
8+
*/
9+
const getAppCategoryTitle = (variant: AppCategories, returnLowerCase?: boolean) => {
10+
let title: string;
11+
12+
if (variant === "crm") {
13+
title = "CRM";
14+
return title;
15+
} else {
16+
title = variant;
17+
}
18+
19+
return returnLowerCase ? title.toLowerCase() : title;
20+
};
21+
22+
export default getAppCategoryTitle;

packages/app-store/_utils/getCalendar.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export const getCalendar = async (credential: CredentialPayload | null): Promise
2929
if (calendarType?.endsWith("_other_calendar")) {
3030
calendarType = calendarType.split("_other_calendar")[0];
3131
}
32+
// Backwards compatibility until CRM manager is created
33+
if (calendarType?.endsWith("_crm")) {
34+
calendarType = calendarType.split("_crm")[0];
35+
}
36+
3237
const calendarAppImportFn = appStore[calendarType.split("_").join("") as keyof typeof appStore];
3338

3439
if (!calendarAppImportFn) {

packages/app-store/closecom/api/_postAdd.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import prisma from "@calcom/prisma";
88

99
import checkSession from "../../_utils/auth";
1010
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
11+
import appConfig from "../config.json";
1112

1213
export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
1314
const session = checkSession(req);
@@ -18,10 +19,10 @@ export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
1819
const encrypted = symmetricEncrypt(JSON.stringify({ api_key }), process.env.CALENDSO_ENCRYPTION_KEY || "");
1920

2021
const data = {
21-
type: "closecom_other_calendar",
22+
type: appConfig.type,
2223
key: { encrypted },
2324
userId: session.user?.id,
24-
appId: "closecom",
25+
appId: appConfig.slug,
2526
};
2627

2728
try {

packages/app-store/closecom/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"name": "Close.com",
44
"title": "Close.com",
55
"slug": "closecom",
6-
"type": "closecom_other_calendar",
6+
"type": "closecom_crm",
77
"logo": "icon.svg",
88
"url": "https://cal.com/",
9-
"variant": "other",
9+
"variant": "crm",
1010
"categories": ["crm"],
1111
"publisher": "Cal.com, Inc.",
1212
"email": "[email protected]",

packages/app-store/hubspot/_metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export const metadata = {
66
name: "HubSpot CRM",
77
installed: !!process.env.HUBSPOT_CLIENT_ID,
88
description: _package.description,
9-
type: "hubspot_other_calendar",
10-
variant: "other_calendar",
9+
type: "hubspot_crm",
10+
variant: "crm",
1111
logo: "icon.svg",
1212
publisher: "Cal.com",
1313
url: "https://hubspot.com/",

packages/app-store/hubspot/api/add.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as hubspot from "@hubspot/api-client";
22
import type { NextApiRequest, NextApiResponse } from "next";
33

4-
import { WEBAPP_URL } from "@calcom/lib/constants";
4+
import { WEBAPP_URL_FOR_OAUTH } from "@calcom/lib/constants";
55

66
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
77
import { encodeOAuthState } from "../../_utils/oauth/encodeOAuthState";
@@ -18,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
1818
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
1919
if (!client_id) return res.status(400).json({ message: "HubSpot client id missing." });
2020

21-
const redirectUri = `${WEBAPP_URL}/api/integrations/hubspot/callback`;
21+
const redirectUri = `${WEBAPP_URL_FOR_OAUTH}/api/integrations/hubspot/callback`;
2222
const url = hubspotClient.oauth.getAuthorizationUrl(
2323
client_id,
2424
redirectUri,

packages/app-store/hubspot/api/callback.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import * as hubspot from "@hubspot/api-client";
22
import type { TokenResponseIF } from "@hubspot/api-client/lib/codegen/oauth/models/TokenResponseIF";
33
import type { NextApiRequest, NextApiResponse } from "next";
44

5-
import { WEBAPP_URL } from "@calcom/lib/constants";
5+
import { WEBAPP_URL_FOR_OAUTH } from "@calcom/lib/constants";
66
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
77

88
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
99
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
1010
import createOAuthAppCredential from "../../_utils/oauth/createOAuthAppCredential";
1111
import { decodeOAuthState } from "../../_utils/oauth/decodeOAuthState";
12+
import metadata from "../_metadata";
1213

1314
let client_id = "";
1415
let client_secret = "";
@@ -39,15 +40,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
3940
const hubspotToken: HubspotToken = await hubspotClient.oauth.tokensApi.createToken(
4041
"authorization_code",
4142
code,
42-
`${WEBAPP_URL}/api/integrations/hubspot/callback`,
43+
`${WEBAPP_URL_FOR_OAUTH}/api/integrations/hubspot/callback`,
4344
client_id,
4445
client_secret
4546
);
4647

4748
// set expiry date as offset from current time.
4849
hubspotToken.expiryDate = Math.round(Date.now() + hubspotToken.expiresIn * 1000);
4950

50-
await createOAuthAppCredential({ appId: "hubspot", type: "hubspot_other_calendar" }, hubspotToken, req);
51+
await createOAuthAppCredential({ appId: metadata.slug, type: metadata.type }, hubspotToken, req);
5152

5253
const state = decodeOAuthState(req);
5354
res.redirect(

packages/app-store/pipedrive-crm/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"/*": "Don't modify slug - If required, do it using cli edit command",
33
"name": "Pipedrive CRM",
44
"slug": "pipedrive-crm",
5-
"type": "pipedrive-crm_other_calendar",
5+
"type": "pipedrive-crm_crm",
66
"logo": "icon.svg",
77
"url": "https://revert.dev",
88
"variant": "crm",

0 commit comments

Comments
 (0)