fix: cancel platform subscription on dashboard (#20787)
* add new endpoint to cancel user subscription * remove comments * add delete button to frontend * update correct request method * fixup * frontend for cancelling subscription * better warning message * better function name * update locales * better error handling in case stripe api call fails * rename teamId to organizationId --------- Co-authored-by: Morgan <[email protected]>
This commit is contained in:
1 parent
ef8b3e83ac
commit
fbe8cf8223
5 files changed
+145
No files matched your search
@@ -2,12 +2,17 @@
|
||||
|
||||
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";
|
||||
|
||||
@@ -37,6 +42,18 @@ export default function PlatformBillingUpgrade() {
|
||||
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>;
|
||||
}
|
||||
@@ -92,6 +109,18 @@ export default function PlatformBillingUpgrade() {
|
||||
|
||||
<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")}
|
||||
@@ -103,3 +132,41 @@ export default function PlatformBillingUpgrade() {
|
||||
</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>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user