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): implement ProductCardSkeleton for loading states
Victor Hugo dos Santos78d83222cbf8
diff --git a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductCardSkeleton.tsx b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductCardSkeleton.tsxnew file mode 100644index 0000000000..7ceff01204--- /dev/null+++ b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductCardSkeleton.tsx@@ -0,0 +1,155 @@+import { Skeleton } from "@app/components/v3";+import { cn } from "@app/components/v3/utils";+import { BillingV2Entitlement } from "@app/hooks/api";++import { commitSavingsNudge, dimHasCeiling, productAnnualCommitted } from "../../billing-v2-format";+import { breakdownableDimensions } from "../UsageBreakdownSheet";++type MeterRow = { key: string; hasBar: boolean };++export type ProductCardShape = {+ meters: MeterRow[];+ figures: number;+ hasOnDemandNote: boolean;+ hasAction: boolean;+ hasTrialStrip: boolean;+ hasBreakdownStrip: boolean;+ hasCommitStrip: boolean;+};++type ShapeContext = { readOnly?: boolean; selfServe: boolean };++export const productCardShape = (+ entitlement: BillingV2Entitlement | undefined,+ { readOnly, selfServe }: ShapeContext+): ProductCardShape => {+ const annualCommitted = productAnnualCommitted(entitlement);+ const monthlyRecurring = entitlement?.cadence === "annual" ? 0 : (entitlement?.amount ?? 0);++ return {+ meters: (entitlement?.dimensions ?? []).map((dim) => ({+ key: dim.key,+ hasBar: dimHasCeiling(dim)+ })),+ figures: [annualCommitted > 0, monthlyRecurring > 0].filter(Boolean).length,+ hasOnDemandNote: (entitlement?.onDemandAmount ?? 0) > 0,+ hasAction: !readOnly && selfServe,+ hasTrialStrip: Boolean(entitlement?.trialPlan),+ hasBreakdownStrip: breakdownableDimensions(entitlement).length > 0,+ hasCommitStrip: Boolean(!readOnly && selfServe && commitSavingsNudge(entitlement))+ };+};++export const UNKNOWN_PRODUCT_SHAPE: ProductCardShape = {+ meters: [+ { key: "first", hasBar: true },+ { key: "second", hasBar: true }+ ],+ figures: 0,+ hasOnDemandNote: false,+ hasAction: false,+ hasTrialStrip: false,+ hasBreakdownStrip: true,+ hasCommitStrip: false+};++const FIGURES = ["figure-a", "figure-b"];++export const ActiveProductCardSkeleton = ({ shape }: { shape: ProductCardShape }) => {+ const priceLines = shape.figures + (shape.hasOnDemandNote ? 1 : 0);+ const figureBox = priceLines > 1 ? "h-6" : "h-7";++ return (+ <div className="flex flex-col gap-3 rounded-lg border border-border bg-container p-4">+ <div className="flex items-center gap-3">+ <Skeleton className="size-10 shrink-0 rounded-lg" />+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">+ <div className="flex h-5.5 items-center">+ <Skeleton className="h-3.5 w-44" />+ </div>+ <div className="flex h-4 items-center">+ <Skeleton className="h-3 w-32" />+ </div>+ </div>+ <div className="flex shrink-0 flex-col items-end gap-0.5">+ {priceLines === 0 ? (+ <div className="flex h-5 items-center">+ <Skeleton className="h-3.5 w-14" />+ </div>+ ) : (+ <>+ {FIGURES.slice(0, shape.figures).map((figure) => (+ <div key={figure} className={cn("flex items-center", figureBox)}>+ <Skeleton className="h-4 w-24" />+ </div>+ ))}+ {shape.hasOnDemandNote && (+ <div className="flex h-4 items-center">+ <Skeleton className="h-3 w-28" />+ </div>+ )}+ </>+ )}+ </div>+ {shape.hasAction && <Skeleton className="h-8 w-20 shrink-0 rounded-md" />}+ </div>++ {shape.hasTrialStrip && (+ <div className="-mx-4 flex flex-col gap-1.5 border-y border-border bg-warning/5 px-4 py-2.5">+ <div className="flex h-4 items-center justify-between gap-3">+ <Skeleton className="h-3 w-40" />+ <Skeleton className="h-3 w-20" />+ </div>+ <div className="flex h-4 items-center">+ <Skeleton className="h-2.5 w-56" />+ </div>+ </div>+ )}++ {shape.meters.length > 0 && (+ <div className="flex flex-col gap-3.5">+ {shape.meters.map((meter) => (+ <div key={meter.key} className="flex flex-col gap-1.5">+ <div className="flex h-4 items-center justify-between gap-2.5">+ <Skeleton className="h-3 w-24" />+ <Skeleton className="h-3 w-28" />+ </div>+ {meter.hasBar && <Skeleton className="h-[5px] w-full rounded-xs" />}+ </div>+ ))}+ </div>+ )}++ {shape.hasBreakdownStrip && (+ <div+ className={cn(+ "-mx-4 -mb-4 flex items-center justify-between gap-3 border-t border-border px-4 py-2.5",+ shape.hasCommitStrip && "mb-0"+ )}+ >+ <div className="flex h-4 items-center">+ <Skeleton className="h-3 w-44" />+ </div>+ <div className="flex h-4 items-center">+ <Skeleton className="h-3 w-24" />+ </div>+ </div>+ )}++ {shape.hasCommitStrip && (+ <div+ className={cn(+ "-mx-4 -mb-4 flex items-center justify-between gap-3 border-t border-border bg-warning/5 px-4 py-2.5",+ shape.hasBreakdownStrip ? "-mt-3" : "mt-1"+ )}+ >+ <div className="flex min-w-0 items-center gap-2.5">+ <Skeleton className="size-6 shrink-0 rounded-md" />+ <Skeleton className="h-3 w-56" />+ </div>+ <Skeleton className="h-8 w-28 shrink-0 rounded-md" />+ </div>+ )}+ </div>+ );+};diff --git a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsxindex f7b47b1094..42f4df20f2 100644--- a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx@@ -11,7 +11,6 @@ import {CardDescription,CardHeader,CardTitle,- Skeleton,Tooltip,TooltipContent,TooltipTrigger@@ -21,7 +20,6 @@ import { useOrganization } from "@app/context";import {BillingV2CatalogProduct,BillingV2Entitlement,- BillingV2EntitlementDim,BillingV2Overview,useRefreshBillingV2Entitlements} from "@app/hooks/api";@@ -37,6 +35,11 @@ import {import { asPlanDeprecation, deprecationSubline } from "../deprecation/deprecation-data";import { ActiveBadge, CardEmpty, DimensionMeter, ProductIcon } from "../shared";import { breakdownableDimensions } from "../UsageBreakdownSheet";+import {+ ActiveProductCardSkeleton,+ productCardShape,+ UNKNOWN_PRODUCT_SHAPE+} from "./ProductCardSkeleton";type ActiveProductCardProps = {prod: BillingV2CatalogProduct;@@ -306,65 +309,7 @@ const AvailableProductTile = ({);};-type ProductSkeletonRow = { key: string; hasBar: boolean };--const skeletonRows = (dims: BillingV2EntitlementDim[]): ProductSkeletonRow[] =>- dims.map((dim) => ({ key: dim.key, hasBar: dimHasCeiling(dim) }));--const UNKNOWN_PRODUCT_ROWS: ProductSkeletonRow[] = [- { key: "first", hasBar: true },- { key: "second", hasBar: true }-];--type ActiveProductCardSkeletonProps = {- rows: ProductSkeletonRow[];- hasBreakdown: boolean;- showAction: boolean;- className?: string;-};--const ActiveProductCardSkeleton = ({- rows,- hasBreakdown,- showAction,- className-}: ActiveProductCardSkeletonProps) => (- <div- className={cn(- "flex flex-col gap-3 overflow-hidden rounded-lg border border-border bg-container p-4",- className- )}- >- <div className="flex items-center gap-3">- <Skeleton className="size-10 shrink-0 rounded-lg" />- <div className="flex min-w-0 flex-1 flex-col gap-2">- <Skeleton className="h-3.5 w-2/5" />- <Skeleton className="h-2.5 w-1/4" />- </div>- <Skeleton className="h-4 w-16 shrink-0" />- {showAction && <Skeleton className="h-8 w-20 shrink-0 rounded-md" />}- </div>- {rows.length > 0 && (- <div className="flex flex-col gap-3.5">- {rows.map((row) => (- <div key={row.key} className="flex flex-col gap-2">- <div className="flex items-center justify-between gap-2.5">- <Skeleton className="h-2.5 w-24" />- <Skeleton className="h-2.5 w-28" />- </div>- {row.hasBar && <Skeleton className="h-[5px] w-full rounded-xs" />}- </div>- ))}- </div>- )}- {hasBreakdown && (- <div className="-mx-4 mt-auto -mb-4 flex items-center justify-between gap-3 border-t border-border px-4 py-3">- <Skeleton className="h-2.5 w-44" />- <Skeleton className="h-2.5 w-24" />- </div>- )}- </div>-);+const UNKNOWN_PRODUCTS = ["product-a", "product-b"];type ProductsCardProps = {overview?: BillingV2Overview;@@ -449,13 +394,8 @@ export const ProductsCard = ({<CardContent>{!overview && (<div className="flex flex-col gap-4">- {[0, 1].map((i) => (- <ActiveProductCardSkeleton- key={i}- rows={UNKNOWN_PRODUCT_ROWS}- hasBreakdown- showAction={false}- />+ {UNKNOWN_PRODUCTS.map((product) => (+ <ActiveProductCardSkeleton key={product} shape={UNKNOWN_PRODUCT_SHAPE} />))}</div>)}@@ -474,29 +414,28 @@ export const ProductsCard = ({/>)}<div className="flex flex-col gap-4">- {active.map((prod) => (- <div key={prod.id} className="relative">- <div className={cn(isReloading && "invisible")} aria-hidden={isReloading}>- <ActiveProductCard- prod={prod}- entitlement={entitlements[prod.id]}- readOnly={readOnly}- selfServe={overview.selfServe}- onManage={onManage}- onSetCommitment={onSetCommitment}- onViewBreakdown={onViewBreakdown}- />- </div>- {isReloading && (- <ActiveProductCardSkeleton- className="absolute inset-0"- rows={skeletonRows(entitlements[prod.id]?.dimensions ?? [])}- hasBreakdown={breakdownableDimensions(entitlements[prod.id]).length > 0}- showAction={!readOnly && overview.selfServe}- />- )}- </div>- ))}+ {active.map((prod) =>+ isReloading ? (+ <ActiveProductCardSkeleton+ key={prod.id}+ shape={productCardShape(entitlements[prod.id], {+ readOnly,+ selfServe: overview.selfServe+ })}+ />+ ) : (+ <ActiveProductCard+ key={prod.id}+ prod={prod}+ entitlement={entitlements[prod.id]}+ readOnly={readOnly}+ selfServe={overview.selfServe}+ onManage={onManage}+ onSetCommitment={onSetCommitment}+ onViewBreakdown={onViewBreakdown}+ />+ )+ )}{available.length > 0 && (<><div className="flex items-center gap-3 pt-2">diff --git a/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsx b/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsxindex 299c23e520..db202708f3 100644--- a/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsx@@ -1,20 +1,27 @@import { Card, CardAction, CardContent, CardHeader, CardTitle, Skeleton } from "@app/components/v3";+const TILES = ["account", "next-charge", "what-you-pay"];+const DETAIL_ROWS = ["row-a", "row-b", "row-c"];+export const StatTilesSkeleton = () => (<div className="flex flex-col gap-3"><div className="flex flex-col gap-4 lg:flex-row">- {[0, 1, 2].map((i) => (- <Card key={i} className="flex-1 gap-2 p-4 shadow-none">+ {TILES.map((tile) => (+ <Card key={tile} className="flex-1 gap-2 p-4 shadow-none"><CardHeader><CardTitle>- <Skeleton className="h-3 w-16" />+ <div className="flex h-4 items-center">+ <Skeleton className="h-3 w-16" />+ </div></CardTitle><CardAction><Skeleton className="size-7 rounded-md" /></CardAction></CardHeader><CardContent className="flex flex-col gap-1.5">- <Skeleton className="h-5 w-2/3" />+ <div className="flex h-7 items-center">+ <Skeleton className="h-4 w-2/3" />+ </div><div className="flex min-h-5 items-center"><Skeleton className="h-3 w-24" /></div>@@ -25,20 +32,24 @@ export const StatTilesSkeleton = () => (<div className="flex items-start gap-2 px-1"><Skeleton className="mt-[2px] size-3 shrink-0 rounded-full" /><div className="flex flex-1 flex-col gap-1.5">- <Skeleton className="h-3 w-full" />- <Skeleton className="h-3 w-2/5" />+ <div className="flex h-4 items-center">+ <Skeleton className="h-3 w-full" />+ </div>+ <div className="flex h-4 items-center">+ <Skeleton className="h-3 w-2/5" />+ </div></div></div></div>);-type CardSkeletonProps = { rows: number; hasAction?: boolean };--const CardSkeleton = ({ rows, hasAction = true }: CardSkeletonProps) => (+const CardSkeleton = ({ rows, hasAction = true }: { rows: string[]; hasAction?: boolean }) => (<Card className="h-full"><CardHeader><CardTitle>- <Skeleton className="h-4 w-32" />+ <div className="flex h-5 items-center">+ <Skeleton className="h-3.5 w-32" />+ </div></CardTitle>{hasAction && (<CardAction>@@ -47,8 +58,8 @@ const CardSkeleton = ({ rows, hasAction = true }: CardSkeletonProps) => ()}</CardHeader><CardContent className="flex flex-col gap-3">- {Array.from({ length: rows }, (_, i) => i).map((row) => (- <div key={row} className="flex items-center justify-between gap-4">+ {rows.map((row) => (+ <div key={row} className="flex h-5 items-center justify-between gap-4"><Skeleton className="h-3 w-40" /><Skeleton className="h-3 w-20" /></div>@@ -61,10 +72,10 @@ export const BillingSectionSkeleton = () => (<><div className="@container"><div className="grid gap-4 @3xl:grid-cols-[2fr_3fr]">- <CardSkeleton rows={2} />- <CardSkeleton rows={3} />+ <CardSkeleton rows={DETAIL_ROWS.slice(0, 2)} />+ <CardSkeleton rows={DETAIL_ROWS} /></div></div>- <CardSkeleton rows={3} hasAction={false} />+ <CardSkeleton rows={DETAIL_ROWS} hasAction={false} /></>);