Files
zemailnator/app/Filament/Resources/Usernames/Tables/UsernamesTable.php
2025-11-15 21:41:28 -08:00

109 lines
4.1 KiB
PHP

<?php
namespace App\Filament\Resources\Usernames\Tables;
use App\enum\ProviderType;
use App\enum\UsernameType;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;
class UsernamesTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('username')
->label('Usernames')
->searchable()
->weight('medium')
->icon(Heroicon::OutlinedUser)
->copyable()
->copyMessage('Domain copied!')
->copyMessageDuration(1500),
ToggleColumn::make('is_active')
->label('Active')
->alignCenter(),
TextColumn::make('username_type')
->label('Type')
->formatStateUsing(fn ($state) => $state ? UsernameType::tryFrom($state)?->getLabel() : '-')
->badge()
->color(fn ($state) => $state ? UsernameType::tryFrom($state)?->getColor() : 'gray')
->alignCenter(),
TextColumn::make('provider_type')
->label('Provider')
->formatStateUsing(fn ($state) => $state ? ProviderType::tryFrom($state)?->getLabel() : '-')
->badge()
->color(fn ($state) => $state ? ProviderType::tryFrom($state)?->getColor() : 'gray')
->alignCenter(),
TextColumn::make('daily_mailbox_limit')
->label('Daily Limit')
->numeric()
->formatStateUsing(fn ($state) => number_format($state))
->alignCenter()
->icon('heroicon-o-inbox'),
TextColumn::make('last_used_at')
->label('Last Used')
->dateTime('M j, Y g:i A')
->placeholder('Never')
->sortable()
->since()
->alignCenter(),
TextColumn::make('checked_at')
->label('Checked')
->dateTime('M j, Y')
->placeholder('Never')
->sortable()
->since()
->alignCenter()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
SelectFilter::make('username_type')
->label('Username Type')
->options(UsernameType::class),
SelectFilter::make('provider_type')
->label('Provider Type')
->options(ProviderType::class),
SelectFilter::make('is_active')
->label('Status')
->options([
true => 'Active',
false => 'Inactive',
]),
TrashedFilter::make(),
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
ForceDeleteBulkAction::make(),
RestoreBulkAction::make(),
]),
])
->emptyStateHeading('No usernames found')
->emptyStateDescription('Get started by creating your first username.')
->emptyStateActions([
// Add create action if needed
])
->poll('60s')
->striped()
->defaultPaginationPageOption(10)
->paginated([10, 25, 50, 100])
->reorderable('sort_order')
->defaultSort('username');
}
}