Skip to content

Commit

Permalink
feat: #68 replace jetstream dashboard with saas-related microdashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-shulha committed Aug 8, 2024
1 parent ba12db5 commit bc46fef
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 116 deletions.
18 changes: 18 additions & 0 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Controllers;

use Inertia\Inertia;

class DashboardController extends Controller
{
public function show()
{
$team = auth()->user()->currentTeam;

return Inertia::render('Dashboard', [
'nodesCount' => $team->nodes()->count(),
'servicesCount' => $team->services()->count(),
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/EnsureTeamSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function handle(Request $request, Closure $next): Response
$team = auth()->user()->currentTeam;
$subscription = $team->subscription();

$doesntHaveSubscription = $subscription === null || ! $subscription->onTrial() && ! $subscription->active();
$doesntHaveSubscription = $subscription === null || ! $subscription->valid();
if ($doesntHaveSubscription) {
return redirect()->route('teams.billing.show', $team);
}
Expand Down
7 changes: 6 additions & 1 deletion app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ protected static function booted()
});
}

protected function nodes(): HasMany
public function nodes(): HasMany
{
return $this->hasMany(Node::class);
}

public function services(): HasMany
{
return $this->hasMany(Service::class);
}

/**
* Get the name of the team.
*/
Expand Down
104 changes: 0 additions & 104 deletions resources/js/Components/Welcome.vue

This file was deleted.

23 changes: 18 additions & 5 deletions resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
<script setup>
import AppLayout from '@/Layouts/AppLayout.vue';
import Welcome from '@/Components/Welcome.vue';
import AppLayout from "@/Layouts/AppLayout.vue";
import ValueCard from "@/Components/ValueCard.vue";
const props = defineProps(["nodesCount", "servicesCount"]);
</script>

<template>
<AppLayout title="Dashboard">
<template #header>
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
<h2
class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight"
>
Dashboard
</h2>
</template>

<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-xl sm:rounded-lg">
<Welcome />
<div class="grid grid-cols-6 gap-4">
<ValueCard
class="bg-white py-2 px-4 rounded shadow text-right"
label="Nodes"
:value="nodesCount"
/>
<ValueCard
class="bg-white py-2 px-4 rounded shadow text-right"
label="Services"
:value="servicesCount"
/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Nodes/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ defineProps({
v-for="node in nodes"
:key="node.id"
:href="route('nodes.show', { node: node.id })"
class="bg-white dark:bg-gray-800 overflow-hidden shadow-xl sm:rounded-lg p-4 flex justify-around"
class="bg-white dark:bg-gray-800 overflow-hidden shadow sm:rounded-lg p-4 flex justify-around"
>
<div class="flex">
<div class="font-bold text-xl">{{ node.name }}</div>
Expand Down
6 changes: 2 additions & 4 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\DashboardController;
use App\Http\Controllers\NodeController;
use App\Http\Controllers\NodeTaskGroupController;
use App\Http\Controllers\RefundPolicyController;
Expand All @@ -9,7 +10,6 @@
use App\Http\Controllers\TeamBillingController;
use App\Http\Middleware\EnsureTeamSubscription;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;

Route::get('/', function () {
if (auth()->user()) {
Expand All @@ -36,9 +36,7 @@
Route::middleware([
EnsureTeamSubscription::class,
])->group(function () {
Route::get('/dashboard', function () {
return Inertia::render('Dashboard');
})->name('dashboard');
Route::get('/dashboard', [DashboardController::class, 'show'])->name('dashboard');

Route::post('/swarms/{swarm}/update-docker-registries', [SwarmController::class, 'updateDockerRegistries'])->name('swarms.update-docker-registries');
Route::post('/swarms/{swarm}/update-s3-storages', [SwarmController::class, 'updateS3Storages'])->name('swarms.update-s3-storages');
Expand Down

0 comments on commit bc46fef

Please sign in to comment.