fix: Forms\Get/Set->Schemas Get/Set on Central panel + rename Super-admini to Utilizatori

This commit is contained in:
2026-05-07 22:08:09 +00:00
parent 10426d0c91
commit 0ac42dde3d
4 changed files with 22 additions and 16 deletions
@@ -8,6 +8,7 @@ use Filament\Actions;
use Filament\Forms; use Filament\Forms;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Schemas; use Filament\Schemas;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema; use Filament\Schemas\Schema;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Table; use Filament\Tables\Table;
@@ -56,8 +57,8 @@ class PlanResource extends Resource
Schemas\Components\Section::make('Preț') Schemas\Components\Section::make('Preț')
->columns(3) ->columns(3)
->schema([ ->schema([
Forms\Components\TextInput::make('price_monthly')->label('Preț lunar')->numeric()->required()->suffix(fn (Forms\Get $get) => $get('currency') ?? 'MDL'), Forms\Components\TextInput::make('price_monthly')->label('Preț lunar')->numeric()->required()->suffix(fn (Get $get) => $get('currency') ?? 'MDL'),
Forms\Components\TextInput::make('price_yearly')->label('Preț anual')->numeric()->helperText('De obicei 10× preț lunar (2 luni gratis).')->suffix(fn (Forms\Get $get) => $get('currency') ?? 'MDL'), Forms\Components\TextInput::make('price_yearly')->label('Preț anual')->numeric()->helperText('De obicei 10× preț lunar (2 luni gratis).')->suffix(fn (Get $get) => $get('currency') ?? 'MDL'),
Forms\Components\Select::make('currency')->options(['MDL' => 'MDL', 'EUR' => 'EUR', 'USD' => 'USD'])->default('MDL'), Forms\Components\Select::make('currency')->options(['MDL' => 'MDL', 'EUR' => 'EUR', 'USD' => 'USD'])->default('MDL'),
]), ]),
Schemas\Components\Section::make('Funcționalități incluse') Schemas\Components\Section::make('Funcționalități incluse')
@@ -11,6 +11,8 @@ use Filament\Forms;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Schemas; use Filament\Schemas;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema; use Filament\Schemas\Schema;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Table; use Filament\Tables\Table;
@@ -51,7 +53,7 @@ class SubscriptionResource extends Resource
->label('Plan') ->label('Plan')
->options(fn () => Plan::pluck('name', 'id')) ->options(fn () => Plan::pluck('name', 'id'))
->required()->searchable()->live() ->required()->searchable()->live()
->afterStateUpdated(function ($state, Forms\Set $set, Forms\Get $get) { ->afterStateUpdated(function ($state, Set $set, Get $get) {
if (! $state) return; if (! $state) return;
$plan = Plan::find($state); $plan = Plan::find($state);
if (! $plan) return; if (! $plan) return;
@@ -61,7 +63,7 @@ class SubscriptionResource extends Resource
}), }),
Forms\Components\Select::make('period') Forms\Components\Select::make('period')
->options(Subscription::PERIODS)->default('monthly')->required()->live() ->options(Subscription::PERIODS)->default('monthly')->required()->live()
->afterStateUpdated(function ($state, Forms\Set $set, Forms\Get $get) { ->afterStateUpdated(function ($state, Set $set, Get $get) {
$plan = Plan::find($get('plan_id')); $plan = Plan::find($get('plan_id'));
if (! $plan) return; if (! $plan) return;
$set('amount', $state === 'yearly' ? $plan->price_yearly : $plan->price_monthly); $set('amount', $state === 'yearly' ? $plan->price_yearly : $plan->price_monthly);
@@ -78,7 +80,7 @@ class SubscriptionResource extends Resource
Schemas\Components\Section::make('Sumă') Schemas\Components\Section::make('Sumă')
->columns(3) ->columns(3)
->schema([ ->schema([
Forms\Components\TextInput::make('amount')->numeric()->required()->suffix(fn (Forms\Get $get) => $get('currency') ?? 'MDL'), Forms\Components\TextInput::make('amount')->numeric()->required()->suffix(fn (Get $get) => $get('currency') ?? 'MDL'),
Forms\Components\Select::make('currency')->options(['MDL' => 'MDL', 'EUR' => 'EUR', 'USD' => 'USD'])->default('MDL'), Forms\Components\Select::make('currency')->options(['MDL' => 'MDL', 'EUR' => 'EUR', 'USD' => 'USD'])->default('MDL'),
Forms\Components\Select::make('payment_method') Forms\Components\Select::make('payment_method')
->options(Subscription::PAYMENT_METHODS), ->options(Subscription::PAYMENT_METHODS),
@@ -113,7 +115,7 @@ class SubscriptionResource extends Resource
Tables\Columns\TextColumn::make('company.name') Tables\Columns\TextColumn::make('company.name')
->label('Companie') ->label('Companie')
->searchable() ->searchable()
->url(fn ($r) => route('filament.central.resources.companies.edit', ['record' => $r->company_id])), ->url(fn ($r) => \App\Filament\Central\Resources\CompanyResource::getUrl('view', ['record' => $r->company_id])),
Tables\Columns\TextColumn::make('plan.name')->label('Plan')->placeholder('—'), Tables\Columns\TextColumn::make('plan.name')->label('Plan')->placeholder('—'),
Tables\Columns\TextColumn::make('period') Tables\Columns\TextColumn::make('period')
->formatStateUsing(fn ($s) => Subscription::PERIODS[$s] ?? $s) ->formatStateUsing(fn ($s) => Subscription::PERIODS[$s] ?? $s)
@@ -18,15 +18,15 @@ class SuperAdminResource extends Resource
{ {
protected static ?string $model = SuperAdmin::class; protected static ?string $model = SuperAdmin::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-shield-check'; protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-users';
protected static ?string $navigationLabel = 'Super-admini'; protected static ?string $navigationLabel = 'Utilizatori';
protected static ?string $modelLabel = 'super-admin'; protected static ?string $modelLabel = 'utilizator';
protected static ?string $pluralModelLabel = 'super-admini'; protected static ?string $pluralModelLabel = 'utilizatori';
protected static string|\UnitEnum|null $navigationGroup = 'Acces'; protected static string|\UnitEnum|null $navigationGroup = null;
protected static ?int $navigationSort = 50; protected static ?int $navigationSort = 50;
@@ -74,7 +74,14 @@ class SuperAdminResource extends Resource
Tables\Columns\TextColumn::make('email')->searchable()->copyable(), Tables\Columns\TextColumn::make('email')->searchable()->copyable(),
Tables\Columns\TextColumn::make('role') Tables\Columns\TextColumn::make('role')
->badge() ->badge()
->formatStateUsing(fn ($s) => array_keys(SuperAdmin::ROLES, SuperAdmin::ROLES[$s] ?? $s)[0] ?? $s) ->formatStateUsing(fn ($s) => match ($s) {
'owner' => 'Proprietar',
'admin' => 'Administrator',
'support' => 'Suport',
'sales' => 'Vânzări',
'finance' => 'Financiar',
default => $s,
})
->color(fn ($s) => match ($s) { ->color(fn ($s) => match ($s) {
'owner' => 'danger', 'owner' => 'danger',
'admin' => 'warning', 'admin' => 'warning',
@@ -59,10 +59,6 @@ class CentralPanelProvider extends PanelProvider
->databaseNotifications() ->databaseNotifications()
->databaseNotificationsPolling('60s') ->databaseNotificationsPolling('60s')
->globalSearchKeyBindings(['command+k', 'ctrl+k']) ->globalSearchKeyBindings(['command+k', 'ctrl+k'])
->navigationGroups([
'Tenants',
'Acces',
])
->renderHook( ->renderHook(
PanelsRenderHook::HEAD_END, PanelsRenderHook::HEAD_END,
fn (): string => Blade::render(<<<'BLADE' fn (): string => Blade::render(<<<'BLADE'