fix: yearly billing interval display in UpgradeDialog and Billing page
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.
This commit is contained in:
parent
aadfe7d6e8
commit
dad4ab21c3
4 changed files with 20 additions and 17 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<Plan[]>(() => (page.props.plans as Plan[]) ?? []);
|
||||
const currentPlan = computed<Plan | null>(() => (page.props.auth as { plan: Plan | null }).plan ?? null);
|
||||
const currentPriceId = computed<string | null>(() => (page.props.auth as { currentPriceId?: string | null }).currentPriceId ?? null);
|
||||
const currentPlan = computed<AuthPlan | null>(() => (page.props.auth as { plan: AuthPlan | null }).plan ?? null);
|
||||
const hasActiveSubscription = computed<boolean>(() => 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<string | null>(null);
|
||||
|
||||
watch(open, (isOpen) => {
|
||||
if (isOpen) {
|
||||
isYearly.value = isOnYearly.value;
|
||||
isYearly.value = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -175,8 +172,8 @@ const onOpenChange = (value: boolean) => {
|
|||
</DialogDescription>
|
||||
</div>
|
||||
|
||||
<!-- Billing toggle pill (hidden when user is already on yearly) -->
|
||||
<div v-if="!isOnYearly" class="flex justify-center pt-6 pb-2">
|
||||
<!-- Billing toggle pill -->
|
||||
<div class="flex justify-center pt-6 pb-2">
|
||||
<div class="relative">
|
||||
<div
|
||||
class="inline-flex items-center gap-1 rounded-full border-2 border-foreground bg-card p-1 shadow-xs"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
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<AuthPlan | null>(() => (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();
|
|||
<Badge v-else-if="subscription?.ends_at" variant="secondary">{{ $t('billing.plan.cancelling') }}</Badge>
|
||||
</div>
|
||||
<p class="text-base text-foreground/70">
|
||||
<span class="text-2xl font-bold tabular-nums text-foreground">{{ monthlyPrice(plan?.slug) }}</span>
|
||||
<span class="text-2xl font-bold tabular-nums text-foreground">{{ displayPrice(plan?.slug) }}</span>
|
||||
<span class="ml-1">/{{ $t('billing.plan.month') }}</span>
|
||||
</p>
|
||||
<p v-if="plan" class="text-xs font-medium text-foreground/60">
|
||||
{{ isYearly ? $t('billing.subscribe.billed_yearly') : $t('billing.subscribe.billed_monthly') }}
|
||||
</p>
|
||||
<p
|
||||
v-if="onTrial && trialEndsAt"
|
||||
class="text-sm font-semibold text-foreground/70"
|
||||
|
|
|
|||
1
resources/js/types/index.d.ts
vendored
1
resources/js/types/index.d.ts
vendored
|
|
@ -32,7 +32,6 @@ export interface Auth {
|
|||
account: AuthAccount | null;
|
||||
plan: AuthPlan | null;
|
||||
hasActiveSubscription: boolean;
|
||||
currentPriceId: string | null;
|
||||
}
|
||||
|
||||
export interface Usage {
|
||||
|
|
|
|||
Loading…
Reference in a new issue