trypost/app/Http/Controllers/App/Settings/UsageController.php
Paulo Castellano ded1c998ec feat: redesign billing, onboarding, sidebar, and settings architecture
- Sidebar reorganized: Workspace group (connections, hashtags, labels,
  API keys, settings) and Account group (settings, usage, billing)
- Account group only visible to owner and hidden in self-hosted mode
- Onboarding simplified: role -> account (connect socials) -> completed
  -> redirect to /subscribe. Removed Subscription setup step.
- Subscribe page redesigned with 4 plan cards, monthly/yearly toggle,
  trial info, and per-plan features list
- Billing page redesigned following Sendkit layout (sections with
  sidebar labels)
- Processing page uses usePoll with immediate watch for subscription
  activation
- Cancel URL redirects directly to /subscribe
- Account settings page with name and billing_email (syncs with Stripe)
- Usage page with ring meters for all plan limits
- Settings layout tabs only for user pages (profile, password,
  notifications). Workspace/API keys/billing are standalone pages.
- GoogleAuthButton extracted as reusable component
- WorkspaceRole TypeScript enum for type-safe role checks in frontend
- Trial period changed to 7 days
- Fixed onboarding loop when user confirms email
- All 1101 tests passing
2026-04-15 00:33:38 -03:00

52 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\App\Settings;
use App\Features\AiImagesLimit;
use App\Features\AiVideosLimit;
use App\Features\DataRetentionDays;
use App\Features\MemberLimit;
use App\Features\SocialAccountLimit;
use App\Features\WorkspaceLimit;
use App\Http\Controllers\App\Controller;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Laravel\Pennant\Feature;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
class UsageController extends Controller
{
public function index(Request $request): Response
{
abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);
$account = $request->user()->account;
$totalSocialAccounts = 0;
$totalMembers = $account->users()->count();
foreach ($account->workspaces as $workspace) {
$totalSocialAccounts += $workspace->socialAccounts()->count();
}
return Inertia::render('settings/Usage', [
'plan' => $account->plan,
'usage' => [
'workspaceCount' => $account->workspaces()->count(),
'workspaceLimit' => Feature::for($account)->value(WorkspaceLimit::class),
'socialAccountCount' => $totalSocialAccounts,
'socialAccountLimit' => Feature::for($account)->value(SocialAccountLimit::class),
'memberCount' => $totalMembers,
'memberLimit' => Feature::for($account)->value(MemberLimit::class),
'aiImagesUsed' => 0,
'aiImagesLimit' => Feature::for($account)->value(AiImagesLimit::class),
'aiVideosUsed' => 0,
'aiVideosLimit' => Feature::for($account)->value(AiVideosLimit::class),
'dataRetentionDays' => Feature::for($account)->value(DataRetentionDays::class),
],
]);
}
}