From 6817f0c9fad2ffb969460ec356c29c683dd51343 Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Fri, 20 Feb 2026 17:50:46 +0100 Subject: [PATCH] fix: streamline invoice preview logic in OrganizationSettings to improve performance and user feedback during plan changes --- components/settings/OrganizationSettings.tsx | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/components/settings/OrganizationSettings.tsx b/components/settings/OrganizationSettings.tsx index 4e5aaa7..fea995c 100644 --- a/components/settings/OrganizationSettings.tsx +++ b/components/settings/OrganizationSettings.tsx @@ -298,6 +298,24 @@ export default function OrganizationSettings() { } }, [activeTab, user?.role, handleTabChange]) + const hasActiveSubscription = subscription?.subscription_status === 'active' || subscription?.subscription_status === 'trialing' + + useEffect(() => { + if (!showChangePlanModal || !hasActiveSubscription) { + setInvoicePreview(null) + return + } + let cancelled = false + setIsLoadingPreview(true) + setInvoicePreview(null) + const interval = changePlanYearly ? 'year' : 'month' + const limit = getLimitForTierIndex(changePlanTierIndex) + previewInvoice({ plan_id: changePlanId, interval, limit }) + .then((res) => { if (!cancelled) setInvoicePreview(res ?? null) }) + .finally(() => { if (!cancelled) setIsLoadingPreview(false) }) + return () => { cancelled = true } + }, [showChangePlanModal, hasActiveSubscription, changePlanId, changePlanTierIndex, changePlanYearly]) + // If no org ID, we are in personal organization context, so don't show org settings if (!currentOrgId) { return ( @@ -362,24 +380,6 @@ export default function OrganizationSettings() { setShowChangePlanModal(true) } - const hasActiveSubscription = subscription?.subscription_status === 'active' || subscription?.subscription_status === 'trialing' - - useEffect(() => { - if (!showChangePlanModal || !hasActiveSubscription) { - setInvoicePreview(null) - return - } - let cancelled = false - setIsLoadingPreview(true) - setInvoicePreview(null) - const interval = changePlanYearly ? 'year' : 'month' - const limit = getLimitForTierIndex(changePlanTierIndex) - previewInvoice({ plan_id: changePlanId, interval, limit }) - .then((res) => { if (!cancelled) setInvoicePreview(res ?? null) }) - .finally(() => { if (!cancelled) setIsLoadingPreview(false) }) - return () => { cancelled = true } - }, [showChangePlanModal, hasActiveSubscription, changePlanId, changePlanTierIndex, changePlanYearly]) - const handleChangePlanSubmit = async () => { const interval = changePlanYearly ? 'year' : 'month' const limit = getLimitForTierIndex(changePlanTierIndex)