feat: billing tab for platform (#16755)

* modules for platform plans and billing pages

* add platform billing and plans related pages

* update platform navigation to include billing tab

* custom hook to upgrade team subscription

* refactors

* export cta row component

* fixup

* only pass in subscription id instead of whole subscription

* refactor :teamId/subscribe endpoint logic, add endpoint for upgrading stripe and shift all webhooks logic into services

* refactor team subscription logic, add logic for upgrading stripe and  webhooks logic from billing controller

---------

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Rajiv SahalandPeer Richelsen authored and GitHub committed 2024-09-23 13:36:03 +03:00
1 parent f642a6ebeb
commit 3371602e0f
13 files changed
+436 -107

No files matched your search

@@ -15,7 +15,7 @@ interface CtaRowProps {
className?: string;
}
const CtaRow = ({ title, description, className, children }: CtaRowProps) => {
export const CtaRow = ({ title, description, className, children }: CtaRowProps) => {
return (
<>
<section className={classNames("text-default flex flex-col sm:flex-row", className)}>
@@ -0,0 +1,75 @@
"use client";
import { usePathname } from "next/navigation";
import { useIntercom } from "@calcom/features/ee/support/lib/intercom/useIntercom";
import Shell from "@calcom/features/shell/Shell";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button } from "@calcom/ui";
import NoPlatformPlan from "@components/settings/platform/dashboard/NoPlatformPlan";
import { useGetUserAttributes } from "@components/settings/platform/hooks/useGetUserAttributes";
import { CtaRow } from "~/settings/billing/billing-view";
export default function PlatformBillingUpgrade() {
const pathname = usePathname();
const { t } = useLocale();
const { open } = useIntercom();
const returnTo = pathname;
const billingHref = `/api/integrations/stripepayment/portal?returnTo=${WEBAPP_URL}${returnTo}`;
const onContactSupportClick = async () => {
await open();
};
const { isUserLoading, isUserBillingDataLoading, isPlatformUser, userBillingData } = useGetUserAttributes();
if (isUserLoading || (isUserBillingDataLoading && !userBillingData)) {
return <div className="m-5">Loading...</div>;
}
if (!isPlatformUser) return <NoPlatformPlan />;
return (
<div>
<Shell
heading="Platform billing"
title="Platform billing"
hideHeadingOnMobile
withoutMain={false}
subtitle="Manage all things billing"
isPlatformUser={true}>
<>
<div className="border-subtle space-y-6 rounded-lg border px-6 py-8 text-sm sm:space-y-8">
<CtaRow
title={t("view_and_manage_billing_details")}
description={t("view_and_edit_billing_details")}>
<Button color="primary" href={billingHref} target="_blank" EndIcon="external-link">
{t("billing_portal")}
</Button>
</CtaRow>
<hr className="border-subtle" />
<CtaRow
title="Change plan"
description={t("Want to change your existing plan or check out other plans?")}>
<Button href="/settings/platform/plans" color="secondary">
Plans
</Button>
</CtaRow>
<hr className="border-subtle" />
<CtaRow title={t("need_anything_else")} description={t("further_billing_help")}>
<Button color="secondary" onClick={onContactSupportClick}>
{t("contact_support")}
</Button>
</CtaRow>
</div>
</>
</Shell>
</div>
);
}
@@ -0,0 +1,36 @@
"use client";
import Shell from "@calcom/features/shell/Shell";
import NoPlatformPlan from "@components/settings/platform/dashboard/NoPlatformPlan";
import { useGetUserAttributes } from "@components/settings/platform/hooks/useGetUserAttributes";
import { PlatformPricing } from "@components/settings/platform/pricing/platform-pricing";
export default function PlatformPlans() {
const { isUserLoading, isUserBillingDataLoading, isPlatformUser, isPaidUser, userBillingData, userOrgId } =
useGetUserAttributes();
if (isUserLoading || (isUserBillingDataLoading && !userBillingData)) {
return <div className="m-5">Loading...</div>;
}
if (!isPlatformUser) return <NoPlatformPlan />;
return (
<div>
<Shell
backPath
isPlatformUser={true}
heading={
<h1 className="mx-2 mt-4 text-center text-xl md:text-2xl">
You are currently subscribed to {userBillingData?.plan[0]}
{userBillingData?.plan.slice(1).toLocaleLowerCase()} plan
</h1>
}
withoutMain={false}
SidebarContainer={<></>}>
<PlatformPricing teamId={userOrgId} teamPlan={userBillingData?.plan.toLocaleLowerCase()} />
</Shell>
</div>
);
}
@@ -58,7 +58,17 @@ export default function Platform() {
return <div className="m-5">Loading...</div>;
}
if (isPlatformUser && !isPaidUser) return <PlatformPricing teamId={userOrgId} />;
if (isPlatformUser && !isPaidUser)
return (
<PlatformPricing
teamId={userOrgId}
heading={
<div className="mb-5 text-center text-2xl font-semibold">
<h1>Subscribe to Platform</h1>
</div>
}
/>
);
if (isPlatformUser) {
return (