* Add Routing logic to Query builder * Make a working redirect * Make it an app * Move pages and components to App * Integrate all pages in the app * Integrate prisma everywhere * Fix Routing Link * Add routing preview * Fixes * Get deplouyed on preview with ts disabled * Fix case * add reordering for routes * Move away from react DnD * Add sidebar * Add sidebar support and select support * Various fixes and improvements * Ignore eslint temporarly * Route might be falsy * Make CalNumber support required validation * Loader improvements * Add SSR support * Fix few typescript issues * More typesafety, download csv, bug fiees * Add seo friendly link * Avoid seding credebtials to frontend * Self review fixes * Improvements in app-store * Cahnge Form layout * Add scaffolding for app tests * Add playwright tests and add user check in serving data * Add CI tests * Add route builder test * Styling * Apply suggestions from code review Co-authored-by: Agusti Fernandez Pardo <6601142+agustif@users.noreply.github.com> * Changes as per loom feedback * Increase time for tests * Fix PR suggestions * Import CSS only in the module * Fix codacy issues * Move the codebbase to ee and add PRO and license check * Add Badge * Avoid lodash import * Fix TS error * Fix lint errors * Fix bug to merge conflicts resolution - me query shouldnt cause the Shell to go in loading state Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Agusti Fernandez Pardo <6601142+agustif@users.noreply.github.com>
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { useRouter } from "next/router";
|
|
import { useState, useEffect, useRef } from "react";
|
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
import { deriveAppDictKeyFromType } from "@calcom/lib/deriveAppDictKeyFromType";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import type { App } from "@calcom/types/App";
|
|
|
|
import { trpc } from "@lib/trpc";
|
|
|
|
import { UpgradeToProDialog } from "@components/UpgradeToProDialog";
|
|
|
|
import { InstallAppButtonMap } from "./apps.browser.generated";
|
|
import { InstallAppButtonProps } from "./types";
|
|
|
|
function InstallAppButtonWithoutPlanCheck(
|
|
props: {
|
|
type: App["type"];
|
|
} & InstallAppButtonProps
|
|
) {
|
|
const key = deriveAppDictKeyFromType(props.type, InstallAppButtonMap);
|
|
const InstallAppButtonComponent = InstallAppButtonMap[key as keyof typeof InstallAppButtonMap];
|
|
if (!InstallAppButtonComponent) return <>{props.render({ useDefaultComponent: true })}</>;
|
|
|
|
return <InstallAppButtonComponent render={props.render} onChanged={props.onChanged} />;
|
|
}
|
|
export const InstallAppButton = (
|
|
props: {
|
|
isProOnly?: App["isProOnly"];
|
|
type: App["type"];
|
|
} & InstallAppButtonProps
|
|
) => {
|
|
const { isLoading, data: user } = trpc.useQuery(["viewer.me"]);
|
|
const { t } = useLocale();
|
|
const [modalOpen, setModalOpen] = useState(false);
|
|
const router = useRouter();
|
|
const proProtectionElementRef = useRef<HTMLDivElement | null>(null);
|
|
useEffect(() => {
|
|
const el = proProtectionElementRef.current;
|
|
if (!el) {
|
|
return;
|
|
}
|
|
el.addEventListener(
|
|
"click",
|
|
(e) => {
|
|
if (!user) {
|
|
router.push(
|
|
`${WEBAPP_URL}/auth/login?callbackUrl=${WEBAPP_URL + location.pathname + location.search}`
|
|
);
|
|
e.stopPropagation();
|
|
return;
|
|
}
|
|
if (user.plan === "FREE" && props.isProOnly) {
|
|
setModalOpen(true);
|
|
e.stopPropagation();
|
|
return;
|
|
}
|
|
},
|
|
true
|
|
);
|
|
}, [isLoading, user, router, props.isProOnly]);
|
|
|
|
if (isLoading) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div ref={proProtectionElementRef}>
|
|
<InstallAppButtonWithoutPlanCheck {...props} />
|
|
<UpgradeToProDialog modalOpen={modalOpen} setModalOpen={setModalOpen}>
|
|
{t("app_upgrade_description")}
|
|
</UpgradeToProDialog>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export { AppConfiguration } from "./_components/AppConfiguration";
|