* feat: implement tiered Intercom chat system replacing Plain - Add TieredIntercomChat component with customer tier detection - Add IntercomContactForm for free users using Intercom API - Add /api/intercom-conversation endpoint for free user support - Update UserDropdown to use tiered chat logic - Replace Plain chat with Intercom in app providers - Remove all Plain chat components and related files - Use useHasPaidPlan hook for customer tier detection Paying customers see Intercom widget, free users see contact form that creates conversations via Intercom API. Co-Authored-By: peer@cal.com <peer@cal.com> * fix: add missing environment variables to turbo.json globalEnv - Add NEXT_PUBLIC_WEBAPP_URL, NEXT_PUBLIC_WEBSITE_URL, NEXT_PUBLIC_STRIPE_PUBLIC_KEY - Add NEXT_PUBLIC_IS_E2E, NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE_MONTHLY - Add NEXT_PUBLIC_BOOKER_NUMBER_OF_DAYS_TO_LOAD, NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID - Resolves turbo/no-undeclared-env-vars ESLint errors blocking commits Co-Authored-By: peer@cal.com <peer@cal.com> * fix: resolve linting errors in platform examples base package - Fix prettier/prettier formatting (quotes and comma) - Add underscore prefix to unused variables - Resolves CI failure in @calcom/base#lint check Co-Authored-By: peer@cal.com <peer@cal.com> * remove plain usage * placement fixes * fix: pop closing immediately issue * stuff * proper error and additional user info * add key to .env.example and remove unused plain route * fix conversation route * refactor intercom dynamic provider * code rabbit fixes * feat: introduce tiered support feature flag * fix: type check * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
172 lines
5.3 KiB
TypeScript
172 lines
5.3 KiB
TypeScript
"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 <div className="m-5">{t("loading")}</div>;
|
|
}
|
|
|
|
if (isPlatformUser && !isPaidUser)
|
|
return (
|
|
<PlatformPricing
|
|
teamId={userOrgId}
|
|
heading={
|
|
<div className="mb-5 text-center text-2xl font-semibold">
|
|
<h1>{t("subscribe_to_platform")}</h1>
|
|
</div>
|
|
}
|
|
/>
|
|
);
|
|
|
|
if (!isPlatformUser)
|
|
return (
|
|
<div>
|
|
<Shell isPlatformUser={true} withoutMain={false} SidebarContainer={<></>}>
|
|
<NoPlatformPlan />
|
|
</Shell>
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<div>
|
|
<Shell
|
|
heading={t("platform_billing")}
|
|
title={t("platform_billing")}
|
|
withoutMain={false}
|
|
subtitle={t("manage_billing_description")}
|
|
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="Cancel subscription" description={t("Cancel your existing platform subscription")}>
|
|
<CancelSubscriptionButton
|
|
buttonClassName="hidden me-2 sm:inline"
|
|
isPending={isRemoveTeamSubscriptionLoading}
|
|
handleDelete={() => {
|
|
removeTeamSubscription();
|
|
}}
|
|
/>
|
|
</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>
|
|
);
|
|
}
|
|
|
|
const CancelSubscriptionButton = ({
|
|
buttonClassName,
|
|
isPending,
|
|
onDeleteConfirmed,
|
|
handleDelete,
|
|
}: {
|
|
onDeleteConfirmed?: () => void;
|
|
buttonClassName: string;
|
|
handleDelete: () => void;
|
|
isPending: boolean;
|
|
}) => {
|
|
const { t } = useLocale();
|
|
|
|
return (
|
|
<Dialog>
|
|
<DialogTrigger asChild>
|
|
<Button color="destructive" className={buttonClassName}>
|
|
{t("cancel")}
|
|
</Button>
|
|
</DialogTrigger>
|
|
|
|
<ConfirmationDialogContent
|
|
isPending={isPending}
|
|
variety="danger"
|
|
title={t("cancel_subscription")}
|
|
confirmBtnText={t("confirm_subscription_cancellation")}
|
|
loadingText={t("confirm_subscription_cancellation")}
|
|
cancelBtnText={t("back")}
|
|
onConfirm={() => {
|
|
handleDelete();
|
|
onDeleteConfirmed?.();
|
|
}}>
|
|
{t("cancel_subscription_description")}
|
|
</ConfirmationDialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|