feat: total users count on dashboard
This commit is contained in:
parent
2bdffccea2
commit
24ec4165a6
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Widgets\StatsOverviewWidget;
|
||||||
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||||
|
|
||||||
|
class TotalUsersOverview extends StatsOverviewWidget
|
||||||
|
{
|
||||||
|
protected static ?int $sort = -2;
|
||||||
|
|
||||||
|
protected static bool $isLazy = false;
|
||||||
|
|
||||||
|
protected ?string $pollingInterval = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<Stat>
|
||||||
|
*/
|
||||||
|
protected function getStats(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Stat::make(__('admin.widgets.total_users.label'), User::query()->count())
|
||||||
|
->description(__('admin.widgets.total_users.description'))
|
||||||
|
->icon(Heroicon::Users)
|
||||||
|
->color('primary'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
'widgets' => [
|
||||||
|
'total_users' => [
|
||||||
|
'label' => 'Users',
|
||||||
|
'description' => 'Total application user accounts.',
|
||||||
|
],
|
||||||
|
],
|
||||||
'users' => [
|
'users' => [
|
||||||
'navigation' => [
|
'navigation' => [
|
||||||
'label' => 'Users',
|
'label' => 'Users',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
'widgets' => [
|
||||||
|
'total_users' => [
|
||||||
|
'label' => 'Utilisateurs',
|
||||||
|
'description' => 'Nombre total de comptes utilisateurs.',
|
||||||
|
],
|
||||||
|
],
|
||||||
'users' => [
|
'users' => [
|
||||||
'navigation' => [
|
'navigation' => [
|
||||||
'label' => 'Utilisateurs',
|
'label' => 'Utilisateurs',
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\UserRole;
|
||||||
|
use App\Filament\Widgets\TotalUsersOverview;
|
||||||
|
use App\Models\User;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
app()->setLocale('fr');
|
||||||
|
|
||||||
|
Filament::setCurrentPanel(Filament::getPanel('dashboard'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the total users count on the filament dashboard widget', function () {
|
||||||
|
$admin = User::factory()->create([
|
||||||
|
'role' => UserRole::ADMIN,
|
||||||
|
]);
|
||||||
|
|
||||||
|
User::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$this->actingAs($admin);
|
||||||
|
|
||||||
|
expect(Filament::getPanel('dashboard')->getWidgets())
|
||||||
|
->toContain(TotalUsersOverview::class);
|
||||||
|
|
||||||
|
Livewire::test(TotalUsersOverview::class)
|
||||||
|
->assertSee('Utilisateurs')
|
||||||
|
->assertSee('Nombre total de comptes utilisateurs.')
|
||||||
|
->assertSee('3');
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue