fix: limits & server creation page

This commit is contained in:
Andras Bacsai 2023-08-21 10:18:11 +02:00
parent 7e37068fc0
commit b7ec1d7d65
5 changed files with 20 additions and 7 deletions

View File

@ -20,8 +20,8 @@ public function new_server()
} }
$servers = auth()->user()->currentTeam()->servers->count(); $servers = auth()->user()->currentTeam()->servers->count();
$subscription = auth()->user()->currentTeam()?->subscription->type(); $subscription = auth()->user()->currentTeam()?->subscription->type();
$limits = config('constants.limits.server')[strtolower($subscription)]; $your_limit = config('constants.limits.server')[strtolower($subscription)];
$limit_reached = true ?? $servers >= $limits[$subscription]; $limit_reached = $servers >= $your_limit;
return view('server.create', [ return view('server.create', [
'limit_reached' => $limit_reached, 'limit_reached' => $limit_reached,

View File

@ -46,6 +46,6 @@ public function set_destination(string $destination_uuid)
public function load_servers() public function load_servers()
{ {
$this->servers = Server::ownedByCurrentTeam()->get(); $this->servers = Server::isUsable()->get();
} }
} }

View File

@ -33,8 +33,9 @@ static public function isReachable()
static public function ownedByCurrentTeam(array $select = ['*']) static public function ownedByCurrentTeam(array $select = ['*'])
{ {
$teamId = auth()->user()->currentTeam()->id;
$selectArray = collect($select)->concat(['id']); $selectArray = collect($select)->concat(['id']);
return Server::whereTeamId(auth()->user()->currentTeam()->id)->with('settings')->select($selectArray->all())->orderBy('name'); return Server::whereTeamId($teamId)->with('settings')->select($selectArray->all())->orderBy('name');
} }
static public function isUsable() static public function isUsable()

View File

@ -80,7 +80,7 @@
<li class="step">Select a Destination</li> <li class="step">Select a Destination</li>
</ul> </ul>
<div class="flex flex-col justify-center gap-2 text-left xl:flex-row"> <div class="flex flex-col justify-center gap-2 text-left xl:flex-row">
@foreach ($servers as $server) @forelse($servers as $server)
<div class="gap-2 py-4 cursor-pointer group hover:bg-coollabs bg-coolgray-200" <div class="gap-2 py-4 cursor-pointer group hover:bg-coollabs bg-coolgray-200"
wire:click="set_server({{ $server }})"> wire:click="set_server({{ $server }})">
<div class="flex flex-col mx-6"> <div class="flex flex-col mx-6">
@ -91,7 +91,15 @@
{{ $server->description }}</div> {{ $server->description }}</div>
</div> </div>
</div> </div>
@endforeach @empty
<div>
<div>No validated & reachable servers found. <a class="text-white underline" href="/servers">
Go to servers page
</a></div>
<x-use-magic-bar link="/server/new" />
</div>
@endforelse
</div> </div>
@endif @endif
@if ($current_step === 'destinations') @if ($current_step === 'destinations')

View File

@ -1,5 +1,9 @@
<x-layout> <x-layout>
<h1>Servers</span></h1> <div class="flex items-start gap-2">
<h1>Servers</h1>
<a class="text-white hover:no-underline" href="/server/new"> <x-forms.button class="btn">+ Add
</x-forms.button></a>
</div>
<div class="subtitle ">All Servers</div> <div class="subtitle ">All Servers</div>
<div class="grid gap-2 lg:grid-cols-2"> <div class="grid gap-2 lg:grid-cols-2">
@forelse ($servers as $server) @forelse ($servers as $server)