Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(billing): require a cancellation reason in Billing V2 cancel dialogs (#8606)
Andrew Huang50525162032a
diff --git a/frontend/src/lib/analytics/events.ts b/frontend/src/lib/analytics/events.tsindex ce8cbb9527..f68d9daad2 100644--- a/frontend/src/lib/analytics/events.ts+++ b/frontend/src/lib/analytics/events.ts@@ -7,7 +7,8 @@ export const AnalyticsEvent = {SecretsAddResourceMenuOpened: "Secrets Add Resource Menu Opened",SecretsAddResourceActionSelected: "Secrets Add Resource Action Selected",ThemePreferenceChanged: "Theme Preference Changed",- SignupFlowCompleted: "Signup Flow Completed"+ SignupFlowCompleted: "Signup Flow Completed",+ BillingCancellationReasonSubmitted: "Billing Cancellation Reason Submitted"} as const;type PaywallProperties = {@@ -67,6 +68,14 @@ type SecretsAddResourceActionSelectedProperties = {environmentMode: SecretsAddResourceEnvironmentMode;};+export type BillingCancellationAction = "remove_product" | "cancel_subscription" | "cancel_trial";++type BillingCancellationReasonSubmittedProperties = {+ action: BillingCancellationAction;+ productId: string;+ reason: string;+};+export type OrganizationAnalyticsEventMap = {[AnalyticsEvent.PaywallViewed]: PaywallProperties;[AnalyticsEvent.PaywallUpgradeClicked]: PaywallProperties;@@ -75,6 +84,7 @@ export type OrganizationAnalyticsEventMap = {[AnalyticsEvent.FolderAccessGrantSheetOpened]: FolderAccessGrantSheetOpenedProperties;[AnalyticsEvent.SecretsAddResourceMenuOpened]: SecretsAddResourceMenuOpenedProperties;[AnalyticsEvent.SecretsAddResourceActionSelected]: SecretsAddResourceActionSelectedProperties;+ [AnalyticsEvent.BillingCancellationReasonSubmitted]: BillingCancellationReasonSubmittedProperties;};export type OrganizationAnalyticsEvent = keyof OrganizationAnalyticsEventMap;diff --git a/frontend/src/lib/analytics/index.ts b/frontend/src/lib/analytics/index.tsindex b6a54ba306..113d452e46 100644--- a/frontend/src/lib/analytics/index.ts+++ b/frontend/src/lib/analytics/index.ts@@ -33,6 +33,7 @@ export const analytics = {export { AnalyticsEvent };export type {+ BillingCancellationAction,FolderAccessGrantSheetSource,SecretsAddResourceAction,SecretsAddResourceMenuLevel,diff --git a/frontend/src/pages/organization/BillingV2Page/components/CancellationFeedbackDialog.tsx b/frontend/src/pages/organization/BillingV2Page/components/CancellationFeedbackDialog.tsxnew file mode 100644index 0000000000..8ed6ab78e0--- /dev/null+++ b/frontend/src/pages/organization/BillingV2Page/components/CancellationFeedbackDialog.tsx@@ -0,0 +1,175 @@+import { ReactNode } from "react";+import { Controller, useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";+import { z } from "zod";++import {+ AlertDialog,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogMedia,+ AlertDialogTitle,+ Button,+ Field,+ FieldError,+ FieldLabel,+ Label,+ RadioGroup,+ RadioGroupItem+} from "@app/components/v3";+import { analytics, AnalyticsEvent, type BillingCancellationAction } from "@app/lib/analytics";++// Values match Stripe's subscription cancellation_details.feedback enum, the same reasons the Stripe+// Customer Portal collects, so in-app and portal feedback share one vocabulary.+const CANCELLATION_REASONS = [+ { value: "too_expensive", label: "Too expensive" },+ { value: "missing_features", label: "Missing features" },+ { value: "switched_service", label: "Switching to another service" },+ { value: "unused", label: "Not using it enough" },+ { value: "too_complex", label: "Too difficult to use" },+ { value: "low_quality", label: "Quality issues" },+ { value: "customer_service", label: "Poor customer service" },+ { value: "other", label: "Other" }+] as const;++type CancellationReason = (typeof CANCELLATION_REASONS)[number]["value"];++const formSchema = z.object({+ reason: z.enum(+ CANCELLATION_REASONS.map((reason) => reason.value) as [+ CancellationReason,+ ...CancellationReason[]+ ],+ { message: "Select a reason to continue." }+ )+});++type FormData = z.infer<typeof formSchema>;++type Props = {+ orgId: string;+ productId: string;+ action: BillingCancellationAction;+ icon: ReactNode;+ title: string;+ description: ReactNode;+ reasonLabel: string;+ confirmLabel: string;+ dismissLabel: string;+ isConfirmDisabled?: boolean;+ children?: ReactNode;+ // Runs the cancellation; rejects when it fails so the dialog stays open and no reason is recorded.+ onConfirm: () => Promise<unknown>;+ onConfirmed: () => void;+ onDismiss: () => void;+};++export const CancellationFeedbackDialog = ({+ orgId,+ productId,+ action,+ icon,+ title,+ description,+ reasonLabel,+ confirmLabel,+ dismissLabel,+ isConfirmDisabled,+ children,+ onConfirm,+ onConfirmed,+ onDismiss+}: Props) => {+ const {+ control,+ handleSubmit,+ formState: { isSubmitting }+ } = useForm<FormData>({+ resolver: zodResolver(formSchema)+ });++ const onSubmit = async ({ reason }: FormData) => {+ try {+ await onConfirm();+ } catch {+ // The backend's message is surfaced by the global mutation error handler (reactQuery.tsx).+ return;+ }+ analytics.captureForOrganization(AnalyticsEvent.BillingCancellationReasonSubmitted, orgId, {+ action,+ productId,+ reason+ });+ onConfirmed();+ };++ return (+ <AlertDialog+ open+ onOpenChange={(isOpen) => {+ if (!isOpen && !isSubmitting) {+ onDismiss();+ }+ }}+ >+ <AlertDialogContent className="sm:max-w-xl!">+ <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-6">+ <AlertDialogHeader>+ <AlertDialogMedia>{icon}</AlertDialogMedia>+ <AlertDialogTitle>{title}</AlertDialogTitle>+ <AlertDialogDescription>{description}</AlertDialogDescription>+ </AlertDialogHeader>+ {children}+ <Controller+ control={control}+ name="reason"+ render={({ field, fieldState }) => (+ <Field>+ <FieldLabel id="cancellation-reason-label">{reasonLabel}</FieldLabel>+ <RadioGroup+ aria-labelledby="cancellation-reason-label"+ value={field.value ?? ""}+ onValueChange={field.onChange}+ disabled={isSubmitting}+ className="sm:grid-cols-2"+ >+ {CANCELLATION_REASONS.map((reason) => {+ const id = `cancellation-reason-${reason.value}`;+ return (+ <div key={reason.value} className="flex items-center gap-3">+ <RadioGroupItem+ id={id}+ value={reason.value}+ isError={Boolean(fieldState.error)}+ />+ <Label htmlFor={id} className="font-normal">+ {reason.label}+ </Label>+ </div>+ );+ })}+ </RadioGroup>+ <FieldError>{fieldState.error?.message}</FieldError>+ </Field>+ )}+ />+ <AlertDialogFooter>+ <AlertDialogCancel isDisabled={isSubmitting}>{dismissLabel}</AlertDialogCancel>+ <Button+ type="submit"+ variant="danger"+ size="sm"+ isDisabled={isSubmitting || isConfirmDisabled}+ isPending={isSubmitting}+ >+ {confirmLabel}+ </Button>+ </AlertDialogFooter>+ </form>+ </AlertDialogContent>+ </AlertDialog>+ );+};diff --git a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsxindex 529af7e5a4..5e1a980a2d 100644--- a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx@@ -56,6 +56,7 @@ import {unitPrice} from "../billing-v2-format";import { ActivateView } from "./ActivateView";+import { CancellationFeedbackDialog } from "./CancellationFeedbackDialog";import { CommitmentView } from "./CommitmentView";import { ActiveBadge, DimensionMeter, ProductIcon } from "./shared";import { UpgradeView } from "./UpgradeView";@@ -583,19 +584,14 @@ export const ProductSheet = ({}};- const handleCancelTrial = async () => {- try {- await cancelTrial.mutateAsync({ orgId, productId: prod.id });- createNotification({- type: "success",- text: upgradeTrialPlan- ? `Your ${upgradeTrialPlan} trial has ended. You're still on ${basePlanName}.`- : `Your ${prod.name} trial has been canceled.`- });- onClose();- } catch {- setShowCancelTrial(false);- }+ const handleCancelTrialConfirmed = () => {+ createNotification({+ type: "success",+ text: upgradeTrialPlan+ ? `Your ${upgradeTrialPlan} trial has ended. You're still on ${basePlanName}.`+ : `Your ${prod.name} trial has been canceled.`+ });+ onClose();};const activatePlanObj = activatePlan@@ -813,46 +809,32 @@ export const ProductSheet = ({</AlertDialogContent></AlertDialog>- <AlertDialog- open={showCancelTrial}- onOpenChange={(open) => {- if (!open && !cancelTrial.isPending) {- setShowCancelTrial(false);+ {showCancelTrial && (+ <CancellationFeedbackDialog+ orgId={orgId}+ productId={prod.id}+ action="cancel_trial"+ icon={<CalendarX2Icon />}+ title={+ upgradeTrialPlan+ ? `End your ${upgradeTrialPlan} trial`+ : `Cancel your ${prod.name} trial`}- }}- >- <AlertDialogContent className="sm:max-w-lg!">- <AlertDialogHeader>- <AlertDialogMedia>- <CalendarX2Icon />- </AlertDialogMedia>- <AlertDialogTitle>- {upgradeTrialPlan- ? `End your ${upgradeTrialPlan} trial`- : `Cancel your ${prod.name} trial`}- </AlertDialogTitle>- <AlertDialogDescription>- {upgradeTrialPlan- ? `You'll go back to ${basePlanName} right away and won't be charged anything. This trial can't be restarted later.`- : "Canceling returns you to the free tier immediately and stops the trial from converting to a paid plan. This trial can't be restarted later."}- </AlertDialogDescription>- </AlertDialogHeader>- <AlertDialogFooter>- <AlertDialogCancel>Keep trial</AlertDialogCancel>- <AlertDialogAction- variant="danger"- isDisabled={cancelTrial.isPending}- isPending={cancelTrial.isPending}- onClick={(e) => {- e.preventDefault();- handleCancelTrial();- }}- >- {upgradeTrialPlan ? "End trial" : "Cancel trial"}- </AlertDialogAction>- </AlertDialogFooter>- </AlertDialogContent>- </AlertDialog>+ description={+ upgradeTrialPlan+ ? `You'll go back to ${basePlanName} right away and won't be charged anything. This trial can't be restarted later.`+ : "Canceling returns you to the free tier immediately and stops the trial from converting to a paid plan. This trial can't be restarted later."+ }+ reasonLabel={+ upgradeTrialPlan ? "Why are you ending your trial?" : "Why are you canceling?"+ }+ confirmLabel={upgradeTrialPlan ? "End trial" : "Cancel trial"}+ dismissLabel="Keep trial"+ onConfirm={() => cancelTrial.mutateAsync({ orgId, productId: prod.id })}+ onConfirmed={handleCancelTrialConfirmed}+ onDismiss={() => setShowCancelTrial(false)}+ />+ )}</>);};diff --git a/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx b/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsxindex 13b848b956..a1c985d4b9 100644--- a/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx@@ -2,17 +2,6 @@ import { useEffect } from "react";import { CalendarX2Icon, Trash2Icon } from "lucide-react";import { createNotification } from "@app/components/notifications";-import {- AlertDialog,- AlertDialogAction,- AlertDialogCancel,- AlertDialogContent,- AlertDialogDescription,- AlertDialogFooter,- AlertDialogHeader,- AlertDialogMedia,- AlertDialogTitle-} from "@app/components/v3";import {BillingV2CatalogProduct,useGetBillingV2Overview,@@ -21,6 +10,7 @@ import {} from "@app/hooks/api";import { dimCommitted, fmtMoney } from "../billing-v2-format";+import { CancellationFeedbackDialog } from "./CancellationFeedbackDialog";// Removing the last product cancels the whole subscription (handled by the remove endpoint). The// unused-time wording depends on whether the plan carries a minimum (annual) commitment.@@ -66,56 +56,34 @@ export const RemoveProductModal = ({ orgId, product, onClose, onRemoved }: Props// eslint-disable-next-line react-hooks/exhaustive-deps}, [orgId, product.id, isOnlyProduct]);- const handleRemove = async (e: React.MouseEvent<HTMLButtonElement>) => {- e.preventDefault();- try {- await removeProduct.mutateAsync({ orgId, productId: product.id });- createNotification({- type: "success",- text: isOnlyProduct- ? "Your subscription will be canceled. It may take a moment to update here."- : `${product.name} will be removed. It may take a moment to update here.`- });- onRemoved();- } catch {- // The backend's message is surfaced by the global mutation error handler (reactQuery.tsx).- }+ const handleRemove = () => removeProduct.mutateAsync({ orgId, productId: product.id });++ const handleRemoved = () => {+ createNotification({+ type: "success",+ text: isOnlyProduct+ ? "Your subscription will be canceled. It may take a moment to update here."+ : `${product.name} will be removed. It may take a moment to update here.`+ });+ onRemoved();};if (isOnlyProduct) {return (- <AlertDialog- open- onOpenChange={(isOpen) => {- if (!isOpen) {- onClose();- }- }}- >- <AlertDialogContent className="sm:max-w-xl!">- <AlertDialogHeader>- <AlertDialogMedia>- <CalendarX2Icon />- </AlertDialogMedia>- <AlertDialogTitle>Cancel your subscription?</AlertDialogTitle>- <AlertDialogDescription>- {product.name} is the only product on your subscription, so removing it ends your- subscription. {hasCommitment ? COMMITMENT_MESSAGE : CREDIT_MESSAGE}- </AlertDialogDescription>- </AlertDialogHeader>- <AlertDialogFooter>- <AlertDialogCancel>Keep subscription</AlertDialogCancel>- <AlertDialogAction- variant="danger"- isDisabled={removeProduct.isPending}- onClick={handleRemove}- isPending={removeProduct.isPending}- >- Cancel subscription- </AlertDialogAction>- </AlertDialogFooter>- </AlertDialogContent>- </AlertDialog>+ <CancellationFeedbackDialog+ orgId={orgId}+ productId={product.id}+ action="cancel_subscription"+ icon={<CalendarX2Icon />}+ title="Cancel your subscription?"+ description={`${product.name} is the only product on your subscription, so removing it ends your subscription. ${hasCommitment ? COMMITMENT_MESSAGE : CREDIT_MESSAGE}`}+ reasonLabel="Why are you canceling?"+ confirmLabel="Cancel subscription"+ dismissLabel="Keep subscription"+ onConfirm={handleRemove}+ onConfirmed={handleRemoved}+ onDismiss={onClose}+ />);}@@ -126,63 +94,47 @@ export const RemoveProductModal = ({ orgId, product, onClose, onRemoved }: Propsconst previewLoading = !preview.data && !preview.isError;return (- <AlertDialog- open- onOpenChange={(isOpen) => {- if (!isOpen) {- onClose();- }- }}+ <CancellationFeedbackDialog+ orgId={orgId}+ productId={product.id}+ action="remove_product"+ icon={<Trash2Icon />}+ title={`Remove ${product.name}?`}+ description={`${product.name} is removed right away. The unused time you already paid for is credited to your next invoice, and your other products are unaffected.`}+ reasonLabel={`Why are you removing ${product.name}?`}+ confirmLabel={`Remove ${product.name}`}+ dismissLabel="Keep product"+ isConfirmDisabled={previewLoading}+ onConfirm={handleRemove}+ onConfirmed={handleRemoved}+ onDismiss={onClose}>- <AlertDialogContent className="sm:max-w-xl!">- <AlertDialogHeader>- <AlertDialogMedia>- <Trash2Icon />- </AlertDialogMedia>- <AlertDialogTitle>Remove {product.name}?</AlertDialogTitle>- <AlertDialogDescription>- {product.name} is removed right away. The unused time you already paid for is credited- to your next invoice, and your other products are unaffected.- </AlertDialogDescription>- </AlertDialogHeader>- <div className="rounded-md border border-border bg-surface-hover/40 px-4 py-3 text-sm">- {preview.isPending && (- <span className="text-label">Calculating your prorated credit...</span>- )}- {preview.isError && (- <span className="text-label">- We couldn't calculate the credit, but you can still remove this product.- </span>- )}- {preview.data && (- <div className="flex flex-col gap-1.5">- <div className="flex items-center justify-between">- <span className="text-label">Prorated credit to next invoice</span>- <span className="font-semibold text-foreground tabular-nums">- {fmtMoney(credit, 2)}- </span>- </div>- <div className="flex items-center justify-between">- <span className="text-label">New recurring total</span>- <span className="font-semibold text-foreground tabular-nums">- {fmtMoney(preview.data.nextRecurringTotal, 2)}- </span>- </div>+ <div className="rounded-md border border-border bg-surface-hover/40 px-4 py-3 text-sm">+ {preview.isPending && (+ <span className="text-label">Calculating your prorated credit...</span>+ )}+ {preview.isError && (+ <span className="text-label">+ We couldn't calculate the credit, but you can still remove this product.+ </span>+ )}+ {preview.data && (+ <div className="flex flex-col gap-1.5">+ <div className="flex items-center justify-between">+ <span className="text-label">Prorated credit to next invoice</span>+ <span className="font-semibold text-foreground tabular-nums">+ {fmtMoney(credit, 2)}+ </span>+ </div>+ <div className="flex items-center justify-between">+ <span className="text-label">New recurring total</span>+ <span className="font-semibold text-foreground tabular-nums">+ {fmtMoney(preview.data.nextRecurringTotal, 2)}+ </span></div>- )}- </div>- <AlertDialogFooter>- <AlertDialogCancel>Keep product</AlertDialogCancel>- <AlertDialogAction- variant="danger"- isDisabled={removeProduct.isPending || previewLoading}- onClick={handleRemove}- isPending={removeProduct.isPending}- >- Remove {product.name}- </AlertDialogAction>- </AlertDialogFooter>- </AlertDialogContent>- </AlertDialog>+ </div>+ )}+ </div>+ </CancellationFeedbackDialog>);};