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.
67 lines
2.8 KiB
PHP
67 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware\App;
|
|
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthAccountResource;
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthPlanResource;
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthUserResource;
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthWorkspaceResource;
|
|
use App\Models\Plan;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Middleware;
|
|
|
|
class HandleInertiaRequests extends Middleware
|
|
{
|
|
protected $rootView = 'app';
|
|
|
|
public function version(Request $request): ?string
|
|
{
|
|
return parent::version($request);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function share(Request $request): array
|
|
{
|
|
$user = $request->user();
|
|
|
|
$currentWorkspace = $user?->currentWorkspace?->load('media');
|
|
$account = $user?->account;
|
|
$isSelfHosted = (bool) config('trypost.self_hosted');
|
|
|
|
return [
|
|
...parent::share($request),
|
|
'name' => config('app.name'),
|
|
'auth' => [
|
|
'user' => $user ? AuthUserResource::make($user) : null,
|
|
'currentWorkspace' => $currentWorkspace ? AuthWorkspaceResource::make($currentWorkspace, $user) : null,
|
|
'workspaces' => $user
|
|
? $user->workspaces()->with('media')->get()->map(fn ($ws) => AuthWorkspaceResource::summary($ws))
|
|
: [],
|
|
'account' => $account ? AuthAccountResource::make($account) : null,
|
|
'plan' => $account && $account->plan ? AuthPlanResource::make($account, $account->plan) : null,
|
|
'hasActiveSubscription' => $account ? $account->hasActiveSubscription() : false,
|
|
],
|
|
'usage' => $account && ! $isSelfHosted ? $account->usage() : null,
|
|
'features' => $account && ! $isSelfHosted ? $account->featureLimits() : null,
|
|
'plans' => $isSelfHosted ? [] : Plan::active()->orderBy('sort')->get(),
|
|
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
|
'flash' => $request->session()->get('flash', []),
|
|
'applicationUrl' => config('app.url'),
|
|
'env' => config('app.env'),
|
|
'locale' => app()->getLocale(),
|
|
'languages' => collect(config('languages.available'))->map(fn ($name, $code) => [
|
|
'code' => $code,
|
|
'name' => $name,
|
|
])->values()->all(),
|
|
'aiEnabled' => ! empty(config('services.gemini.api_key')) || ! empty(config('services.openai.api_key')),
|
|
'selfHosted' => $isSelfHosted,
|
|
'googleAuthEnabled' => config('trypost.google_auth_enabled'),
|
|
'githubAuthEnabled' => config('trypost.github_auth_enabled'),
|
|
'trialDays' => config('cashier.trial_days'),
|
|
];
|
|
}
|
|
}
|