From f390776e11a521f7b7db055a027eaf09ee62453c Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Mon, 9 Feb 2026 15:06:45 +0100 Subject: [PATCH] refactor: update subscription cancellation state management in OrganizationSettings component --- components/settings/OrganizationSettings.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/components/settings/OrganizationSettings.tsx b/components/settings/OrganizationSettings.tsx index 526d21e..d2e1889 100644 --- a/components/settings/OrganizationSettings.tsx +++ b/components/settings/OrganizationSettings.tsx @@ -69,7 +69,7 @@ export default function OrganizationSettings() { const [subscription, setSubscription] = useState(null) const [isLoadingSubscription, setIsLoadingSubscription] = useState(false) const [isRedirectingToPortal, setIsRedirectingToPortal] = useState(false) - const [isCanceling, setIsCanceling] = useState(false) + const [cancelLoadingAction, setCancelLoadingAction] = useState<'period_end' | 'immediate' | null>(null) const [showCancelPrompt, setShowCancelPrompt] = useState(false) const [showChangePlanModal, setShowChangePlanModal] = useState(false) const [changePlanTierIndex, setChangePlanTierIndex] = useState(2) @@ -269,7 +269,7 @@ export default function OrganizationSettings() { } const handleCancelSubscription = async (atPeriodEnd: boolean) => { - setIsCanceling(true) + setCancelLoadingAction(atPeriodEnd ? 'period_end' : 'immediate') try { await cancelSubscription({ at_period_end: atPeriodEnd }) toast.success(atPeriodEnd ? 'Subscription will cancel at the end of the billing period.' : 'Subscription canceled.') @@ -278,12 +278,12 @@ export default function OrganizationSettings() { } catch (error: any) { toast.error(getAuthErrorMessage(error) || error.message || 'Failed to cancel subscription') } finally { - setIsCanceling(false) + setCancelLoadingAction(null) } } const openChangePlanModal = () => { - if (subscription?.pageview_limit) { + if (subscription?.pageview_limit != null && subscription.pageview_limit > 0) { setChangePlanTierIndex(getTierIndexForLimit(subscription.pageview_limit)) } else { setChangePlanTierIndex(2) @@ -1154,7 +1154,7 @@ export default function OrganizationSettings() { @@ -1165,8 +1165,8 @@ export default function OrganizationSettings() {
@@ -1174,11 +1174,12 @@ export default function OrganizationSettings() { variant="ghost" className="text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20" onClick={() => handleCancelSubscription(false)} - disabled={isCanceling} + disabled={cancelLoadingAction != null} + isLoading={cancelLoadingAction === 'immediate'} > Cancel immediately -