diff --git a/apps/web/pages/apps/[slug]/setup.tsx b/apps/web/pages/apps/[slug]/setup.tsx index 3ffd9d3285..f6ec407ab5 100644 --- a/apps/web/pages/apps/[slug]/setup.tsx +++ b/apps/web/pages/apps/[slug]/setup.tsx @@ -1,9 +1,10 @@ -import type { GetStaticPaths, InferGetStaticPropsType } from "next"; +import type { InferGetStaticPropsType } from "next"; import { useSession } from "next-auth/react"; import { useRouter, useSearchParams } from "next/navigation"; import { AppSetupPage } from "@calcom/app-store/_pages/setup"; -import { getStaticProps } from "@calcom/app-store/_pages/setup/_getStaticProps"; +import { getServerSideProps } from "@calcom/app-store/_pages/setup/_getServerSideProps"; +import type { getStaticProps } from "@calcom/app-store/_pages/setup/_getStaticProps"; import { HeadSeo } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; @@ -36,11 +37,4 @@ export default function SetupInformation(props: InferGetStaticPropsType { - return { - paths: [], - fallback: "blocking", - }; -}; - -export { getStaticProps }; +export { getServerSideProps }; diff --git a/packages/app-store/_pages/setup/_getServerSideProps.tsx b/packages/app-store/_pages/setup/_getServerSideProps.tsx new file mode 100644 index 0000000000..7b82c85992 --- /dev/null +++ b/packages/app-store/_pages/setup/_getServerSideProps.tsx @@ -0,0 +1,22 @@ +import type { GetServerSidePropsContext } from "next"; + +export const AppSetupPageMap = { + alby: import("../../alby/pages/setup/_getServerSideProps"), + make: import("../../make/pages/setup/_getServerSideProps"), + zapier: import("../../zapier/pages/setup/_getServerSideProps"), +}; + +export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { + const { slug } = ctx.params || {}; + if (typeof slug !== "string") return { notFound: true } as const; + + if (!(slug in AppSetupPageMap)) return { props: {} }; + + const page = await AppSetupPageMap[slug as keyof typeof AppSetupPageMap]; + + if (!page.getServerSideProps) return { props: {} }; + + const props = await page.getServerSideProps(ctx); + + return props; +}; diff --git a/packages/app-store/_pages/setup/_getStaticProps.tsx b/packages/app-store/_pages/setup/_getStaticProps.tsx deleted file mode 100644 index 3a10131c9d..0000000000 --- a/packages/app-store/_pages/setup/_getStaticProps.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import type { GetStaticPropsContext } from "next"; - -export const AppSetupPageMap = { - zapier: import("../../zapier/pages/setup/_getStaticProps"), - make: import("../../make/pages/setup/_getStaticProps"), -}; - -export const getStaticProps = async (ctx: GetStaticPropsContext) => { - const { slug } = ctx.params || {}; - if (typeof slug !== "string") return { notFound: true } as const; - - if (!(slug in AppSetupPageMap)) return { props: {} }; - - const page = await AppSetupPageMap[slug as keyof typeof AppSetupPageMap]; - - if (!page.getStaticProps) return { props: {} }; - - const props = await page.getStaticProps(ctx); - - return props; -}; diff --git a/packages/app-store/alby/pages/setup/_getServerSideProps.tsx b/packages/app-store/alby/pages/setup/_getServerSideProps.tsx new file mode 100644 index 0000000000..dee944924b --- /dev/null +++ b/packages/app-store/alby/pages/setup/_getServerSideProps.tsx @@ -0,0 +1,34 @@ +import type { GetServerSidePropsContext } from "next"; + +import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; + +import type { IAlbySetupProps } from "./index"; + +export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { + if (typeof ctx.params?.slug !== "string") return { notFound: true } as const; + + const { req, res } = ctx; + const session = await getServerSession({ req, res }); + + if (!session?.user?.id) { + return res.status(401).json({ message: "You must be logged in to do this" }); + } + + const credentials = await prisma.credential.findFirst({ + where: { + type: "alby_payment", + userId: session.user.id, + }, + }); + + const props: IAlbySetupProps = {}; + if (credentials?.key) { + const { account_lightning_address, account_email } = credentials.key; + props.email = account_email; + props.lightningAddress = account_lightning_address; + } + + return { + props, + }; +}; diff --git a/packages/app-store/alby/pages/setup/index.tsx b/packages/app-store/alby/pages/setup/index.tsx index 9e8ba1d1be..edafe5a0c0 100644 --- a/packages/app-store/alby/pages/setup/index.tsx +++ b/packages/app-store/alby/pages/setup/index.tsx @@ -11,13 +11,18 @@ import { Info } from "@calcom/ui/components/icon"; import { albyCredentialKeysSchema } from "../../lib/albyCredentialKeysSchema"; -export default function AlbySetup() { +export interface IAlbySetupProps { + email?: string; + lightningAddress?: string; +} + +export default function AlbySetup(props: IAlbySetupProps) { const params = globalThis.window && new URLSearchParams(window.location.search); if (params?.get("callback") === "true") { return ; } - return ; + return ; } function AlbySetupCallback() { @@ -56,7 +61,7 @@ function AlbySetupCallback() { ); } -function AlbySetupPage() { +function AlbySetupPage(props: IAlbySetupProps) { const router = useRouter(); const { t } = useLocale(); const integrations = trpc.viewer.integrations.useQuery({ variant: "payment", appId: "alby" }); @@ -120,21 +125,31 @@ function AlbySetupPage() { {showContent ? (
-

- Create or connect to an existing Alby account to receive lightning payments for your paid - bookings. -

+ {!props.lightningAddress ? ( + <> +

+ Create or connect to an existing Alby account to receive lightning payments for your paid + bookings. +

+ + + ) : ( + <> +

Alby Connected!

+

Email: {props.email}

+

Lightning Address: {props.lightningAddress}

+ + )} - {/* TODO: remove when invoices are generated using user identifier */}
Your Alby lightning address will be used to diff --git a/packages/app-store/make/pages/setup/_getStaticProps.tsx b/packages/app-store/make/pages/setup/_getServerSideProps.tsx similarity index 76% rename from packages/app-store/make/pages/setup/_getStaticProps.tsx rename to packages/app-store/make/pages/setup/_getServerSideProps.tsx index 1c6cac0efe..1582221efd 100644 --- a/packages/app-store/make/pages/setup/_getStaticProps.tsx +++ b/packages/app-store/make/pages/setup/_getServerSideProps.tsx @@ -1,4 +1,4 @@ -import type { GetStaticPropsContext } from "next"; +import type { GetServerSidePropsContext } from "next"; import getAppKeysFromSlug from "../../../_utils/getAppKeysFromSlug"; @@ -6,7 +6,7 @@ export interface IMakeSetupProps { inviteLink: string; } -export const getStaticProps = async (ctx: GetStaticPropsContext) => { +export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { if (typeof ctx.params?.slug !== "string") return { notFound: true } as const; let inviteLink = ""; const appKeys = await getAppKeysFromSlug("make"); diff --git a/packages/app-store/zapier/pages/setup/_getStaticProps.tsx b/packages/app-store/zapier/pages/setup/_getServerSideProps.tsx similarity index 76% rename from packages/app-store/zapier/pages/setup/_getStaticProps.tsx rename to packages/app-store/zapier/pages/setup/_getServerSideProps.tsx index 05b728d3fe..9231c683bd 100644 --- a/packages/app-store/zapier/pages/setup/_getStaticProps.tsx +++ b/packages/app-store/zapier/pages/setup/_getServerSideProps.tsx @@ -1,4 +1,4 @@ -import type { GetStaticPropsContext } from "next"; +import type { GetServerSidePropsContext } from "next"; import getAppKeysFromSlug from "../../../_utils/getAppKeysFromSlug"; @@ -6,7 +6,7 @@ export interface IZapierSetupProps { inviteLink: string; } -export const getStaticProps = async (ctx: GetStaticPropsContext) => { +export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { if (typeof ctx.params?.slug !== "string") return { notFound: true } as const; let inviteLink = ""; const appKeys = await getAppKeysFromSlug("zapier");