feat: notification on filament dashboard
This commit is contained in:
@@ -7,6 +7,8 @@ use App\Enums\PhysicalActivityLevel;
|
||||
use App\Enums\UserRole;
|
||||
use App\Enums\UserSex;
|
||||
use App\Enums\WeightGoal;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -49,6 +51,11 @@ class UsersTable
|
||||
->sortable()
|
||||
->placeholder(__('admin.users.placeholders.not_verified'))
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('suspended_at')
|
||||
->label(__('admin.users.fields.suspended_at'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->placeholder(__('admin.users.placeholders.not_suspended')),
|
||||
ImageColumn::make('avatar_url')
|
||||
->label(__('admin.users.fields.avatar'))
|
||||
->disk('public')
|
||||
@@ -144,10 +151,25 @@ class UsersTable
|
||||
TernaryFilter::make('account_verified_at')
|
||||
->label(__('admin.users.filters.account_verified'))
|
||||
->nullable(),
|
||||
TernaryFilter::make('suspended_at')
|
||||
->label(__('admin.users.filters.suspended'))
|
||||
->nullable(),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
Action::make('suspend')
|
||||
->label(__('admin.users.actions.suspend'))
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (User $record): bool => ! $record->isSuspended() && $record->getKey() !== auth()->id())
|
||||
->action(fn (User $record): bool => self::suspendUser($record)),
|
||||
Action::make('unsuspend')
|
||||
->label(__('admin.users.actions.unsuspend'))
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (User $record): bool => $record->isSuspended())
|
||||
->action(fn (User $record): bool => self::unsuspendUser($record)),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
@@ -155,4 +177,30 @@ class UsersTable
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
private static function suspendUser(User $record): bool
|
||||
{
|
||||
if ($record->getKey() === auth()->id()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$record->forceFill([
|
||||
'suspended_at' => now(),
|
||||
'suspended_by' => auth()->id(),
|
||||
'suspended_reason' => __('admin.users.actions.suspend'),
|
||||
])->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function unsuspendUser(User $record): bool
|
||||
{
|
||||
$record->forceFill([
|
||||
'suspended_at' => null,
|
||||
'suspended_by' => null,
|
||||
'suspended_reason' => null,
|
||||
])->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user