163 lines
6.1 KiB
PHP
163 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\Onboarding\Admin\Resources;
|
|
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Forms\Form;
|
|
use Filament\Forms\Get;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables\Columns\ImageColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Columns\ToggleColumn;
|
|
use Filament\Tables\Table;
|
|
use Paymenter\Extensions\Others\Onboarding\Admin\Resources\OnboardingResource\Pages\CreateOnboardingSlide;
|
|
use Paymenter\Extensions\Others\Onboarding\Admin\Resources\OnboardingResource\Pages\EditOnboardingSlide;
|
|
use Paymenter\Extensions\Others\Onboarding\Admin\Resources\OnboardingResource\Pages\ListOnboardingSlides;
|
|
use Paymenter\Extensions\Others\Onboarding\Models\OnboardingSlide;
|
|
|
|
class OnboardingResource extends Resource
|
|
{
|
|
protected static ?string $model = OnboardingSlide::class;
|
|
|
|
protected static ?string $navigationIcon = 'ri-slideshow-line';
|
|
|
|
protected static ?string $activeNavigationIcon = 'ri-slideshow-fill';
|
|
|
|
protected static ?string $navigationGroup = 'Administration';
|
|
|
|
protected static ?string $navigationLabel = 'Onboarding';
|
|
|
|
protected static ?int $navigationSort = 10;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
TextInput::make('title')
|
|
->label('Title')
|
|
->required()
|
|
->maxLength(255)
|
|
->placeholder('Welcome to Our Platform'),
|
|
|
|
Textarea::make('description')
|
|
->label('Description')
|
|
->required()
|
|
->rows(4)
|
|
->placeholder('A brief description of this onboarding step...'),
|
|
|
|
FileUpload::make('image')
|
|
->label('Image')
|
|
->image()
|
|
->disk('public')
|
|
->directory('onboarding')
|
|
->visibility('public')
|
|
->imageEditor()
|
|
->imageEditorAspectRatios([
|
|
'16:9',
|
|
'4:3',
|
|
'1:1',
|
|
])
|
|
->maxSize(2048)
|
|
->helperText('Upload an image for this slide (max 2MB). Recommended aspect ratio: 16:9'),
|
|
|
|
TextInput::make('sort')
|
|
->label('Sort Order')
|
|
->numeric()
|
|
->default(0)
|
|
->required()
|
|
->helperText('Lower numbers appear first'),
|
|
|
|
Toggle::make('enabled')
|
|
->label('Enabled')
|
|
->default(true)
|
|
->helperText('Only enabled slides will be shown to users'),
|
|
|
|
Toggle::make('is_guided')
|
|
->label('Guided Slide')
|
|
->default(false)
|
|
->helperText('If enabled, this slide will redirect the user to a specific page')
|
|
->live(),
|
|
|
|
Select::make('page_route')
|
|
->label('Page to Guide To')
|
|
->options([
|
|
'dashboard' => 'Dashboard',
|
|
'services' => 'Services',
|
|
'services.first' => 'First Active Service',
|
|
'invoices' => 'Invoices',
|
|
'tickets' => 'Tickets',
|
|
'tickets.create' => 'Create Ticket',
|
|
'account' => 'Account Settings',
|
|
'account.security' => 'Account Security',
|
|
'account.payment-methods' => 'Payment Methods',
|
|
'account.notifications' => 'Notifications',
|
|
'products' => 'Browse Products',
|
|
])
|
|
->helperText('Select which page the user should be guided to')
|
|
->visible(fn (Get $get): bool => $get('is_guided'))
|
|
->required(fn (Get $get): bool => $get('is_guided')),
|
|
])
|
|
->columns(1);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
ImageColumn::make('image')
|
|
->label('Image')
|
|
->disk('public')
|
|
->square()
|
|
->defaultImageUrl(url('/images/placeholder.png')),
|
|
|
|
TextColumn::make('title')
|
|
->label('Title')
|
|
->searchable()
|
|
->sortable()
|
|
->limit(50),
|
|
|
|
TextColumn::make('description')
|
|
->label('Description')
|
|
->limit(80)
|
|
->wrap(),
|
|
|
|
TextColumn::make('sort')
|
|
->label('Order')
|
|
->sortable()
|
|
->alignCenter(),
|
|
|
|
ToggleColumn::make('enabled')
|
|
->label('Enabled')
|
|
->alignCenter(),
|
|
|
|
TextColumn::make('is_guided')
|
|
->label('Guided')
|
|
->badge()
|
|
->color(fn (bool $state): string => $state ? 'success' : 'gray')
|
|
->formatStateUsing(fn (bool $state): string => $state ? 'Yes' : 'No')
|
|
->alignCenter(),
|
|
|
|
TextColumn::make('created_at')
|
|
->label('Created')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->defaultSort('sort', 'asc')
|
|
->reorderable('sort');
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListOnboardingSlides::route('/'),
|
|
'create' => CreateOnboardingSlide::route('/create'),
|
|
'edit' => EditOnboardingSlide::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|