feat: add domain management system
This commit is contained in:
61
app/Filament/Resources/Domains/DomainResource.php
Normal file
61
app/Filament/Resources/Domains/DomainResource.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Domains;
|
||||
|
||||
use App\Filament\Resources\Domains\Pages\CreateDomain;
|
||||
use App\Filament\Resources\Domains\Pages\EditDomain;
|
||||
use App\Filament\Resources\Domains\Pages\ListDomains;
|
||||
use App\Filament\Resources\Domains\Schemas\DomainForm;
|
||||
use App\Filament\Resources\Domains\Tables\DomainsTable;
|
||||
use App\Models\Domain;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use UnitEnum;
|
||||
|
||||
class DomainResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Domain::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::GlobeAlt;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Email';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return DomainForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return DomainsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListDomains::route('/'),
|
||||
'create' => CreateDomain::route('/create'),
|
||||
'edit' => EditDomain::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Domains/Pages/CreateDomain.php
Normal file
11
app/Filament/Resources/Domains/Pages/CreateDomain.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Domains\Pages;
|
||||
|
||||
use App\Filament\Resources\Domains\DomainResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateDomain extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DomainResource::class;
|
||||
}
|
||||
23
app/Filament/Resources/Domains/Pages/EditDomain.php
Normal file
23
app/Filament/Resources/Domains/Pages/EditDomain.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Domains\Pages;
|
||||
|
||||
use App\Filament\Resources\Domains\DomainResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditDomain extends EditRecord
|
||||
{
|
||||
protected static string $resource = DomainResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
ForceDeleteAction::make(),
|
||||
RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Domains/Pages/ListDomains.php
Normal file
19
app/Filament/Resources/Domains/Pages/ListDomains.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Domains\Pages;
|
||||
|
||||
use App\Filament\Resources\Domains\DomainResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListDomains extends ListRecords
|
||||
{
|
||||
protected static string $resource = DomainResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
67
app/Filament/Resources/Domains/Schemas/DomainForm.php
Normal file
67
app/Filament/Resources/Domains/Schemas/DomainForm.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Domains\Schemas;
|
||||
|
||||
use App\enum\DomainType;
|
||||
use App\enum\ProviderType;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class DomainForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->columnSpan(1)
|
||||
->helperText('Domain name: example.com')
|
||||
->required(),
|
||||
TextInput::make('daily_mailbox_limit')
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->default(100)
|
||||
->helperText('How many mailboxes can be created with this domain daily')
|
||||
->columnSpan(1)
|
||||
->required(),
|
||||
ToggleButtons::make('is_active')
|
||||
->options([
|
||||
true => 'Active',
|
||||
false => 'Disabled',
|
||||
])
|
||||
->inline()
|
||||
->default(true)
|
||||
->columnSpanFull()
|
||||
->required(),
|
||||
Select::make('domain_type')
|
||||
->options(DomainType::class)
|
||||
->enum(DomainType::class)
|
||||
->required(),
|
||||
Select::make('provider_type')
|
||||
->options(ProviderType::class)
|
||||
->enum(ProviderType::class)
|
||||
->required(),
|
||||
DateTimePicker::make('starts_at'),
|
||||
DateTimePicker::make('ends_at'),
|
||||
TextEntry::make('last_used_at')
|
||||
->label('Last Used At')
|
||||
->formatStateUsing(fn ($state) => $state ? $state->diffForHumans() : 'Never')
|
||||
->visible(fn ($context) => $context === 'edit'),
|
||||
TextEntry::make('checked_at')
|
||||
->label('Last Checked At')
|
||||
->formatStateUsing(fn ($state) => $state ? $state->diffForHumans() : 'Never')
|
||||
->visible(fn ($context) => $context === 'edit'),
|
||||
TextEntry::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->formatStateUsing(fn ($state) => $state ? $state->diffForHumans() : null)
|
||||
->color('danger')
|
||||
->icon('heroicon-o-trash')
|
||||
->visible(fn ($record) => $record?->deleted_at !== null),
|
||||
|
||||
])->columns(2);
|
||||
}
|
||||
}
|
||||
107
app/Filament/Resources/Domains/Tables/DomainsTable.php
Normal file
107
app/Filament/Resources/Domains/Tables/DomainsTable.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Domains\Tables;
|
||||
|
||||
use App\enum\DomainType;
|
||||
use App\enum\ProviderType;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
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 DomainsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label('Domain')
|
||||
->searchable()
|
||||
->weight('medium')
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->copyable()
|
||||
->copyMessage('Domain copied!')
|
||||
->copyMessageDuration(1500),
|
||||
ToggleColumn::make('is_active')
|
||||
->label('Active')
|
||||
->alignCenter(),
|
||||
TextColumn::make('domain_type')
|
||||
->label('Type')
|
||||
->formatStateUsing(fn ($state) => $state ? DomainType::tryFrom($state)?->getLabel() : '-')
|
||||
->badge()
|
||||
->color(fn ($state) => $state ? DomainType::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('domain_type')
|
||||
->label('Domain Type')
|
||||
->options(DomainType::class),
|
||||
SelectFilter::make('provider_type')
|
||||
->label('Provider Type')
|
||||
->options(ProviderType::class),
|
||||
SelectFilter::make('is_active')
|
||||
->label('Status')
|
||||
->options([
|
||||
'1' => 'Active',
|
||||
'0' => 'Inactive',
|
||||
]),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('No domains found')
|
||||
->emptyStateDescription('Get started by creating your first domain.')
|
||||
->emptyStateActions([
|
||||
// Add create action if needed
|
||||
])
|
||||
->poll('60s')
|
||||
->striped()
|
||||
->defaultPaginationPageOption(10)
|
||||
->paginated([10, 25, 50, 100])
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('name');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user