Files
Vasyka 95aeecb932 i18n: fix widget heading, translate Select options from model consts, +40 keys
- LowStockTable: rename getHeading → getTableHeading (correct Filament API)
- Global I18n::opts() helper wraps Model::CONST values in __() so
  Select dropdowns show translated status/type/season/etc. labels
- Sed-transform ->options(X::CONST), ->options(array_combine(X::A,X::A)),
  and formatStateUsing(fn($s)=>X::CONST[$s]??$s) → wrap with __()
  (58 options + 10 combines + 7 formatStateUsing across 28 files)
- CalendarBoard: all 7 day names now via __() (was missing 4)
- calendar-board.blade: fix untranslated 'săptămâna curentă', 'capacitate',
  'rata confirmare', 'mediu', 'plin', 'Pod / Zi' / 'Mecanic / Zi'
- +40 RU/EN translations (Client & Auto, Maistru / Mecanic, Programat,
  Sosit, Finalizat, Anulat, Neprezentat, days of week, calendar KPIs)

All 306 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-16 06:42:16 +00:00

171 lines
7.5 KiB
PHP

<?php
namespace App\Filament\Central\Resources;
use App\Filament\Central\Resources\SuperAdminResource\Pages;
use App\Models\Central\SuperAdmin;
use Filament\Actions;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Schemas;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Hash;
class SuperAdminResource extends Resource
{
protected static ?string $model = SuperAdmin::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-users';
public static function getNavigationLabel(): string
{
return __('nav.label.Utilizatori');
}
protected static ?string $modelLabel = null;
public static function getModelLabel(): string
{
return __('utilizator');
}
protected static ?string $pluralModelLabel = null;
public static function getPluralModelLabel(): string
{
return __('utilizatori');
}
protected static string|\UnitEnum|null $navigationGroup = null;
protected static ?int $navigationSort = 50;
public static function form(Schema $schema): Schema
{
return $schema->components([
Schemas\Components\Section::make(__('Identificare'))
->columns(2)
->schema([
Forms\Components\TextInput::make('name')->required()->maxLength(120),
Forms\Components\TextInput::make('email')->email()->required()->unique(ignoreRecord: true)->maxLength(120),
Forms\Components\TextInput::make('phone')->tel()->maxLength(40),
Forms\Components\Toggle::make('is_active')->label(__('Activ'))->default(true),
]),
Schemas\Components\Section::make(__('Permisiuni'))
->columns(1)
->schema([
Forms\Components\Select::make('role')
->options(\App\Support\I18n::opts(SuperAdmin::ROLES))
->default('support')
->required()
->helperText(__('Owner = drepturi totale. Admin = aproape la fel. Sales = doar tenanți + planuri. Finance = facturi. Support = read-only.')),
]),
Schemas\Components\Section::make(__('Parolă'))
->columns(1)
->schema([
Forms\Components\TextInput::make('password')
->password()
->revealable()
->dehydrated(fn ($state) => filled($state))
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->required(fn (string $operation) => $operation === 'create')
->minLength(8)
->helperText(fn (string $operation) => $operation === 'edit' ? 'Lasă gol ca să o păstrezi.' : 'Min 8 caractere.'),
]),
Forms\Components\Textarea::make('notes')->label(__('Note interne'))->rows(2)->columnSpanFull(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->searchable()->sortable()->weight('bold'),
Tables\Columns\TextColumn::make('email')->searchable()->copyable(),
Tables\Columns\TextColumn::make('role')
->badge()
->formatStateUsing(fn ($s) => match ($s) {
'owner' => 'Proprietar',
'admin' => 'Administrator',
'support' => 'Suport',
'sales' => __('Vânzări'),
'finance' => 'Financiar',
default => $s,
})
->color(fn ($s) => match ($s) {
'owner' => 'danger',
'admin' => 'warning',
'finance' => 'success',
'sales' => 'info',
default => 'gray',
}),
Tables\Columns\IconColumn::make('is_active')->boolean()->label(__('Activ')),
Tables\Columns\IconColumn::make('app_authentication_secret')
->label(__('2FA'))
->boolean()
->getStateUsing(fn ($record) => $record?->app_authentication_secret !== null)
->trueIcon('heroicon-o-lock-closed')
->falseIcon('heroicon-o-lock-open')
->trueColor('success')
->falseColor('warning'),
Tables\Columns\TextColumn::make('last_login_at')->label(__('Ultim login'))->dateTime()->placeholder('—'),
Tables\Columns\TextColumn::make('created_at')->date(),
])
->filters([
Tables\Filters\SelectFilter::make('role')->options(\App\Support\I18n::opts(SuperAdmin::ROLES)),
Tables\Filters\TernaryFilter::make('is_active')->label(__('Activ')),
])
->actions([
Actions\Action::make('reset_password')
->label(__('Reset parolă'))
->icon('heroicon-m-key')
->color('warning')
->schema([
Forms\Components\TextInput::make('new_password')
->password()->required()->minLength(8)->revealable(),
])
->action(function (SuperAdmin $record, array $data) {
$record->update(['password' => Hash::make($data['new_password'])]);
Notification::make()->title(__('Parolă resetată.'))->success()->send();
}),
Actions\Action::make('toggle_2fa')
->label(fn (SuperAdmin $record) => $record->app_authentication_secret ? 'Dezactivează 2FA' : 'Forțează re-setare 2FA')
->icon('heroicon-m-lock-open')
->color('danger')
->visible(fn (SuperAdmin $record) => $record->app_authentication_secret !== null)
->requiresConfirmation()
->action(function (SuperAdmin $record) {
$record->forceFill([
'app_authentication_secret' => null,
'app_authentication_recovery_codes' => null,
'email_authentication_at' => null,
])->saveQuietly();
Notification::make()->title(__('2FA dezactivat.'))->success()->send();
}),
Actions\EditAction::make(),
Actions\DeleteAction::make()
->before(function (SuperAdmin $record) {
if (auth('central')->id() === $record->id) {
Notification::make()->title(__('Nu te poți șterge pe tine!'))->danger()->send();
return false;
}
}),
])
->emptyStateHeading(__('Doar tu ești aici'))
->emptyStateDescription(__('Adaugă echipa ta — colegi de la suport, sales, finance — fiecare cu rolul lui.'))
->defaultSort('created_at', 'desc');
}
public static function getPages(): array
{
return [
'index' => Pages\ListSuperAdmins::route('/'),
'create' => Pages\CreateSuperAdmin::route('/create'),
'edit' => Pages\EditSuperAdmin::route('/{record}/edit'),
];
}
}