139 lines
4.7 KiB
PHP
139 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\Security\Admin\Resources;
|
|
|
|
use Filament\Resources\Resource;
|
|
use Filament\Forms\Form;
|
|
use Filament\Tables\Table;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Columns\BadgeColumn;
|
|
use Filament\Tables\Columns\BooleanColumn;
|
|
use Filament\Tables\Actions\EditAction;
|
|
use Filament\Tables\Actions\Action;
|
|
use Filament\Tables\Actions\BulkActionGroup;
|
|
use Filament\Tables\Actions\DeleteBulkAction;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Paymenter\Extensions\Others\Security\Models\SuspendedAccount;
|
|
use Paymenter\Extensions\Others\Security\Admin\Resources\SuspendedAccountResource\Pages;
|
|
use Filament\Forms\Get;
|
|
|
|
class SuspendedAccountResource extends Resource
|
|
{
|
|
protected static ?string $model = SuspendedAccount::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-user-minus';
|
|
protected static ?string $navigationGroup = 'Security';
|
|
protected static ?string $navigationLabel = 'Suspended Accounts';
|
|
protected static ?string $pluralLabel = 'Suspended Accounts';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Select::make('user_id')
|
|
->label('User')
|
|
->relationship('user', 'email')
|
|
->searchable()
|
|
->preload()
|
|
->required(),
|
|
|
|
TextInput::make('reason')
|
|
->label('Reason')
|
|
->required()
|
|
->maxLength(255),
|
|
|
|
Textarea::make('notes')
|
|
->label('Notes')
|
|
->rows(3)
|
|
->maxLength(1000),
|
|
|
|
Toggle::make('is_permanent')
|
|
->label('Permanent Suspension')
|
|
->default(false)
|
|
->reactive(),
|
|
|
|
DateTimePicker::make('suspended_until')
|
|
->label('Suspended Until')
|
|
->nullable()
|
|
->hidden(fn (Get $get) => $get('is_permanent')),
|
|
|
|
Select::make('suspended_by')
|
|
->label('Suspended By')
|
|
->relationship('suspendedBy', 'email')
|
|
->nullable()
|
|
->default(fn () => Auth::id())
|
|
->required(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('user.email')
|
|
->label('User')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
TextColumn::make('reason')
|
|
->label('Reason')
|
|
->searchable()
|
|
->limit(50),
|
|
|
|
BadgeColumn::make('is_permanent')
|
|
->label('Type')
|
|
->getStateUsing(fn (SuspendedAccount $record) => $record->is_permanent ? 'Permanent' : 'Temporary')
|
|
->colors([
|
|
'danger' => 'Permanent',
|
|
'warning' => 'Temporary',
|
|
]),
|
|
|
|
TextColumn::make('suspended_until')
|
|
->label('Until')
|
|
->dateTime()
|
|
->sortable(),
|
|
|
|
BooleanColumn::make('is_active')
|
|
->label('Active'),
|
|
|
|
TextColumn::make('suspendedBy.email')
|
|
->label('Suspended By')
|
|
->sortable(),
|
|
|
|
TextColumn::make('suspended_at')
|
|
->label('Suspended At')
|
|
->dateTime()
|
|
->sortable(),
|
|
])
|
|
->actions([
|
|
EditAction::make(),
|
|
Action::make('lift')
|
|
->label('Lift Suspension')
|
|
->icon('heroicon-m-check')
|
|
->color('success')
|
|
->action(fn (SuspendedAccount $record) => $record->lift(Auth::id()))
|
|
->requiresConfirmation()
|
|
->visible(fn (SuspendedAccount $record) => $record->is_active),
|
|
])
|
|
->bulkActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->defaultSort('suspended_at', 'desc');
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListSuspendedAccounts::route('/'),
|
|
'create' => Pages\CreateSuspendedAccount::route('/create'),
|
|
'edit' => Pages\EditSuspendedAccount::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|