2026-03-31 00:18:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\User;
|
|
|
|
|
|
|
|
|
|
use App\Enums\User\Setup;
|
2026-03-31 03:40:18 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-04-15 01:22:04 +00:00
|
|
|
use App\Models\Account;
|
2026-03-31 00:18:07 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
class CreateUser
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @param array{name: string, email: string, password?: string, timezone?: string, setup?: Setup, email_verified_at?: \DateTimeInterface|null} $data
|
|
|
|
|
*/
|
|
|
|
|
public static function execute(array $data): User
|
|
|
|
|
{
|
|
|
|
|
return DB::transaction(function () use ($data): User {
|
|
|
|
|
$isInviteRegistration = data_get($data, 'is_invite', false);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$account = Account::create([
|
|
|
|
|
'name' => data_get($data, 'name')."'s Account",
|
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 03:33:38 +00:00
|
|
|
'billing_email' => data_get($data, 'email'),
|
2026-04-15 01:22:04 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-31 00:18:07 +00:00
|
|
|
$user = User::create([
|
|
|
|
|
'name' => data_get($data, 'name'),
|
|
|
|
|
'email' => data_get($data, 'email'),
|
|
|
|
|
'password' => data_get($data, 'password'),
|
|
|
|
|
'setup' => data_get($data, 'setup', $isInviteRegistration ? Setup::Completed : Setup::Role),
|
|
|
|
|
'email_verified_at' => data_get($data, 'email_verified_at', $isInviteRegistration ? now() : null),
|
2026-04-15 01:22:04 +00:00
|
|
|
'account_id' => $account->id,
|
2026-03-31 00:18:07 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$account->update(['owner_id' => $user->id]);
|
|
|
|
|
|
2026-03-31 00:18:07 +00:00
|
|
|
$workspace = Workspace::create([
|
2026-04-15 01:22:04 +00:00
|
|
|
'account_id' => $account->id,
|
2026-03-31 00:18:07 +00:00
|
|
|
'user_id' => $user->id,
|
|
|
|
|
'name' => $user->name."'s Workspace",
|
|
|
|
|
'timezone' => data_get($data, 'timezone', 'UTC'),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
|
2026-03-31 00:18:07 +00:00
|
|
|
|
|
|
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|