From c2ffe884979e688aebeacca04f4b4ef9648cb00d Mon Sep 17 00:00:00 2001 From: Ayush Rodrigues Date: Sat, 28 Feb 2026 18:54:32 +0000 Subject: [PATCH] fix org caching when switching orgs and envs --- shared/utils/productDisplayUtils.ts | 3 +-- vite/src/views/auth/Consent.tsx | 3 ++- vite/src/views/main-sidebar/EnvDropdown.tsx | 2 ++ vite/src/views/main-sidebar/components/OrgDropdown.tsx | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/shared/utils/productDisplayUtils.ts b/shared/utils/productDisplayUtils.ts index 94768e850..956262a59 100644 --- a/shared/utils/productDisplayUtils.ts +++ b/shared/utils/productDisplayUtils.ts @@ -120,8 +120,7 @@ export const getFeatureItemDisplay = ({ const intervalDisplay = getIntervalDisplay(item); if (intervalDisplay) { secondaryText = intervalDisplay; - } else if (isSingleUseFeature(feature)) { - // Only show "one-off" for single-use features, not continuous use + } else if (isSingleUseFeature(feature) && item.included_usage !== Infinite) { secondaryText = "one-off"; } } diff --git a/vite/src/views/auth/Consent.tsx b/vite/src/views/auth/Consent.tsx index 132a6af63..d3a839423 100644 --- a/vite/src/views/auth/Consent.tsx +++ b/vite/src/views/auth/Consent.tsx @@ -1,4 +1,5 @@ import { type GroupedPermission, groupAndFormatScopes } from "@autumn/shared"; +import { clearOrgCache } from "@/hooks/common/useOrg"; import { Check, ChevronDown, @@ -146,7 +147,7 @@ export const Consent = () => { await authClient.organization.setActive({ organizationId: orgId, }); - // Reload to refresh the page with new org context + clearOrgCache(); window.location.reload(); } catch (_) { toast.error("Failed to switch organization"); diff --git a/vite/src/views/main-sidebar/EnvDropdown.tsx b/vite/src/views/main-sidebar/EnvDropdown.tsx index 91c73417e..90c11c2cd 100644 --- a/vite/src/views/main-sidebar/EnvDropdown.tsx +++ b/vite/src/views/main-sidebar/EnvDropdown.tsx @@ -12,6 +12,7 @@ import { DropdownMenuContent, DropdownMenuItem, } from "@/components/ui/dropdown-menu"; +import { clearOrgCache } from "@/hooks/common/useOrg"; import { cn } from "@/lib/utils"; import { envToPath } from "@/utils/genUtils"; import { ExpandedEnvTrigger } from "./env-dropdown/ExpandedEnvTrigger"; @@ -23,6 +24,7 @@ export const useEnvChange = () => { const handleEnvChange = (targetEnv: AppEnv, reset?: boolean) => { // Clear all cached query data so it refetches for the new env queryClient.clear(); + clearOrgCache(); // Calculate the new path const newPath = envToPath(targetEnv, location.pathname); diff --git a/vite/src/views/main-sidebar/components/OrgDropdown.tsx b/vite/src/views/main-sidebar/components/OrgDropdown.tsx index c8d0f4b38..c5f3ed536 100644 --- a/vite/src/views/main-sidebar/components/OrgDropdown.tsx +++ b/vite/src/views/main-sidebar/components/OrgDropdown.tsx @@ -26,7 +26,7 @@ import { } from "@/components/ui/dropdown-menu"; import { Skeleton } from "@/components/ui/skeleton"; import { useTheme } from "@/contexts/ThemeProvider"; -import { useOrg } from "@/hooks/common/useOrg"; +import { clearOrgCache, useOrg } from "@/hooks/common/useOrg"; import { authClient, useListOrganizations, @@ -247,6 +247,7 @@ export const handleSwitchOrg = async ( organizationId: orgId, }); + clearOrgCache(); window.location.reload(); } catch (error: any) { toast.error(error.message);