From 97e4cca252ace04f78453465a33c1b267f7edc14 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Thu, 21 Apr 2022 14:17:56 -0400 Subject: [PATCH] Remove global app installed button (#2561) * Remove global app installed button * Add Jitsi add button * Find app credentials based on variant * Make huddle installable * Remove default installed message from installed apps page * Display Jitsi and Huddle as locations if installed * Reverse global app changes and made Jitsi and Huddle non global * Changes to app page refrence #2556 * Fix type errors * Revert code Co-authored-by: Peer Richelsen Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/app-store/components.tsx | 2 + packages/app-store/huddle01video/_metadata.ts | 2 +- packages/app-store/huddle01video/api/add.ts | 42 +++++++++++++++++++ packages/app-store/huddle01video/api/index.ts | 1 + .../components/InstallAppButton.tsx | 18 ++++++++ .../huddle01video/components/index.ts | 1 + packages/app-store/huddle01video/index.ts | 1 + packages/app-store/jitsivideo/_metadata.ts | 2 +- packages/app-store/jitsivideo/api/add.ts | 42 +++++++++++++++++++ packages/app-store/jitsivideo/api/index.ts | 1 + .../components/InstallAppButton.tsx | 18 ++++++++ .../app-store/jitsivideo/components/index.ts | 1 + packages/app-store/jitsivideo/index.ts | 1 + 13 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 packages/app-store/huddle01video/api/add.ts create mode 100644 packages/app-store/huddle01video/api/index.ts create mode 100644 packages/app-store/huddle01video/components/InstallAppButton.tsx create mode 100644 packages/app-store/huddle01video/components/index.ts create mode 100644 packages/app-store/jitsivideo/api/add.ts create mode 100644 packages/app-store/jitsivideo/api/index.ts create mode 100644 packages/app-store/jitsivideo/components/InstallAppButton.tsx create mode 100644 packages/app-store/jitsivideo/components/index.ts diff --git a/packages/app-store/components.tsx b/packages/app-store/components.tsx index 162adfab38..3a529c3e6a 100644 --- a/packages/app-store/components.tsx +++ b/packages/app-store/components.tsx @@ -21,6 +21,8 @@ export const InstallAppButtonMap = { zoomvideo: dynamic(() => import("./zoomvideo/components/InstallAppButton")), office365video: dynamic(() => import("./office365video/components/InstallAppButton")), wipemycalother: dynamic(() => import("./wipemycalother/components/InstallAppButton")), + jitsivideo: dynamic(() => import("./jitsivideo/components/InstallAppButton")), + huddle01video: dynamic(() => import("./huddle01video/components/InstallAppButton")), }; export const InstallAppButton = ( diff --git a/packages/app-store/huddle01video/_metadata.ts b/packages/app-store/huddle01video/_metadata.ts index 90ac8d8009..ee68f1ff45 100644 --- a/packages/app-store/huddle01video/_metadata.ts +++ b/packages/app-store/huddle01video/_metadata.ts @@ -21,7 +21,7 @@ export const metadata = { slug: "huddle01_video", title: "Huddle01", trending: true, - isGlobal: true, + isGlobal: false, email: "support@huddle01.com", locationType: LocationType.Huddle01, locationLabel: "Huddle01 Video", diff --git a/packages/app-store/huddle01video/api/add.ts b/packages/app-store/huddle01video/api/add.ts new file mode 100644 index 0000000000..79531647c7 --- /dev/null +++ b/packages/app-store/huddle01video/api/add.ts @@ -0,0 +1,42 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +/** + * This is an example endpoint for an app, these will run under `/api/integrations/[...args]` + * @param req + * @param res + */ +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + if (!req.session?.user?.id) { + return res.status(401).json({ message: "You must be logged in to do this" }); + } + const appType = "huddle01_video"; + try { + const alreadyInstalled = await prisma.credential.findFirst({ + where: { + type: appType, + userId: req.session.user.id, + }, + }); + if (alreadyInstalled) { + throw new Error("Already installed"); + } + const installation = await prisma.credential.create({ + data: { + type: appType, + key: {}, + userId: req.session.user.id, + }, + }); + if (!installation) { + throw new Error("Unable to create user credential for huddle01video"); + } + } catch (error: unknown) { + if (error instanceof Error) { + return res.status(500).json({ message: error.message }); + } + return res.status(500); + } + return res.redirect("/apps/installed"); +} diff --git a/packages/app-store/huddle01video/api/index.ts b/packages/app-store/huddle01video/api/index.ts new file mode 100644 index 0000000000..4c0d2ead01 --- /dev/null +++ b/packages/app-store/huddle01video/api/index.ts @@ -0,0 +1 @@ +export { default as add } from "./add"; diff --git a/packages/app-store/huddle01video/components/InstallAppButton.tsx b/packages/app-store/huddle01video/components/InstallAppButton.tsx new file mode 100644 index 0000000000..e1b7ddf69a --- /dev/null +++ b/packages/app-store/huddle01video/components/InstallAppButton.tsx @@ -0,0 +1,18 @@ +import type { InstallAppButtonProps } from "@calcom/app-store/types"; + +import useAddAppMutation from "../../_utils/useAddAppMutation"; + +export default function InstallAppButton(props: InstallAppButtonProps) { + const mutation = useAddAppMutation("huddle01_video"); + + return ( + <> + {props.render({ + onClick() { + mutation.mutate(""); + }, + loading: mutation.isLoading, + })} + + ); +} diff --git a/packages/app-store/huddle01video/components/index.ts b/packages/app-store/huddle01video/components/index.ts new file mode 100644 index 0000000000..0d6008d4ca --- /dev/null +++ b/packages/app-store/huddle01video/components/index.ts @@ -0,0 +1 @@ +export { default as InstallAppButton } from "./InstallAppButton"; diff --git a/packages/app-store/huddle01video/index.ts b/packages/app-store/huddle01video/index.ts index 374ae5ab45..c0b23d24cc 100644 --- a/packages/app-store/huddle01video/index.ts +++ b/packages/app-store/huddle01video/index.ts @@ -1,2 +1,3 @@ export * as lib from "./lib"; +export * as api from "./api"; export { metadata } from "./_metadata"; diff --git a/packages/app-store/jitsivideo/_metadata.ts b/packages/app-store/jitsivideo/_metadata.ts index d27a056344..497fd382e1 100644 --- a/packages/app-store/jitsivideo/_metadata.ts +++ b/packages/app-store/jitsivideo/_metadata.ts @@ -20,7 +20,7 @@ export const metadata = { slug: "jitsi_video", title: "Jitsi Meet", trending: true, - isGlobal: true, + isGlobal: false, email: "help@cal.com", locationType: LocationType.Jitsi, locationLabel: "Jitsi Video", diff --git a/packages/app-store/jitsivideo/api/add.ts b/packages/app-store/jitsivideo/api/add.ts new file mode 100644 index 0000000000..9885fa75d5 --- /dev/null +++ b/packages/app-store/jitsivideo/api/add.ts @@ -0,0 +1,42 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +/** + * This is an example endpoint for an app, these will run under `/api/integrations/[...args]` + * @param req + * @param res + */ +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + if (!req.session?.user?.id) { + return res.status(401).json({ message: "You must be logged in to do this" }); + } + const appType = "jitsi_video"; + try { + const alreadyInstalled = await prisma.credential.findFirst({ + where: { + type: appType, + userId: req.session.user.id, + }, + }); + if (alreadyInstalled) { + throw new Error("Already installed"); + } + const installation = await prisma.credential.create({ + data: { + type: appType, + key: {}, + userId: req.session.user.id, + }, + }); + if (!installation) { + throw new Error("Unable to create user credential for jitsivideo"); + } + } catch (error: unknown) { + if (error instanceof Error) { + return res.status(500).json({ message: error.message }); + } + return res.status(500); + } + return res.redirect("/apps/installed"); +} diff --git a/packages/app-store/jitsivideo/api/index.ts b/packages/app-store/jitsivideo/api/index.ts new file mode 100644 index 0000000000..4c0d2ead01 --- /dev/null +++ b/packages/app-store/jitsivideo/api/index.ts @@ -0,0 +1 @@ +export { default as add } from "./add"; diff --git a/packages/app-store/jitsivideo/components/InstallAppButton.tsx b/packages/app-store/jitsivideo/components/InstallAppButton.tsx new file mode 100644 index 0000000000..048c5d9700 --- /dev/null +++ b/packages/app-store/jitsivideo/components/InstallAppButton.tsx @@ -0,0 +1,18 @@ +import type { InstallAppButtonProps } from "@calcom/app-store/types"; + +import useAddAppMutation from "../../_utils/useAddAppMutation"; + +export default function InstallAppButton(props: InstallAppButtonProps) { + const mutation = useAddAppMutation("jitsi_video"); + + return ( + <> + {props.render({ + onClick() { + mutation.mutate(""); + }, + loading: mutation.isLoading, + })} + + ); +} diff --git a/packages/app-store/jitsivideo/components/index.ts b/packages/app-store/jitsivideo/components/index.ts new file mode 100644 index 0000000000..0d6008d4ca --- /dev/null +++ b/packages/app-store/jitsivideo/components/index.ts @@ -0,0 +1 @@ +export { default as InstallAppButton } from "./InstallAppButton"; diff --git a/packages/app-store/jitsivideo/index.ts b/packages/app-store/jitsivideo/index.ts index 374ae5ab45..c0b23d24cc 100644 --- a/packages/app-store/jitsivideo/index.ts +++ b/packages/app-store/jitsivideo/index.ts @@ -1,2 +1,3 @@ export * as lib from "./lib"; +export * as api from "./api"; export { metadata } from "./_metadata";