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
Confirm add-product with a proration preview before committing
Tre Dubrava6daaf88343e0
diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsxindex 47e1e7338d..c6cdfaa045 100644--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx@@ -20,6 +20,7 @@ import {useGetBillingV2Overview} from "@app/hooks/api";+import { AddProductModal } from "./components/AddProductModal";import { BillingV2RenderState, Overview } from "./components/Overview";import { ProductSheet } from "./components/ProductSheet";import { RemoveProductModal } from "./components/RemoveProductModal";@@ -49,6 +50,7 @@ export const BillingV2Page = () => {const [flow, setFlow] = useState<BillingV2Flow | null>(null);const [removeProdId, setRemoveProdId] = useState<string | null>(null);+ const [addProdId, setAddProdId] = useState<string | null>(null);// Stripe redirects back with ?checkout=success|canceled; surface the outcome and refresh state.useEffect(() => {@@ -80,6 +82,7 @@ export const BillingV2Page = () => {const cadence = intervalToCadence(overview?.interval ?? null);const removeProd = removeProdId ? catalogById(catalog, removeProdId) : undefined;+ const addProd = addProdId ? catalogById(catalog, addProdId) : undefined;const close = () => setFlow(null);@@ -135,14 +138,24 @@ export const BillingV2Page = () => {setFlow({ type: "sheet", prodId: productId });};- // Owned products are managed in the Stripe portal; a product the org isn't entitled to yet always- // goes through checkout, even when a subscription already exists.+ // Owned products are managed in the Stripe portal. A new product is added in place with a proration+ // confirmation when a subscription already exists; a first-time customer goes through Stripe Checkout.+ const hasActiveSubscription =+ overview?.subState === "active" ||+ overview?.subState === "trialing" ||+ overview?.subState === "past-due";+const onSheetManage = async (productId: string) => {const isEntitled = Boolean(overview?.entitlements[productId]?.entitled);if (isEntitled) {await redirectToPortal();return;}+ if (hasActiveSubscription) {+ close();+ setAddProdId(productId);+ return;+ }await redirectToCheckout(productId);};@@ -232,6 +245,15 @@ export const BillingV2Page = () => {onClose={() => setRemoveProdId(null)}/>)}++ {addProd && (+ <AddProductModal+ orgId={orgId}+ product={addProd}+ cadence={cadence}+ onClose={() => setAddProdId(null)}+ />+ )}</div>);};diff --git a/frontend/src/pages/organization/BillingV2Page/components/AddProductModal.tsx b/frontend/src/pages/organization/BillingV2Page/components/AddProductModal.tsxnew file mode 100644index 0000000000..f29871802e--- /dev/null+++ b/frontend/src/pages/organization/BillingV2Page/components/AddProductModal.tsx@@ -0,0 +1,113 @@+import { useEffect } from "react";+import { PlusIcon } 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,+ BillingV2Cadence,+ useAddBillingV2Product,+ usePreviewBillingV2Change+} from "@app/hooks/api";++import { fmtMoney } from "../billing-v2-data";++type Props = {+ orgId: string;+ product: BillingV2CatalogProduct;+ cadence: BillingV2Cadence;+ onClose: () => void;+};++export const AddProductModal = ({ orgId, product, cadence, onClose }: Props) => {+ const preview = usePreviewBillingV2Change();+ const addProduct = useAddBillingV2Product();++ // Preview the prorated charge once when the dialog opens, so the user confirms against real numbers.+ useEffect(() => {+ preview.mutate({ orgId, addProductId: product.id, cadence });+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [orgId, product.id, cadence]);++ const handleAdd = async () => {+ try {+ await addProduct.mutateAsync({ orgId, productId: product.id, cadence });+ createNotification({+ type: "success",+ text: `${product.name} was added. It may take a moment to update here.`+ });+ onClose();+ } catch {+ createNotification({ type: "error", text: `Failed to add ${product.name}.` });+ }+ };++ const dueToday = preview.data ? Math.max(preview.data.prorationAmount, 0) : 0;++ return (+ <AlertDialog+ open+ onOpenChange={(isOpen) => {+ if (!isOpen) {+ onClose();+ }+ }}+ >+ <AlertDialogContent className="sm:max-w-xl!">+ <AlertDialogHeader>+ <AlertDialogMedia>+ <PlusIcon />+ </AlertDialogMedia>+ <AlertDialogTitle>Add {product.name}?</AlertDialogTitle>+ <AlertDialogDescription>+ {product.name} is added to your subscription right away. You are charged an estimated+ prorated amount for the rest of this billing period, then the new recurring total going+ forward.+ </AlertDialogDescription>+ </AlertDialogHeader>+ <div className="rounded-md border border-border bg-mineshaft-700/40 px-4 py-3 text-sm">+ {preview.isPending && (+ <span className="text-mineshaft-300">Calculating your prorated charge...</span>+ )}+ {preview.isError && (+ <span className="text-mineshaft-300">+ We couldn't calculate the charge, but you can still add this product.+ </span>+ )}+ {preview.data && (+ <div className="flex flex-col gap-1.5">+ <div className="flex items-center justify-between">+ <span className="text-mineshaft-300">Estimated due today</span>+ <span className="font-semibold text-foreground tabular-nums">+ {fmtMoney(dueToday, 2)}+ </span>+ </div>+ <div className="flex items-center justify-between">+ <span className="text-mineshaft-300">New recurring total</span>+ <span className="font-semibold text-foreground tabular-nums">+ {fmtMoney(preview.data.nextRecurringTotal, 2)}+ </span>+ </div>+ </div>+ )}+ </div>+ <AlertDialogFooter>+ <AlertDialogCancel>Cancel</AlertDialogCancel>+ <AlertDialogAction variant="org" isDisabled={addProduct.isPending} onClick={handleAdd}>+ Add {product.name}+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ );+};