feat(server): add dedicated server creation flow

This commit is contained in:
Andras Bacsai committed 2026-07-08 12:20:56 +02:00
1 parent 18f0f7f6be
commit 7236cb8228
31 files changed
+1158 -352

No files matched your search

+54 -8
View File
@@ -33,6 +33,8 @@ class ByDigitalOcean extends Component
public ?int $selected_token_id = null;
public ?string $selectedTokenUuid = null;
public array $regions = [];
public array $images = [];
@@ -74,11 +76,12 @@ class ByDigitalOcean extends Component
public bool $from_onboarding = false;
public function mount()
public function mount(?string $selectedTokenUuid = null)
{
try {
$this->authorize('viewAny', CloudProviderToken::class);
$this->loadTokens();
$this->selectTokenFromUrl($selectedTokenUuid);
$this->loadSavedCloudInitScripts();
$this->server_name = generate_random_name();
$this->private_keys = PrivateKey::ownedAndOnlySShKeys()->where('id', '!=', 0)->get();
@@ -86,6 +89,11 @@ class ByDigitalOcean extends Component
if ($this->private_keys->count() > 0) {
$this->private_key_id = $this->private_keys->first()->id;
}
if ($this->selectedTokenUuid) {
$this->current_step = 2;
$this->loading_data = true;
}
} catch (\Throwable $e) {
return handleError($e, $this);
}
@@ -174,9 +182,27 @@ class ByDigitalOcean extends Component
];
}
public function selectToken(int $tokenId): void
public function selectToken(int $tokenId): mixed
{
$this->selected_token_id = $tokenId;
return $this->nextStep();
}
private function selectTokenFromUrl(?string $selectedTokenUuid): void
{
if (! $selectedTokenUuid) {
return;
}
$token = $this->available_tokens->firstWhere('uuid', $selectedTokenUuid);
if (! $token) {
return;
}
$this->selectedTokenUuid = $selectedTokenUuid;
$this->selected_token_id = $token->id;
}
private function getDigitalOceanToken(): string
@@ -197,26 +223,46 @@ class ByDigitalOcean extends Component
]);
try {
$digitalOceanToken = $this->getDigitalOceanToken();
if (! $this->selectedTokenUuid) {
$token = $this->available_tokens->firstWhere('id', $this->selected_token_id);
if (! $digitalOceanToken) {
return $this->dispatch('error', 'Please select a valid DigitalOcean token.');
if ($token) {
return $this->redirectRoute('server.create.token', [
'type' => 'digital-ocean',
'token_uuid' => $token->uuid,
], navigate: true);
}
}
$this->loadDigitalOceanData($digitalOceanToken);
$this->current_step = 2;
$this->loading_data = true;
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function previousStep(): void
public function previousStep(): mixed
{
if ($this->selectedTokenUuid) {
return $this->redirectRoute('server.create.type', ['type' => 'digital-ocean'], navigate: true);
}
$this->current_step = 1;
return null;
}
private function loadDigitalOceanData(string $token): void
public function loadDigitalOceanData(): void
{
$token = $this->getDigitalOceanToken();
if (! $token) {
$this->loading_data = false;
$this->dispatch('error', 'Please select a valid DigitalOcean token.');
return;
}
$this->loading_data = true;
try {