"use client"; import { usePathname } from "next/navigation"; import { Dialog } from "@calcom/features/components/controlled-dialog"; 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/components/button"; import { DialogTrigger, ConfirmationDialogContent } from "@calcom/ui/components/dialog"; import { showToast } from "@calcom/ui/components/toast"; import { PlatformPricing } from "@calcom/web/components/settings/platform/pricing/platform-pricing/index"; import { useUnsubscribeTeamToStripe } from "@lib/hooks/settings/platform/billing/useUnsubscribeTeamToStripe"; import NoPlatformPlan from "@components/settings/platform/dashboard/NoPlatformPlan"; import { useGetUserAttributes } from "@components/settings/platform/hooks/useGetUserAttributes"; import { CtaRow } from "~/settings/billing/billing-view"; declare global { interface Window { Support?: { open: () => void; shouldShowTriggerButton: (showTrigger: boolean) => void; }; } } export default function PlatformBillingUpgrade() { const pathname = usePathname(); const { t } = useLocale(); const returnTo = pathname; const billingHref = `/api/integrations/stripepayment/portal?returnTo=${WEBAPP_URL}${returnTo}`; const onContactSupportClick = async () => { if (window.Support) { window.Support.open(); } }; const { isUserLoading, isUserBillingDataLoading, isPlatformUser, userBillingData, isPaidUser, userOrgId } = useGetUserAttributes(); const { mutateAsync: removeTeamSubscription, isPending: isRemoveTeamSubscriptionLoading } = useUnsubscribeTeamToStripe({ onSuccess: () => { window.location.href = "/settings/platform/"; showToast(t("team_subscription_cancelled_successfully"), "success"); }, onError: () => { showToast(t("team_subscription_cancellation_error"), "error"); }, teamId: userOrgId, }); if (isUserLoading || (isUserBillingDataLoading && !userBillingData)) { return
{t("loading")}
; } if (isPlatformUser && !isPaidUser) return (

{t("subscribe_to_platform")}

} /> ); if (!isPlatformUser) return (
}>
); return (
<>


{ removeTeamSubscription(); }} />
); } const CancelSubscriptionButton = ({ buttonClassName, isPending, onDeleteConfirmed, handleDelete, }: { onDeleteConfirmed?: () => void; buttonClassName: string; handleDelete: () => void; isPending: boolean; }) => { const { t } = useLocale(); return ( { handleDelete(); onDeleteConfirmed?.(); }}> {t("cancel_subscription_description")} ); };