From dad4ab21c316087417284f2d06c40000d6a5dca1 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Thu, 7 May 2026 11:35:28 -0300 Subject: [PATCH] fix: yearly billing interval display in UpgradeDialog and Billing page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UpgradeDialog was reading 'currentPlan.stripe_yearly_price_id' from 'auth.plan', but auth.plan is built by AuthPlanResource which only exposes {id, slug, name, interval} — the price ids are absent. The 'isOnYearly' computation always compared against undefined and returned false, so users on a yearly subscription saw the dialog as if they were on monthly: no current-plan badge match, the toggle was forced visible, and the wrong price/billing label was shown. Switches both UpgradeDialog and the Billing settings page to read auth.plan.interval directly (the authoritative field already present in shared props), drops the now-unused 'currentPriceId' from the Inertia middleware and the Auth type. Yearly is now the default selection on dialog open and the toggle stays visible regardless of current cadence. --- .../Middleware/App/HandleInertiaRequests.php | 2 -- resources/js/components/UpgradeDialog.vue | 17 +++++++---------- resources/js/pages/settings/account/Billing.vue | 17 +++++++++++++---- resources/js/types/index.d.ts | 1 - 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/Http/Middleware/App/HandleInertiaRequests.php b/app/Http/Middleware/App/HandleInertiaRequests.php index 1ffcb50f..f17aa60e 100644 --- a/app/Http/Middleware/App/HandleInertiaRequests.php +++ b/app/Http/Middleware/App/HandleInertiaRequests.php @@ -8,7 +8,6 @@ use App\Http\Resources\App\HandleInertiaRequests\AuthPlanResource; use App\Http\Resources\App\HandleInertiaRequests\AuthUserResource; use App\Http\Resources\App\HandleInertiaRequests\AuthWorkspaceResource; -use App\Models\Account; use App\Models\Plan; use Illuminate\Http\Request; use Inertia\Middleware; @@ -45,7 +44,6 @@ public function share(Request $request): array 'account' => $account ? AuthAccountResource::make($account) : null, 'plan' => $account && $account->plan ? AuthPlanResource::make($account, $account->plan) : null, 'hasActiveSubscription' => $account ? $account->hasActiveSubscription() : false, - 'currentPriceId' => $account?->subscription(Account::SUBSCRIPTION_NAME)?->stripe_price, ], 'usage' => $account && ! $isSelfHosted ? $account->usage() : null, 'features' => $account && ! $isSelfHosted ? $account->featureLimits() : null, diff --git a/resources/js/components/UpgradeDialog.vue b/resources/js/components/UpgradeDialog.vue index e5ca83f4..b23dc1a8 100644 --- a/resources/js/components/UpgradeDialog.vue +++ b/resources/js/components/UpgradeDialog.vue @@ -9,6 +9,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/comp import { useFeatureAccess } from '@/composables/useFeatureAccess'; import { useUpgradeDialog } from '@/composables/useUpgradeDialog'; import { checkout, swap } from '@/routes/app/billing'; +import type { AuthPlan } from '@/types'; type PlanSlug = 'starter' | 'plus' | 'pro' | 'max'; @@ -34,21 +35,17 @@ const { usage } = useFeatureAccess(); const page = usePage(); const plans = computed(() => (page.props.plans as Plan[]) ?? []); -const currentPlan = computed(() => (page.props.auth as { plan: Plan | null }).plan ?? null); -const currentPriceId = computed(() => (page.props.auth as { currentPriceId?: string | null }).currentPriceId ?? null); +const currentPlan = computed(() => (page.props.auth as { plan: AuthPlan | null }).plan ?? null); const hasActiveSubscription = computed(() => Boolean((page.props.auth as { hasActiveSubscription?: boolean }).hasActiveSubscription)); -const isOnYearly = computed(() => { - if (!currentPriceId.value || !currentPlan.value) return false; - return currentPriceId.value === currentPlan.value.stripe_yearly_price_id; -}); +const isOnYearly = computed(() => currentPlan.value?.interval === 'yearly'); -const isYearly = ref(false); +const isYearly = ref(true); const processing = ref(null); watch(open, (isOpen) => { if (isOpen) { - isYearly.value = isOnYearly.value; + isYearly.value = true; } }); @@ -175,8 +172,8 @@ const onOpenChange = (value: boolean) => { - -
+ +
-import { Head } from '@inertiajs/vue3'; +import { Head, usePage } from '@inertiajs/vue3'; import { IconCreditCard, IconDownload, IconFileText, IconSparkles } from '@tabler/icons-vue'; import { trans } from 'laravel-vue-i18n'; import { computed } from 'vue'; @@ -16,6 +16,7 @@ import { settings as settingsHub } from '@/routes/app'; import { edit as accountEdit } from '@/routes/app/account'; import { index as billingIndex, portal } from '@/routes/app/billing'; import { index as usageIndex } from '@/routes/app/usage'; +import type { AuthPlan } from '@/types'; interface Plan { name: string; @@ -59,9 +60,14 @@ const tabs = computed(() => [ { name: 'billing', label: trans('settings.account.tabs.billing'), href: billingIndex().url }, ]); -const monthlyPrice = (slug: string | undefined): string => { +const page = usePage(); +const authPlan = computed(() => (page.props.auth as { plan: AuthPlan | null }).plan ?? null); +const isYearly = computed(() => authPlan.value?.interval === 'yearly'); + +const displayPrice = (slug: string | undefined): string => { if (! slug) return 'Free'; - return trans(`billing.subscribe.prices.${slug}.monthly`); + const key = isYearly.value ? 'yearly_per_month' : 'monthly'; + return trans(`billing.subscribe.prices.${slug}.${key}`); }; const { openUpgrade } = useUpgradeDialog(); @@ -106,9 +112,12 @@ const { openUpgrade } = useUpgradeDialog(); {{ $t('billing.plan.cancelling') }}

- {{ monthlyPrice(plan?.slug) }} + {{ displayPrice(plan?.slug) }} /{{ $t('billing.plan.month') }}

+

+ {{ isYearly ? $t('billing.subscribe.billed_yearly') : $t('billing.subscribe.billed_monthly') }} +