get_public_key_content(), ]); return $form ->schema([ ProviderField::make('provider') ->label('Select a provider') ->default(ServerProvider::CUSTOM) ->live() ->reactive() ->reactive() ->afterStateUpdated(function (callable $set) { $set('server_provider', null); $set('region', null); $set('plan', null); }) ->rules(fn ($get) => CreateServerAction::rules($this->all())['provider']), AlertField::make('alert') ->warning() ->message(__('servers.create.public_key_warning')) ->visible(fn ($get) => $this->provider === ServerProvider::CUSTOM), Select::make('server_provider') ->visible(fn ($get) => $this->provider !== ServerProvider::CUSTOM) ->label('Server provider connection') ->rules(fn ($get) => CreateServerAction::rules($this->all())['server_provider']) ->options(function ($get) { return \App\Models\ServerProvider::getByProjectId(auth()->user()->current_project_id) ->where('provider', $this->provider) ->pluck('profile', 'id'); }) ->live() ->suffixAction( Action::make('connect') ->form(Create::form()) ->modalHeading('Connect to a new server provider') ->modalSubmitActionLabel('Connect') ->icon('heroicon-o-wifi') ->tooltip('Connect to a new server provider') ->modalWidth(MaxWidth::Medium) ->authorize(fn () => auth()->user()->can('create', \App\Models\ServerProvider::class)) // TODO: remove this after filament #14319 is fixed ->url(\App\Web\Pages\Settings\ServerProviders\Index::getUrl()) ->action(fn (array $data) => Create::action($data)) ) ->placeholder('Select profile') ->native(false) ->selectablePlaceholder(false) ->visible(fn ($get) => $this->provider !== ServerProvider::CUSTOM), Grid::make() ->schema([ Select::make('region') ->label('Region') ->rules(fn ($get) => CreateServerAction::rules($this->all())['region']) ->live() ->reactive() ->options(function () { if (! $this->server_provider) { return []; } return \App\Models\ServerProvider::regions($this->server_provider); }) ->loadingMessage('Loading regions...') ->disabled(fn ($get) => ! $this->server_provider) ->placeholder(fn ($get) => $this->server_provider ? 'Select region' : 'Select connection first') ->searchable(), Select::make('plan') ->label('Plan') ->rules(fn ($get) => CreateServerAction::rules($this->all())['plan']) ->reactive() ->options(function () { if (! $this->server_provider || ! $this->region) { return []; } return \App\Models\ServerProvider::plans($this->server_provider, $this->region); }) ->loadingMessage('Loading plans...') ->disabled(fn ($get) => ! $this->region) ->placeholder(fn ($get) => $this->region ? 'Select plan' : 'Select plan first') ->searchable(), ]) ->visible(fn ($get) => $this->provider !== ServerProvider::CUSTOM), TextInput::make('public_key') ->label('Public Key') ->default($publicKey) ->suffixAction( Action::make('copy') ->icon('heroicon-o-clipboard-document-list') ->tooltip('Copy') ->action(function ($livewire, $state) { $livewire->js( 'window.navigator.clipboard.writeText("'.$state.'");' ); Notification::make() ->success() ->title('Copied!') ->send(); }) ) ->helperText('Run this command on your server as root user') ->disabled() ->visible(fn ($get) => $this->provider === ServerProvider::CUSTOM), TextInput::make('name') ->label('Name') ->rules(fn ($get) => CreateServerAction::rules($this->all())['name']), Grid::make() ->schema([ TextInput::make('ip') ->label('SSH IP Address') ->rules(fn ($get) => CreateServerAction::rules($this->all())['ip']), TextInput::make('port') ->label('SSH Port') ->rules(fn ($get) => CreateServerAction::rules($this->all())['port']), ]) ->visible(fn ($get) => $this->provider === ServerProvider::CUSTOM), Grid::make() ->schema([ Select::make('os') ->label('OS') ->native(false) ->selectablePlaceholder(false) ->rules(fn ($get) => CreateServerAction::rules($this->all())['os']) ->options(function () { return collect(config('core.operating_systems')) ->mapWithKeys(fn ($value) => [$value => $value]); }), Select::make('type') ->label('Server Type') ->native(false) ->selectablePlaceholder(false) ->rules(fn ($get) => CreateServerAction::rules($this->all())['type']) ->options(function () { return collect(config('core.server_types')) ->mapWithKeys(fn ($value) => [$value => $value]); }) ->default(ServerType::REGULAR), ]), Grid::make(3) ->schema([ Select::make('webserver') ->label('Webserver') ->native(false) ->selectablePlaceholder(false) ->rules(fn ($get) => CreateServerAction::rules($this->all())['webserver'] ?? []) ->options(function () { return collect(config('core.webservers')) ->mapWithKeys(fn ($value) => [$value => $value]); }), Select::make('database') ->label('Database') ->native(false) ->selectablePlaceholder(false) ->rules(fn ($get) => CreateServerAction::rules($this->all())['database'] ?? []) ->options(function () { return collect(config('core.databases_name')) ->mapWithKeys(fn ($value, $key) => [ $key => $value.' '.config('core.databases_version')[$key], ]); }), Select::make('php') ->label('PHP') ->native(false) ->selectablePlaceholder(false) ->rules(fn ($get) => CreateServerAction::rules($this->all())['php'] ?? []) ->options(function () { return collect(config('core.php_versions')) ->mapWithKeys(fn ($value) => [$value => $value]); }), ]), Actions::make([ Action::make('create') ->label('Create Server') ->button() ->action(fn () => $this->submit()), ]), ]) ->columns(1); } public function submit(): void { $this->authorize('create', Server::class); $this->validate(); try { $server = app(CreateServerAction::class)->create(auth()->user(), $this->all()['data']); $this->redirect(Index::getUrl()); } catch (Throwable $e) { Notification::make() ->title($e->getMessage()) ->danger() ->send(); } } }