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
refactor(billing): remove useHeldLoading hook and simplify loading state management
Victor Hugo dos Santoscba5a1149d2d
diff --git a/frontend/src/hooks/index.ts b/frontend/src/hooks/index.tsindex aa686a9b25..fa9e8d630e 100644--- a/frontend/src/hooks/index.ts+++ b/frontend/src/hooks/index.ts@@ -6,7 +6,6 @@ export { useDebounce } from "./useDebounce";export { useDelayedLoading } from "./useDelayedLoading";export { useDiscardChangesGuard } from "./useDiscardChangesGuard";export * from "./useGetProjectTypeFromRoute";-export { useHeldLoading } from "./useHeldLoading";export { useImplicitProduct } from "./useImplicitProduct";export { useImplicitProjectId } from "./useImplicitProjectId";export { useLastLogin } from "./useLastLogin";diff --git a/frontend/src/hooks/useHeldLoading.ts b/frontend/src/hooks/useHeldLoading.tsdeleted file mode 100644index 30eaa0c3af..0000000000--- a/frontend/src/hooks/useHeldLoading.ts+++ /dev/null@@ -1,28 +0,0 @@-import { useEffect, useRef, useState } from "react";--// Holds a loading flag on screen for a legible minimum. A cached or local answer can arrive faster-// than a skeleton can be read, which makes a reload look like a flicker rather than a reload; a-// request slower than the minimum is unaffected.-export const useHeldLoading = (isLoading: boolean, minMs = 500) => {- const [isHeld, setIsHeld] = useState(isLoading);- const startedAt = useRef(Date.now());-- useEffect(() => {- if (isLoading) {- startedAt.current = Date.now();- setIsHeld(true);- return undefined;- }-- const remaining = minMs - (Date.now() - startedAt.current);- if (remaining <= 0) {- setIsHeld(false);- return undefined;- }-- const timer = setTimeout(() => setIsHeld(false), remaining);- return () => clearTimeout(timer);- }, [isLoading, minMs]);-- return isLoading || isHeld;-};diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsxindex a56107ea2d..674a8864e9 100644--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx@@ -12,7 +12,7 @@ import {useOrgPermission} from "@app/context";import { isInfisicalCloud } from "@app/helpers/platform";-import { useDebounce, useHeldLoading } from "@app/hooks";+import { useDebounce } from "@app/hooks";import {BillingV2BreakdownScopeKind,useAddBillingV2PaymentMethod,@@ -170,7 +170,7 @@ export const BillingV2Page = () => {const isViewingOtherOrg = selectedOrgId !== orgId;const canManageBilling = hasManageBillingPermission && !isViewingOtherOrg;- const isReloading = useHeldLoading(isPlaceholderData && !isError);+ const isReloading = isPlaceholderData && !isError;let subState: BillingV2RenderState = "loading";if (isError) {diff --git a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsxindex 194c3f5494..c29d3cf8c7 100644--- a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx@@ -29,7 +29,6 @@ import {TabsTrigger} from "@app/components/v3";import { cn } from "@app/components/v3/utils";-import { useHeldLoading } from "@app/hooks";import {BillingV2BreakdownDimension,BillingV2BreakdownScope,@@ -98,7 +97,6 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowPconst orgLevelTint = "bg-neutral/85";const canExpand = hasProjectDetail && scope.count > 0;const ScopeIcon = scope.isRoot ? OrgIcon : SubOrgIcon;- const projectLabel = `${scope.projects.length} ${scope.projects.length === 1 ? "project" : "projects"}`;const header = (<div className="flex min-w-0 flex-1 flex-col gap-2">@@ -156,9 +154,9 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowP</div>)}{scope.projects.length > 0 && (- <div className="flex items-center gap-2 border-t border-border pt-2.5">+ <div className="flex items-center justify-between gap-3 border-t border-border pt-2.5"><span className="text-2xs tracking-wide text-muted uppercase">Projects</span>- <span className="text-2xs text-muted">{projectLabel}</span>+ <span className="text-2xs text-muted tabular-nums">{scope.projects.length}</span></div>)}{scope.projects.map((project) => (@@ -472,7 +470,7 @@ export const UsageBreakdownSheet = ({isPending,isError} = useGetBillingV2UsageBreakdown(orgId, dimensionKey, scope);- const isLoading = useHeldLoading(isPending && Boolean(dimensionKey));+ const isLoading = isPending && Boolean(dimensionKey);return (<Sheet open onOpenChange={(open) => !open && onClose()}>@@ -523,9 +521,7 @@ export const UsageBreakdownSheet = ({</Empty>)}- {breakdown && !isError && !isLoading && (- <BreakdownBody breakdown={breakdown} scopeKind={scope} />- )}+ {breakdown && !isError && <BreakdownBody breakdown={breakdown} scopeKind={scope} />}</div><SheetFooter className="flex-row items-center justify-end border-t">