feat: app install flow followup (#15193)
Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
57 files changed
+1471
-1224
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import type { UserAdminTeams } from "@calcom/features/ee/teams/lib/getUserAdminTeams";
|
||||
import getInstallCountPerApp from "@calcom/lib/apps/getInstallCountPerApp";
|
||||
import type { UserAdminTeams } from "@calcom/lib/server/repository/user";
|
||||
import prisma, { safeAppSelect, safeCredentialSelect } from "@calcom/prisma";
|
||||
import { userMetadata } from "@calcom/prisma/zod-utils";
|
||||
import type { AppFrontendPayload as App } from "@calcom/types/App";
|
||||
@@ -58,19 +58,13 @@ export async function getAppRegistry() {
|
||||
|
||||
export async function getAppRegistryWithCredentials(userId: number, userAdminTeams: UserAdminTeams = []) {
|
||||
// Get teamIds to grab existing credentials
|
||||
const teamIds = [];
|
||||
for (const team of userAdminTeams) {
|
||||
if (!team.isUser) {
|
||||
teamIds.push(team.id);
|
||||
}
|
||||
}
|
||||
|
||||
const dbApps = await prisma.app.findMany({
|
||||
where: { enabled: true },
|
||||
select: {
|
||||
...safeAppSelect,
|
||||
credentials: {
|
||||
where: { OR: [{ userId }, { teamId: { in: teamIds } }] },
|
||||
where: { OR: [{ userId }, { teamId: { in: userAdminTeams } }] },
|
||||
select: safeCredentialSelect,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -61,7 +61,6 @@ export default function OmniInstallAppButton({
|
||||
type: app.type,
|
||||
variant: app.variant,
|
||||
slug: app.slug,
|
||||
isOmniInstall: true,
|
||||
...(teamId && { teamId }),
|
||||
});
|
||||
},
|
||||
|
||||
@@ -7,9 +7,6 @@ export function decodeOAuthState(req: NextApiRequest) {
|
||||
return undefined;
|
||||
}
|
||||
const state: IntegrationOAuthCallbackState = JSON.parse(req.query.state);
|
||||
if (state.appOnboardingRedirectUrl) {
|
||||
state.appOnboardingRedirectUrl = decodeURIComponent(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import getUserAdminTeams from "@calcom/features/ee/teams/lib/getUserAdminTeams";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
|
||||
export const throwIfNotHaveAdminAccessToTeam = async ({
|
||||
teamId,
|
||||
@@ -11,8 +11,8 @@ export const throwIfNotHaveAdminAccessToTeam = async ({
|
||||
if (!teamId) {
|
||||
return;
|
||||
}
|
||||
const teamsUserHasAdminAccessFor = await getUserAdminTeams({ userId });
|
||||
const hasAdminAccessToTeam = teamsUserHasAdminAccessFor.some((team) => team.id === teamId);
|
||||
const teamsUserHasAdminAccessFor = await UserRepository.getUserAdminTeams(userId);
|
||||
const hasAdminAccessToTeam = teamsUserHasAdminAccessFor.some((id) => id === teamId);
|
||||
|
||||
if (!hasAdminAccessToTeam) {
|
||||
throw new HttpError({ statusCode: 401, message: "You must be an admin of the team to do this" });
|
||||
|
||||
@@ -6,8 +6,6 @@ import type { IntegrationOAuthCallbackState } from "@calcom/app-store/types";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { App } from "@calcom/types/App";
|
||||
|
||||
import getInstalledAppPath from "./getInstalledAppPath";
|
||||
|
||||
function gotoUrl(url: string, newTab?: boolean) {
|
||||
if (newTab) {
|
||||
window.open(url, "_blank");
|
||||
@@ -27,17 +25,7 @@ type UseAddAppMutationOptions = CustomUseMutationOptions & {
|
||||
returnTo?: string;
|
||||
};
|
||||
|
||||
type useAddAppMutationVariables = {
|
||||
type?: App["type"];
|
||||
variant?: string;
|
||||
slug?: string;
|
||||
isOmniInstall?: boolean;
|
||||
teamId?: number;
|
||||
onErrorReturnTo?: string;
|
||||
};
|
||||
|
||||
function useAddAppMutation(_type: App["type"] | null, allOptions?: UseAddAppMutationOptions) {
|
||||
const { returnTo, ...options } = allOptions || {};
|
||||
function useAddAppMutation(_type: App["type"] | null, options?: UseAddAppMutationOptions) {
|
||||
const pathname = usePathname();
|
||||
const onErrorReturnTo = `${WEBAPP_URL}${pathname}`;
|
||||
|
||||
@@ -48,8 +36,8 @@ function useAddAppMutation(_type: App["type"] | null, allOptions?: UseAddAppMuta
|
||||
type?: App["type"];
|
||||
variant?: string;
|
||||
slug?: string;
|
||||
isOmniInstall?: boolean;
|
||||
teamId?: number;
|
||||
returnTo?: string;
|
||||
defaultInstall?: boolean;
|
||||
}
|
||||
| ""
|
||||
@@ -57,13 +45,16 @@ function useAddAppMutation(_type: App["type"] | null, allOptions?: UseAddAppMuta
|
||||
...options,
|
||||
mutationFn: async (variables) => {
|
||||
let type: string | null | undefined;
|
||||
let isOmniInstall;
|
||||
const teamId = variables && variables.teamId ? variables.teamId : undefined;
|
||||
const defaultInstall = variables && variables.defaultInstall ? variables.defaultInstall : undefined;
|
||||
const returnTo = options?.returnTo
|
||||
? options.returnTo
|
||||
: variables && variables.returnTo
|
||||
? variables.returnTo
|
||||
: undefined;
|
||||
if (variables === "") {
|
||||
type = _type;
|
||||
} else {
|
||||
isOmniInstall = variables.isOmniInstall;
|
||||
type = variables.type;
|
||||
}
|
||||
if (type?.endsWith("_other_calendar")) {
|
||||
@@ -74,22 +65,20 @@ function useAddAppMutation(_type: App["type"] | null, allOptions?: UseAddAppMuta
|
||||
throw new Error("Could not install Google Meet");
|
||||
|
||||
const state: IntegrationOAuthCallbackState = {
|
||||
returnTo:
|
||||
returnTo ||
|
||||
WEBAPP_URL +
|
||||
getInstalledAppPath(
|
||||
{ variant: variables && variables.variant, slug: variables && variables.slug },
|
||||
location.search
|
||||
),
|
||||
onErrorReturnTo,
|
||||
fromApp: true,
|
||||
...(type === "google_calendar" && { installGoogleVideo: options?.installGoogleVideo }),
|
||||
...(teamId && { teamId }),
|
||||
...(returnTo && { returnTo }),
|
||||
...(defaultInstall && { defaultInstall }),
|
||||
};
|
||||
|
||||
const stateStr = JSON.stringify(state);
|
||||
const searchParams = generateSearchParamString({ stateStr, teamId, returnTo });
|
||||
const searchParams = generateSearchParamString({
|
||||
stateStr,
|
||||
teamId,
|
||||
returnTo,
|
||||
});
|
||||
|
||||
const res = await fetch(`/api/integrations/${type}/add${searchParams}`);
|
||||
|
||||
@@ -99,23 +88,25 @@ function useAddAppMutation(_type: App["type"] | null, allOptions?: UseAddAppMuta
|
||||
}
|
||||
|
||||
const json = await res.json();
|
||||
const externalUrl = /https?:\/\//.test(json.url) && !json.url.startsWith(window.location.origin);
|
||||
if (!isOmniInstall) {
|
||||
gotoUrl(json.url, json.newTab);
|
||||
return { setupPending: externalUrl || json.url.endsWith("/setup") };
|
||||
}
|
||||
|
||||
// Skip redirection only if it is an OmniInstall and redirect URL isn't of some other origin
|
||||
// This allows installation of apps like Stripe to still redirect to their authentication pages.
|
||||
const externalUrl = /https?:\/\//.test(json?.url) && !json?.url?.startsWith(window.location.origin);
|
||||
|
||||
// Check first that the URL is absolute, then check that it is of different origin from the current.
|
||||
if (externalUrl) {
|
||||
// TODO: For Omni installation to authenticate and come back to the page where installation was initiated, some changes need to be done in all apps' add callbacks
|
||||
gotoUrl(json.url, json.newTab);
|
||||
return { setupPending: externalUrl };
|
||||
return { setupPending: !json.newTab };
|
||||
} else if (json.url) {
|
||||
gotoUrl(json.url, json.newTab);
|
||||
return {
|
||||
setupPending:
|
||||
json?.url?.endsWith("/setup") || json?.url?.includes("/apps/installation/event-types"),
|
||||
};
|
||||
} else if (returnTo) {
|
||||
gotoUrl(returnTo, false);
|
||||
return { setupPending: true };
|
||||
} else {
|
||||
return { setupPending: false };
|
||||
}
|
||||
|
||||
return { setupPending: externalUrl || json.url.endsWith("/setup") };
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
const variant = appConfig.variant;
|
||||
const appType = appConfig.type;
|
||||
const teamId = req.query.teamId ? Number(req.query.teamId) : undefined;
|
||||
const returnTo = req.query?.returnTo;
|
||||
|
||||
await checkInstalled(slug, session.user.id);
|
||||
await createDefaultInstallation({
|
||||
@@ -23,7 +24,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
teamId,
|
||||
});
|
||||
|
||||
return { url: getInstalledAppPath({ variant, slug }) };
|
||||
return { url: returnTo ?? getInstalledAppPath({ variant, slug }) };
|
||||
}
|
||||
|
||||
export default defaultResponder(getHandler);
|
||||
@@ -89,9 +89,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
const state = decodeOAuthState(req);
|
||||
|
||||
if (state?.appOnboardingRedirectUrl && state.appOnboardingRedirectUrl !== "") {
|
||||
return res.redirect(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
res.redirect(getInstalledAppPath({ variant: appConfig.variant, slug: appConfig.slug }));
|
||||
}
|
||||
@@ -9,6 +9,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
return res.status(401).json({ message: "You must be logged in to do this" });
|
||||
}
|
||||
const appType = "google_video";
|
||||
const returnTo = req.query?.returnTo;
|
||||
try {
|
||||
const alreadyInstalled = await prisma.credential.findFirst({
|
||||
where: {
|
||||
@@ -36,5 +37,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
return res.status(500);
|
||||
}
|
||||
return res.status(200).json({ url: getInstalledAppPath({ variant: "conferencing", slug: "google-meet" }) });
|
||||
return res
|
||||
.status(200)
|
||||
.json({ url: returnTo ?? getInstalledAppPath({ variant: "conferencing", slug: "google-meet" }) });
|
||||
}
|
||||
@@ -14,7 +14,7 @@ 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 { teamId } = req.query;
|
||||
const { teamId, returnTo } = req.query;
|
||||
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: Number(teamId) ?? null, userId: req.session.user.id });
|
||||
const installForObject = teamId ? { teamId: Number(teamId) } : { userId: req.session.user.id };
|
||||
@@ -48,5 +48,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
return res.status(500);
|
||||
}
|
||||
// need to return a json object with the response status
|
||||
return res.status(200).json({ url: getInstalledAppPath({ variant: "conferencing", slug: "huddle01" }) });
|
||||
return res
|
||||
.status(200)
|
||||
.json({ url: returnTo ?? getInstalledAppPath({ variant: "conferencing", slug: "huddle01" }) });
|
||||
}
|
||||
@@ -88,10 +88,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
const state = decodeOAuthState(req);
|
||||
|
||||
if (state?.appOnboardingRedirectUrl && state.appOnboardingRedirectUrl !== "") {
|
||||
return res.redirect(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(`${WEBAPP_URL}/apps/installed/automation?hl=intercom`) ??
|
||||
getInstalledAppPath({ variant: "automation", slug: "intercom" })
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
||||
@@ -60,5 +61,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
setDefaultConferencingApp(userId, "jelly");
|
||||
}
|
||||
|
||||
res.redirect(getInstalledAppPath({ variant: "conferencing", slug: "jelly" }));
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: "conferencing", slug: "jelly" })
|
||||
);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ 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 { teamId } = req.query;
|
||||
const { teamId, returnTo } = req.query;
|
||||
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: Number(teamId) ?? null, userId: req.session.user.id });
|
||||
|
||||
@@ -47,5 +47,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
return res.status(500);
|
||||
}
|
||||
return res.status(200).json({ url: getInstalledAppPath({ variant: "conferencing", slug: "jitsi" }) });
|
||||
return res
|
||||
.status(200)
|
||||
.json({ url: returnTo ?? getInstalledAppPath({ variant: "conferencing", slug: "jitsi" }) });
|
||||
}
|
||||
@@ -104,10 +104,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
await createOAuthAppCredential({ appId: "msteams", type: "office365_video" }, responseBody, req);
|
||||
|
||||
if (state?.appOnboardingRedirectUrl && state.appOnboardingRedirectUrl !== "") {
|
||||
return res.redirect(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
return res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: "conferencing", slug: "msteams" })
|
||||
);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { AppOnboardingSteps } from "@calcom/lib/apps/appOnboardingSteps";
|
||||
import { getAppOnboardingUrl } from "@calcom/lib/apps/getAppOnboardingUrl";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import type { DialogProps } from "@calcom/ui";
|
||||
import { Button } from "@calcom/ui";
|
||||
import { Dialog, DialogClose, DialogContent, DialogFooter } from "@calcom/ui";
|
||||
@@ -5,7 +8,7 @@ import { Dialog, DialogClose, DialogContent, DialogFooter } from "@calcom/ui";
|
||||
import useAddAppMutation from "../../_utils/useAddAppMutation";
|
||||
|
||||
export function AccountDialog(props: DialogProps) {
|
||||
const mutation = useAddAppMutation("office365_video");
|
||||
const mutation = useAddAppMutation(null);
|
||||
return (
|
||||
<Dialog name="Account check" open={props.open} onOpenChange={props.onOpenChange}>
|
||||
<DialogContent
|
||||
@@ -24,7 +27,21 @@ export function AccountDialog(props: DialogProps) {
|
||||
Cancel
|
||||
</DialogClose>
|
||||
|
||||
<Button type="button" onClick={() => mutation.mutate("")}>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
mutation.mutate({
|
||||
type: "office365_video",
|
||||
variant: "conferencing",
|
||||
slug: "msteams",
|
||||
returnTo:
|
||||
WEBAPP_URL +
|
||||
getAppOnboardingUrl({
|
||||
slug: "msteams",
|
||||
step: AppOnboardingSteps.EVENT_TYPES_STEP,
|
||||
}),
|
||||
})
|
||||
}>
|
||||
Continue
|
||||
</Button>
|
||||
</>
|
||||
|
||||
@@ -11,6 +11,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
const session = checkSession(req);
|
||||
const slug = appConfig.slug;
|
||||
const appType = appConfig.type;
|
||||
const returnTo = req.query?.returnTo;
|
||||
|
||||
await checkInstalled(slug, session.user.id);
|
||||
await createDefaultInstallation({
|
||||
@@ -20,7 +21,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
key: {},
|
||||
});
|
||||
|
||||
return { url: getInstalledAppPath({ variant: appConfig.variant, slug: "ping" }) };
|
||||
return { url: returnTo ?? getInstalledAppPath({ variant: appConfig.variant, slug: "ping" }) };
|
||||
}
|
||||
|
||||
export default defaultResponder(getHandler);
|
||||
@@ -11,6 +11,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
const session = checkSession(req);
|
||||
const slug = appConfig.slug;
|
||||
const appType = appConfig.type;
|
||||
const returnTo = req.query?.returnTo;
|
||||
|
||||
await checkInstalled(slug, session.user.id);
|
||||
await createDefaultInstallation({
|
||||
@@ -20,7 +21,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
key: {},
|
||||
});
|
||||
|
||||
return { url: getInstalledAppPath({ variant: "conferencing", slug: "riverside" }) };
|
||||
return { url: returnTo ?? getInstalledAppPath({ variant: "conferencing", slug: "riverside" }) };
|
||||
}
|
||||
|
||||
export default defaultResponder(getHandler);
|
||||
@@ -42,10 +42,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
await createOAuthAppCredential({ appId: appConfig.slug, type: appConfig.type }, salesforceTokenInfo, req);
|
||||
|
||||
if (state?.appOnboardingRedirectUrl && state.appOnboardingRedirectUrl !== "") {
|
||||
return res.redirect(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: "other", slug: "salesforce" })
|
||||
);
|
||||
|
||||
@@ -21,6 +21,7 @@ export async function getLocationGroupedOptions(
|
||||
disabled?: boolean;
|
||||
icon?: string;
|
||||
slug?: string;
|
||||
credentialId?: number;
|
||||
}[]
|
||||
> = {};
|
||||
|
||||
@@ -93,7 +94,9 @@ export async function getLocationGroupedOptions(
|
||||
label,
|
||||
icon: app.logo,
|
||||
slug: app.slug,
|
||||
...(app.credential ? { credentialId: app.credential.id, teamName: app.credential.team?.name } : {}),
|
||||
...(app.credential
|
||||
? { credentialId: app.credential.id, teamName: app.credential.team?.name ?? null }
|
||||
: {}),
|
||||
};
|
||||
if (apps[groupByCategory]) {
|
||||
apps[groupByCategory] = [...apps[groupByCategory], option];
|
||||
|
||||
@@ -53,10 +53,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
req
|
||||
);
|
||||
|
||||
if (state?.appOnboardingRedirectUrl && state.appOnboardingRedirectUrl !== "") {
|
||||
return res.redirect(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
const returnTo = getReturnToValueFromQueryState(req);
|
||||
res.redirect(returnTo || getInstalledAppPath({ variant: "payment", slug: "stripe" }));
|
||||
}
|
||||
@@ -14,6 +14,7 @@ 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 returnTo = req.query?.returnTo;
|
||||
const appType = config.type;
|
||||
try {
|
||||
const alreadyInstalled = await prisma.credential.findFirst({
|
||||
@@ -42,5 +43,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
return res.status(500);
|
||||
}
|
||||
return res.status(200).json({ url: getInstalledAppPath({ variant: "conferencing", slug: config.slug }) });
|
||||
return res
|
||||
.status(200)
|
||||
.json({ url: returnTo ?? getInstalledAppPath({ variant: "conferencing", slug: config.slug }) });
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
import createOAuthAppCredential from "../../_utils/oauth/createOAuthAppCredential";
|
||||
import { decodeOAuthState } from "../../_utils/oauth/decodeOAuthState";
|
||||
|
||||
let client_id = "";
|
||||
let client_secret = "";
|
||||
@@ -17,6 +19,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
|
||||
const code = req.query.code as string;
|
||||
const state = decodeOAuthState(req);
|
||||
|
||||
const appKeys = await getAppKeysFromSlug("tandem");
|
||||
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
||||
@@ -62,6 +65,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
await createOAuthAppCredential({ appId: "tandem", type: "tandem_video" }, responseBody, req);
|
||||
|
||||
res.redirect(getInstalledAppPath({ variant: "conferencing", slug: "tandem" }));
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: "conferencing", slug: "tandem" })
|
||||
);
|
||||
}
|
||||
}
|
||||
Vendored
+1
-2
@@ -6,11 +6,10 @@ import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import type { ButtonProps } from "@calcom/ui";
|
||||
|
||||
export type IntegrationOAuthCallbackState = {
|
||||
returnTo: string;
|
||||
returnTo?: string;
|
||||
onErrorReturnTo: string;
|
||||
fromApp: boolean;
|
||||
installGoogleVideo?: boolean;
|
||||
appOnboardingRedirectUrl?: string;
|
||||
teamId?: number;
|
||||
defaultInstall?: boolean;
|
||||
};
|
||||
|
||||
@@ -162,9 +162,12 @@ export function doesAppSupportTeamInstall({
|
||||
);
|
||||
}
|
||||
|
||||
export function isConferencing(appCategories: string[]) {
|
||||
return appCategories.some((category) => category === "conferencing" || category === "video");
|
||||
}
|
||||
export const defaultVideoAppCategories: AppCategories[] = [
|
||||
"conferencing",
|
||||
"messaging",
|
||||
"conferencing",
|
||||
// Legacy name for conferencing
|
||||
"video",
|
||||
];
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
import createOAuthAppCredential from "../../_utils/oauth/createOAuthAppCredential";
|
||||
import { decodeOAuthState } from "../../_utils/oauth/decodeOAuthState";
|
||||
import config from "../config.json";
|
||||
import { getWebexAppKeys } from "../lib/getWebexAppKeys";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { code } = req.query;
|
||||
const { client_id, client_secret } = await getWebexAppKeys();
|
||||
const state = decodeOAuthState(req);
|
||||
|
||||
/** @link https://developer.webex.com/docs/integrations#getting-an-access-token **/
|
||||
|
||||
@@ -82,5 +85,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
await createOAuthAppCredential({ appId: config.slug, type: config.type }, responseBody, req);
|
||||
|
||||
res.redirect(getInstalledAppPath({ variant: config.variant, slug: config.slug }));
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: config.variant, slug: config.slug })
|
||||
);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
const session = checkSession(req);
|
||||
const slug = appConfig.slug;
|
||||
const appType = appConfig.type;
|
||||
const returnTo = req.query?.returnTo;
|
||||
|
||||
await checkInstalled(slug, session.user.id);
|
||||
await createDefaultInstallation({
|
||||
@@ -20,7 +21,7 @@ export async function getHandler(req: NextApiRequest) {
|
||||
key: {},
|
||||
});
|
||||
|
||||
return { url: getInstalledAppPath({ variant: "conferencing", slug: "whereby" }) };
|
||||
return { url: returnTo ?? getInstalledAppPath({ variant: "conferencing", slug: "whereby" }) };
|
||||
}
|
||||
|
||||
export default defaultResponder(getHandler);
|
||||
@@ -55,10 +55,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
await createOAuthAppCredential({ appId: appConfig.slug, type: appConfig.type }, tokenInfo.data, req);
|
||||
|
||||
if (state?.appOnboardingRedirectUrl && state.appOnboardingRedirectUrl !== "") {
|
||||
return res.redirect(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ??
|
||||
getInstalledAppPath({ variant: appConfig.variant, slug: appConfig.slug })
|
||||
|
||||
@@ -57,10 +57,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
const state = decodeOAuthState(req);
|
||||
|
||||
if (state?.appOnboardingRedirectUrl && state.appOnboardingRedirectUrl !== "") {
|
||||
return res.redirect(state.appOnboardingRedirectUrl);
|
||||
}
|
||||
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: "other", slug: "zohocrm" })
|
||||
);
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
import createOAuthAppCredential from "../../_utils/oauth/createOAuthAppCredential";
|
||||
import { decodeOAuthState } from "../../_utils/oauth/decodeOAuthState";
|
||||
import { getZoomAppKeys } from "../lib";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const state = decodeOAuthState(req);
|
||||
const { code } = req.query;
|
||||
const { client_id, client_secret } = await getZoomAppKeys();
|
||||
|
||||
@@ -74,5 +77,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
await createOAuthAppCredential({ appId: "zoom", type: "zoom_video" }, responseBody, req);
|
||||
|
||||
res.redirect(getInstalledAppPath({ variant: "conferencing", slug: "zoom" }));
|
||||
res.redirect(
|
||||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: "conferencing", slug: "zoom" })
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user