public static function getManageWorkspaceLink(): Action { return Action::make('manage_workspace') ->label('Manage workspace') ->icon(Heroicon::OutlinedCog6Tooth) ->modal() ->modalHeading(fn (): string => Filament::getTenant()->workspace->name) ->modalSubmitActionLabel('Save') ->schema([ TextInput::make('name') ->label('Name') ->default(fn (): string => Filament::getTenant()->workspace->name) ->required() ->maxLength(255) ->columnSpanFull() ->helperText('The name of the workspace'), Repeater::make('organizations') ->addable(fn (): bool => auth()->user()->is_admin) ->deletable(false) ->reorderable(false) ->default(fn (): array => auth()->user() ->organizations ->map(fn (Organization $organization): array => [ 'id' => $organization->id, 'name' => $organization->name, ] ) ->toArray() ) ->table([ TableColumn::make('Organization') ->alignLeft(), ]) ->schema([ TextEntry::make('name') ->disableLabel(), ]) ->extraItemActions([ Action::make('switch') ->label('Switch') ->icon(Heroicon::OutlinedArrowRightEndOnRectangle) ->color('primary') ->size(Size::Large) ->tooltip(fn (): string => 'Switch to organization') ->action(function (array $arguments, Repeater $component) { $rowIndex = $arguments['item']; // Get the id of the row whose action was clicked in the table $allRows = $component->getState(); // Get all the table rows $organizationRow = $allRows[$rowIndex]; // Get the organization row's data we're looking for return redirect()->to(Filament::getCurrentPanel()->getUrl(Organization::findOrFail($organizationRow['id']))); }), ]) ->addActionAlignment(Alignment::Right) ->addActionLabel('Add organizations') ->addAction(fn (Action $action, Repeater $component): Action => $action ->label('Add organization') ->icon(Heroicon::OutlinedPlus) ->modal() ->modalSubmitActionLabel('Create') ->schema([ TextInput::make('name') ->label('Name') ->required() ->maxLength(255) ->columnSpanFull() ->helperText('The name of the organization'), ]) ->action(function (array $data) use ($component): void { /** * Create new organization in this workspace, assign active user to it * and update organizations list to display the new organization. */ $createdOrganization = Organization::create([ ...$data, 'workspace_id' => Filament::getTenant()->workspace->id, ]); $createdOrganization->users()->attach(auth()->user()->id, [ 'role' => OrganizationMembershipRole::ADMIN->value, ]); $organizations = $component->getState(); $organizations[] = [ 'id' => $createdOrganization->id, 'name' => $createdOrganization->name ]; $component->state($organizations); // Need to also update second repeater to display new organization in organizations_list computed property. }) ->successNotification(fn (): Notification => Notification::make() ->title('Created') ->body('The organization has been successfully created.') ->success() ) ), Repeater::make('team_members') ->deletable(false) ->reorderable(false) ->default(fn (): array => Filament::getTenant() ->workspace ->users ->map(function (User $teamMember): array { $you = auth()->user()->id === $teamMember->id ? '(you)' : ''; return [ 'id' => $teamMember->id, 'name' => "{$teamMember->name} {$you}", 'organizations' => $teamMember->organizations->isEmpty() ? 'No organizations' : $teamMember->organizations_list, ]; }) ->toArray() ) ->table([ TableColumn::make('Member') ->alignLeft(), TableColumn::make('Organizations') ->alignLeft(), ]) ->schema([ TextEntry::make('name') ->disableLabel(), TextEntry::make('organizations') ->disableLabel(), ]) ->extraItemActions([ Action::make('manage_member') ->label('Manage') ->icon(Heroicon::OutlinedCog6Tooth) ->color('primary') ->size(Size::Large) ->modal() ->modalHeading('Manage user') ->tooltip(fn (): string => 'Manage this user') ->action(function (array $arguments, Repeater $component): void { }), ]) ->addActionAlignment(Alignment::Right) ->addActionLabel('Invite') ->addAction(fn (Action $action, Repeater $component): Action => $action ->label('Invite') ->icon(Heroicon::OutlinedPlus) ->modal() ->modalSubmitActionLabel('Invite') ->schema([ TextInput::make('email') ->label('Name') ->required() ->maxLength(255) ->columnSpanFull() ->helperText('Invite user by entering their email'), ]) ->action(function (array $data) use ($component): void { /** * TODO: invite users to this workspace using their email. */ }) ->successNotification(fn (): Notification => Notification::make() ->title('Invited') ->body('The user has been invited to the workspace.') ->success() ) ), ]) ->action(function (array $data): void { $workspace = Filament::getTenant()->workspace; $workspace->update([ 'name' => $data['name'], ]); }) ->successNotification(fn (): Notification => Notification::make() ->title('Saved') ->body('The workspace settings have been updated.') ->success() ) ->visible(fn (): bool => auth()->user()->is_admin); }