# Cancel Subscription Dialog URL: /docs/components/cancel-subscription/cancel-subscription-dialog The Cancel Subscription Dialog component provides a comprehensive and user-friendly interface for handling subscription cancellations. It features a two-step confirmation process, loading states, error handling, and full customization options. *** title: Cancel Subscription Dialog description: The Cancel Subscription Dialog component provides a comprehensive and user-friendly interface for handling subscription cancellations. It features a two-step confirmation process, loading states, error handling, and full customization options. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ```tsx title="src/components/cancel-subscription-dialog-demo.tsx" "use client"; import { CancelSubscriptionDialog } from "@/components/billingsdk/cancel-subscription-dialog"; import { plans } from "@/lib/billingsdk-config"; export function CancelSubscriptionDialogDemo() { return (
{ console.log("Cancelling subscription for plan:", planId); return new Promise((resolve) => { setTimeout(() => { resolve(void 0); }, 1000); }); }} onKeepSubscription={async (planId) => { console.log("Keeping subscription for plan:", planId); }} onDialogClose={() => { console.log("Dialog closed"); }} className="max-w-4xl" />
); } ```
## Installation ```bash npx shadcn@latest add @billingsdk/cancel-subscription-dialog ``` ```bash pnpm dlx shadcn@latest add @billingsdk/cancel-subscription-dialog ``` ```bash yarn dlx shadcn@latest add @billingsdk/cancel-subscription-dialog ``` ```bash bunx shadcn@latest add @billingsdk/cancel-subscription-dialog ``` ```bash npx @billingsdk/cli add cancel-subscription-dialog ``` ```bash pnpm dlx @billingsdk/cli add cancel-subscription-dialog ``` ```bash yarn dlx @billingsdk/cli add cancel-subscription-dialog ``` ```bash bunx @billingsdk/cli add cancel-subscription-dialog ``` ## Usage ```tsx import { CancelSubscriptionDialog } from "@/components/billingsdk/cancel-subscription-dialog"; import { plans } from "@/lib/billingsdk-config"; ``` ```tsx { // Handle cancellation await cancelSubscription(planId); }} /> ``` ## Props | Prop | Type | Required | Description | | -------------------- | ------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------ | | `title` | `string` | ✅ | Main dialog title | | `description` | `string` | ✅ | Dialog description text | | `plan` | `Plan` | ✅ | Plan object containing subscription details. The `plans` array in the `lib/billingsdk-config.ts` file. | | `onCancel` | `(planId: string) => Promise \| void` | ✅ | Callback when subscription is cancelled | | `triggerButtonText` | `string` | ❌ | Text for the trigger button (default: "Cancel Subscription") | | `leftPanelImageUrl` | `string` | ❌ | Background image URL for left panel | | `warningTitle` | `string` | ❌ | Title for warning section | | `warningText` | `string` | ❌ | Warning message text | | `keepButtonText` | `string` | ❌ | Text for keep subscription button | | `continueButtonText` | `string` | ❌ | Text for continue cancellation button | | `finalTitle` | `string` | ❌ | Title for final confirmation step | | `finalSubtitle` | `string` | ❌ | Subtitle for final confirmation step | | `finalWarningText` | `string` | ❌ | Final warning message | | `goBackButtonText` | `string` | ❌ | Text for go back button | | `confirmButtonText` | `string` | ❌ | Text for final confirm button | | `onKeepSubscription` | `(planId: string) => Promise \| void` | ❌ | Callback when user keeps subscription | | `onDialogClose` | `() => void` | ❌ | Callback when dialog is closed | | `className` | `string` | ❌ | Additional CSS classes | ## Theming The cancel subscription dialog component is styled using the `shadcn/ui` library. You can customize the colors and fonts by overriding the CSS variables. You can also get the theme from the [Theming](/docs/theming) page. ## Example ```tsx title="src/components/cancel-subscription-dialog-demo.tsx" "use client"; import { CancelSubscriptionDialog } from "@/components/billingsdk/cancel-subscription-dialog"; import { plans } from "@/lib/billingsdk-config"; export function CancelSubscriptionDialogDemo() { return (
{ console.log("Cancelling subscription for plan:", planId); return new Promise((resolve) => { setTimeout(() => { resolve(void 0); }, 1000); }); }} onKeepSubscription={async (planId) => { console.log("Keeping subscription for plan:", planId); }} onDialogClose={() => { console.log("Dialog closed"); }} className="max-w-4xl" />
); } ```