2022-03-23 22:00:30 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
|
|
|
import dynamic from "next/dynamic";
|
|
|
|
|
2022-04-06 12:37:06 +00:00
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
2022-03-23 22:00:30 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import type { App } from "@calcom/types/App";
|
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
|
|
|
|
import { InstallAppButtonProps } from "./types";
|
|
|
|
|
|
|
|
export const InstallAppButtonMap = {
|
|
|
|
// examplevideo: dynamic(() => import("./_example/components/InstallAppButton")),
|
|
|
|
applecalendar: dynamic(() => import("./applecalendar/components/InstallAppButton")),
|
|
|
|
caldavcalendar: dynamic(() => import("./caldavcalendar/components/InstallAppButton")),
|
|
|
|
googlecalendar: dynamic(() => import("./googlecalendar/components/InstallAppButton")),
|
2022-04-16 02:23:38 +00:00
|
|
|
hubspotothercalendar: dynamic(() => import("./hubspotothercalendar/components/InstallAppButton")),
|
2022-03-23 22:00:30 +00:00
|
|
|
office365calendar: dynamic(() => import("./office365calendar/components/InstallAppButton")),
|
2022-04-06 12:37:06 +00:00
|
|
|
slackmessaging: dynamic(() => import("./slackmessaging/components/InstallAppButton")),
|
2022-03-23 22:00:30 +00:00
|
|
|
stripepayment: dynamic(() => import("./stripepayment/components/InstallAppButton")),
|
|
|
|
tandemvideo: dynamic(() => import("./tandemvideo/components/InstallAppButton")),
|
|
|
|
zoomvideo: dynamic(() => import("./zoomvideo/components/InstallAppButton")),
|
2022-04-04 09:11:24 +00:00
|
|
|
office365video: dynamic(() => import("./office365video/components/InstallAppButton")),
|
2022-04-15 02:24:27 +00:00
|
|
|
wipemycalother: dynamic(() => import("./wipemycalother/components/InstallAppButton")),
|
2022-04-21 18:17:56 +00:00
|
|
|
jitsivideo: dynamic(() => import("./jitsivideo/components/InstallAppButton")),
|
|
|
|
huddle01video: dynamic(() => import("./huddle01video/components/InstallAppButton")),
|
2022-05-02 21:44:37 +00:00
|
|
|
metamask: dynamic(() => import("./metamask/components/InstallAppButton")),
|
2022-05-02 20:39:35 +00:00
|
|
|
giphy: dynamic(() => import("./giphy/components/InstallAppButton")),
|
2022-03-23 22:00:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const InstallAppButton = (
|
|
|
|
props: {
|
|
|
|
type: App["type"];
|
|
|
|
} & InstallAppButtonProps
|
|
|
|
) => {
|
|
|
|
const { status } = useSession();
|
|
|
|
const { t } = useLocale();
|
2022-05-02 20:39:35 +00:00
|
|
|
let appName = props.type.replace(/_/g, "");
|
|
|
|
let InstallAppButtonComponent = InstallAppButtonMap[appName as keyof typeof InstallAppButtonMap];
|
|
|
|
/** So we can either call it by simple name (ex. `slack`, `giphy`) instead of
|
|
|
|
* `slackmessaging`, `giphyother` while maintaining retro-compatibility. */
|
|
|
|
if (!InstallAppButtonComponent) {
|
|
|
|
[appName] = props.type.split("_");
|
|
|
|
InstallAppButtonComponent = InstallAppButtonMap[appName as keyof typeof InstallAppButtonMap];
|
|
|
|
}
|
2022-03-23 22:00:30 +00:00
|
|
|
if (!InstallAppButtonComponent) return null;
|
|
|
|
if (status === "unauthenticated")
|
|
|
|
return (
|
|
|
|
<InstallAppButtonComponent
|
|
|
|
render={() => (
|
|
|
|
<Button
|
2022-04-14 04:00:38 +00:00
|
|
|
data-testid="install-app-button"
|
2022-03-23 22:00:30 +00:00
|
|
|
color="primary"
|
2022-04-06 12:37:06 +00:00
|
|
|
href={`${WEBAPP_URL}/auth/login?callbackUrl=${WEBAPP_URL + location.pathname + location.search}`}>
|
2022-03-23 22:00:30 +00:00
|
|
|
{t("install_app")}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
onChanged={props.onChanged}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
return <InstallAppButtonComponent render={props.render} onChanged={props.onChanged} />;
|
|
|
|
};
|