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') }} +