Dashboard changes

This commit is contained in:
Tomasz Boruc 2026-08-26 14:51:08 +02:00
parent 6848ed0875
commit e4f40faca1
4 changed files with 213 additions and 39 deletions

View File

@ -45,7 +45,7 @@ class UserSeeder extends Seeder
$pracownik->assignRole($pracownikRole);
// 2. Generowanie dodatkowych 30 losowych użytkowników z rolami (password = 'password')
User::factory(300)->create()->each(function ($user) use ($pracownikRole, $kierownikRole) {
User::factory(30)->create()->each(function ($user) use ($pracownikRole, $kierownikRole) {
$role = rand(1, 100) <= 80 ? $pracownikRole : $kierownikRole;
$user->assignRole($role);
});

View File

@ -1,4 +1,29 @@
<x-guest-layout>
@php
$layout = isset($roles) ? 'app-layout' : 'guest-layout';
@endphp
<x-dynamic-component :component="$layout">
@if(isset($roles))
<x-slot name="header">
<div class="flex items-center justify-between">
<h2 class="font-semibold text-xl text-gray-800 dark:text-white leading-tight">
{{ __('Dodaj użytkownika') }}
</h2>
<a href="{{ route('users.index') }}"
class="inline-flex items-center px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-800 dark:text-white text-sm font-medium rounded-md shadow-sm transition ease-in-out duration-150 gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
</svg>
<span>{{ __('Powrót do listy') }}</span>
</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg border border-gray-200 dark:border-gray-700/50 p-6 text-gray-900 dark:text-white">
@endif
<form method="POST" action="{{ isset($roles) ? route('users.store') : route('register') }}">
@csrf
@ -44,34 +69,37 @@
<!-- Password -->
<div class="mt-4">
<x-input-label for="password" :value="__('Hasło')" />
<x-text-input id="password" class="block mt-1 w-full"
type="password"
name="password"
required autocomplete="new-password" />
<x-text-input id="password" class="block mt-1 w-full" type="password" name="password" required autocomplete="new-password" />
<x-input-error :messages="$errors->get('password')" class="mt-2" />
</div>
<!-- Confirm Password -->
<div class="mt-4">
<x-input-label for="password_confirmation" :value="__('Powtórz Hasło')" />
<x-text-input id="password_confirmation" class="block mt-1 w-full"
type="password"
name="password_confirmation" required autocomplete="new-password" />
<x-text-input id="password_confirmation" class="block mt-1 w-full" type="password" name="password_confirmation" required autocomplete="new-password" />
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
</div>
<div class="flex items-center justify-end mt-4">
<div class="flex items-center justify-end mt-6 gap-4">
@if(!isset($roles))
<a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('login') }}">
{{ __('Already registered?') }}
</a>
@else
<a href="{{ route('users.index') }}" class="inline-flex items-center px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-md font-semibold text-xs text-gray-700 dark:text-gray-300 uppercase tracking-widest shadow-sm hover:bg-gray-50 dark:hover:bg-gray-700 transition">
{{ __('Anuluj') }}
</a>
@endif
<x-primary-button class="ms-4">
<x-primary-button>
{{ __('Zapisz') }}
</x-primary-button>
</div>
</form>
</x-guest-layout>
@if(isset($roles))
</div>
</div>
</div>
@endif
</x-dynamic-component>

View File

@ -6,12 +6,135 @@
</x-slot>
<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-sm sm:rounded-lg">
<div class="p-6 text-gray-900 dark:text-gray-100">
{{ __("You're logged in!") }}
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
{{-- Karty ze statystykami --}}
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
{{-- Wszyscy użytkownicy --}}
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700/50 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Wszyscy użytkownicy</p>
<p class="text-3xl font-bold text-gray-900 dark:text-white mt-1">
{{ $totalUsers ?? 0 }}
</p>
</div>
<div class="p-3 bg-indigo-50 dark:bg-indigo-900/40 text-indigo-600 dark:text-indigo-400 rounded-full">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
</svg>
</div>
</div>
{{-- Administratorzy --}}
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700/50 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Administratorzy</p>
<p class="text-3xl font-bold text-gray-900 dark:text-white mt-1">
{{ $adminCount ?? 0 }}
</p>
</div>
<div class="p-3 bg-red-50 dark:bg-red-900/40 text-red-600 dark:text-red-400 rounded-full">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
</svg>
</div>
</div>
{{-- Kierownicy --}}
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700/50 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Kierownicy</p>
<p class="text-3xl font-bold text-gray-900 dark:text-white mt-1">
{{ $managerCount ?? 0 }}
</p>
</div>
<div class="p-3 bg-amber-50 dark:bg-amber-900/40 text-amber-600 dark:text-amber-400 rounded-full">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2m4 6h.01M5 20h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
</svg>
</div>
</div>
{{-- Pracownicy / Użytkownicy --}}
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700/50 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Pracownicy</p>
<p class="text-3xl font-bold text-gray-900 dark:text-white mt-1">
{{ $workerCount ?? 0 }}
</p>
</div>
<div class="p-3 bg-emerald-50 dark:bg-emerald-900/40 text-emerald-600 dark:text-emerald-400 rounded-full">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
</svg>
</div>
</div>
</div>
{{-- Sekcja dolna: Szybkie akcje i powitanie --}}
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
{{-- Powitanie i szybki stan --}}
<div class="lg:col-span-2 bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700/50">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">
Witaj, {{ Auth::user()->name }}! 👋
</h3>
<p class="text-gray-600 dark:text-gray-300 text-sm mb-4">
Jesteś zalogowany w systemie. Poniżej znajdziesz szybkie skróty do najważniejszych modułów w aplikacji.
</p>
<div class="pt-4 border-t border-gray-200 dark:border-gray-700 flex flex-wrap gap-3">
<a href="{{ route('users.index') }}"
class="inline-flex items-center px-4 py-2 bg-indigo-600 hover:bg-indigo-500 text-white text-sm font-medium rounded-md shadow-sm transition gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 43v17m0 0l-4-4m4 4l4-4" />
</svg>
<span>Zarządzaj użytkownikami</span>
</a>
@hasanyrole('admin|kierownik')
<a href="{{ route('users.create') }}"
class="inline-flex items-center px-4 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-600 text-sm font-medium rounded-md shadow-sm transition gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg>
<span>Dodaj użytkownika</span>
</a>
@endhasanyrole
</div>
</div>
{{-- Ostatnio zarejestrowani --}}
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700/50">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">
Ostatnio dodani
</h3>
<div class="space-y-3">
@forelse($recentUsers ?? [] as $user)
<div class="flex items-center justify-between pb-2 border-b border-gray-100 dark:border-gray-700/50 last:border-0 last:pb-0">
<div>
<p class="text-sm font-medium text-gray-900 dark:text-white">
{{ $user->name }} {{ $user->surname }}
</p>
<p class="text-xs text-gray-500 dark:text-gray-400">
{{ $user->email }}
</p>
</div>
<span class="text-xs text-gray-400 dark:text-gray-500">
{{ $user->created_at->diffForHumans() }}
</span>
</div>
@empty
<p class="text-sm text-gray-500 dark:text-gray-400">Brak nowych użytkowników.</p>
@endforelse
</div>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@ -3,6 +3,7 @@
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;
use App\Models\User;
Route::get('/', function () {
return view('welcome');
@ -20,6 +21,28 @@ Route::middleware(['auth', 'verified'])->group(function () {
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
Route::get('/dashboard', function () {
$totalUsers = User::count();
// Jeśli używasz Spatie Roles/Permissions:
$adminCount = User::role('admin')->count();
$managerCount = User::role('kierownik')->count();
$workerCount = User::role('pracownik')->count();
// Pobranie 5 ostatnio dodanych użytkowników:
$recentUsers = User::latest()->take(5)->get();
return view('dashboard', compact(
'totalUsers',
'adminCount',
'managerCount',
'workerCount',
'recentUsers'
));
})->middleware(['auth', 'verified'])->name('dashboard');
// Zarządzanie użytkownikami (tylko dla posiadaczy uprawnienia users_access)
Route::middleware(['can:users_access'])->group(function () {
Route::get('/users', [UserController::class, 'index'])->name('users.index');