2026-03-29 22:24:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Workspace;
|
|
|
|
|
|
2026-03-31 03:40:18 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-03-29 22:24:28 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
2026-06-22 12:26:31 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2026-03-29 22:24:28 +00:00
|
|
|
|
|
|
|
|
class CreateWorkspace
|
|
|
|
|
{
|
2026-04-17 02:05:51 +00:00
|
|
|
/**
|
|
|
|
|
* @param array<string, mixed> $data
|
|
|
|
|
*/
|
2026-03-29 22:24:28 +00:00
|
|
|
public static function execute(User $user, array $data): Workspace
|
|
|
|
|
{
|
2026-04-17 02:05:51 +00:00
|
|
|
$attributes = array_filter([
|
|
|
|
|
'name' => data_get($data, 'name'),
|
|
|
|
|
'brand_website' => data_get($data, 'brand_website'),
|
|
|
|
|
'brand_description' => data_get($data, 'brand_description'),
|
2026-06-12 20:09:39 +00:00
|
|
|
'brand_voice_traits' => data_get($data, 'brand_voice_traits'),
|
2026-05-02 16:30:59 +00:00
|
|
|
'brand_color' => data_get($data, 'brand_color'),
|
|
|
|
|
'background_color' => data_get($data, 'background_color'),
|
|
|
|
|
'text_color' => data_get($data, 'text_color'),
|
2026-07-01 16:49:48 +00:00
|
|
|
'content_language' => data_get($data, 'content_language', app()->getLocale()),
|
2026-04-17 02:05:51 +00:00
|
|
|
], static fn ($value): bool => $value !== null);
|
|
|
|
|
|
2026-06-22 12:26:31 +00:00
|
|
|
$workspace = DB::transaction(function () use ($user, $attributes): Workspace {
|
|
|
|
|
$workspace = Workspace::create([
|
|
|
|
|
...$attributes,
|
|
|
|
|
'account_id' => $user->account_id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
]);
|
2026-03-29 22:24:28 +00:00
|
|
|
|
2026-06-22 12:26:31 +00:00
|
|
|
// Creator becomes Admin of the workspace they made. The Account Owner
|
|
|
|
|
// is resolved separately (via account.owner_id) and outranks this role.
|
|
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Admin->value]);
|
|
|
|
|
$user->switchWorkspace($workspace);
|
|
|
|
|
|
|
|
|
|
return $workspace;
|
|
|
|
|
});
|
2026-03-29 22:24:28 +00:00
|
|
|
|
feat: per-workspace pricing, onboarding, and billing overhaul
Pricing
- Bill per workspace ($12/mo or $120/yr each); Stripe quantity tracks the
workspace count and syncs on workspace create/delete.
- 2,500 AI credits per workspace, pooled at the account level; monthly reset
on the billing anniversary, annual granted upfront (no rollover).
- One social account per network per workspace; remove all count-based limits
(workspace/social/member) and the legacy plan tiers (single Workspace plan).
Onboarding (cloud only: SELF_HOSTED=false + PostHog)
- Replace the /subscribe plan picker with /onboarding persona selection
(Creator/Freelancer/Startup/Agency/Small business/Other), saved on the user
(users.persona) and mirrored to PostHog, then Stripe Checkout on the monthly
price. 8-day trial so Stripe displays 7.
Billing screen
- Remove the Change Plan dialog (dead with a single plan); add an annual-upgrade
banner for monthly subscribers (swapToYearly).
- Current-plan card shows the workspace count instead of the plan name.
System AI
- Brand analyzer / workspace autofill is always allowed and never debits credits
(system feature, not the user's usage).
Self-hosted (SELF_HOSTED=true) bypasses all billing, credit, limit, network,
and onboarding logic.
2026-06-21 23:40:03 +00:00
|
|
|
$user->account?->syncWorkspaceQuantity();
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
return $workspace;
|
|
|
|
|
}
|
|
|
|
|
}
|