Files
autocrm/app/Filament/Tenant/Resources/LeadResource.php
T
Vasyka 78ff8d4b43 feat: i18n on Filament admin sidebar — 54 resources/pages translated
User screenshots showed the tenant admin panel (Filament) had sidebar
labels stuck in Romanian even when switching to Russian: 'Cereri',
'Calendar vizual', 'Atelierul meu', 'KPI mecanici', 'Fișe lucru',
'Norme-ore', 'Tehnicieni', 'Șabloane servicii', 'Depozite', 'Scaner',
'Depozit', 'VIN-căutare', 'Furnizori', 'Achiziții', 'Procentaj',
'Coeficienți preț', plus all group headers.

Root cause: every Filament Resource and Page had static properties
'protected static ?string $navigationLabel = "Fișe lucru"' — string
literals baked into class definitions. Static properties don't run
through the translation layer.

Fix in two parts:

1. New translation files with 52 label keys + 12 group keys:
   - lang/ro/nav.php — Romanian (identity)
   - lang/ru/nav.php — full Russian translations (Заказ-наряды,
     Автомобили, Клиенты, Календарь, Моя мастерская, Механики KPI,
     Настройки, etc.)
   - lang/en/nav.php — English translations (Work orders, Vehicles,
     Clients, Calendar, My workshop, Mechanic KPI, Settings, etc.)

   Keyed by the Romanian original so lookups map 1:1 —
   'nav.label.Fișe lucru' returns 'Заказ-наряды' in RU, 'Work orders'
   in EN, 'Fișe lucru' in RO.

2. Python transformer converted 54 files:
   - 33 Filament Tenant Resources
   - 15 Filament Tenant Pages
   - 4 Filament Central Resources
   - 1 Filament Central Page
   - 1 Widget

   Each 'protected static ?string $navigationLabel = "X";' became
   'public static function getNavigationLabel(): string { return
   __("nav.label.X"); }'. Same treatment for $navigationGroup.

Cleanup: 6 resources already had manually-added getNavigationLabel
methods from an earlier partial effort — those used flat JSON keys
(__("Cereri")) that never resolved. Deduped so only the nav.label.*
version remains.

Untouched (intentional):
- $modelLabel / $pluralModelLabel (used in breadcrumbs and headings —
  still hardcoded, next tier of work)
- Section titles, column headers, form field labels (medium priority)
- $navigationSort (numeric, no translation needed)
- $navigationIcon (icon reference)

Suite: 306 passed (853 assertions). Unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-13 20:41:55 +00:00

158 lines
6.5 KiB
PHP

<?php
namespace App\Filament\Tenant\Resources;
use App\Filament\Tenant\Resources\LeadResource\Pages;
use App\Models\Tenant\Lead;
use App\Models\Tenant\User;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Actions;
use Filament\Schemas;
use Filament\Tables;
use Filament\Tables\Table;
class LeadResource extends Resource
{
protected static ?string $model = Lead::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-inbox-arrow-down';
public static function getNavigationLabel(): string
{
return __('nav.label.Cereri');
}
public static function getNavigationGroup(): ?string
{
return __('nav.group.CRM');
}
protected static ?string $modelLabel = 'cerere';
protected static ?string $pluralModelLabel = 'cereri';
protected static ?int $navigationSort = 5;
public static function getGloballySearchableAttributes(): array
{
return ['name', 'phone', 'email', 'source', 'car', 'model'];
}
public static function getGlobalSearchResultDetails(\Illuminate\Database\Eloquent\Model $record): array
{
return [
'Telefon' => $record->phone,
'Status' => $record->status,
];
}
public static function form(Schema $schema): Schema
{
return $schema->components([
Schemas\Components\Section::make('Contact')
->columns(2)
->schema([
Forms\Components\TextInput::make('name')->label('Nume')->required()->maxLength(120),
Forms\Components\TextInput::make('phone')->label('Telefon')->tel()->required()->maxLength(40),
Forms\Components\TextInput::make('email')->email()->maxLength(120),
Forms\Components\Select::make('status')
->options(Lead::STATUSES)
->default('new')
->required(),
]),
Schemas\Components\Section::make('Auto')
->columns(2)
->schema([
Forms\Components\TextInput::make('car')->label('Marca')->maxLength(60),
Forms\Components\TextInput::make('model')->maxLength(60),
]),
Forms\Components\Textarea::make('message')->label('Mesaj client')->columnSpanFull()->rows(3),
Schemas\Components\Section::make('Sursă & Atribuire')
->columns(2)
->schema([
Forms\Components\Select::make('source')
->options(Lead::SOURCES)
->searchable()
->default('manual'),
Forms\Components\Select::make('assigned_to')
->label('Responsabil')
->options(fn () => User::pluck('name', 'id'))
->searchable(),
Forms\Components\TextInput::make('budget')->label('Buget')->numeric(),
]),
Schemas\Components\Section::make('Marketing (UTM)')
->collapsed()
->columns(2)
->schema([
Forms\Components\TextInput::make('utm_source'),
Forms\Components\TextInput::make('utm_medium'),
Forms\Components\TextInput::make('utm_campaign'),
Forms\Components\TextInput::make('utm_term'),
Forms\Components\TextInput::make('utm_content'),
]),
Forms\Components\Textarea::make('notes')->label('Notițe interne')->columnSpanFull()->rows(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('created_at')->label('Data')->dateTime('d.m.Y H:i')->sortable(),
Tables\Columns\TextColumn::make('name')->searchable()->sortable(),
Tables\Columns\TextColumn::make('phone')->copyable()->searchable(),
Tables\Columns\TextColumn::make('car')->label('Auto')->formatStateUsing(fn ($state, $record) => trim($state . ' ' . ($record->model ?? ''))),
Tables\Columns\TextColumn::make('source')->label('Sursă')->formatStateUsing(fn ($state) => Lead::SOURCES[$state] ?? $state)->badge(),
Tables\Columns\TextColumn::make('status')
->formatStateUsing(fn ($state) => Lead::STATUSES[$state] ?? $state)
->badge()
->colors([
'gray' => ['new'],
'warning' => ['contacted', 'no_answer'],
'info' => ['scheduled'],
'success' => ['converted'],
'danger' => ['lost'],
]),
Tables\Columns\TextColumn::make('assignedTo.name')->label('Responsabil')->placeholder('—'),
Tables\Columns\TextColumn::make('budget')->money('MDL')->placeholder('—'),
])
->filters([
Tables\Filters\SelectFilter::make('status')->options(Lead::STATUSES),
Tables\Filters\SelectFilter::make('source')->options(Lead::SOURCES),
])
->actions([
Actions\Action::make('convert')
->label('Convertește')
->icon('heroicon-m-arrow-right-circle')
->color('success')
->visible(fn (Lead $r) => $r->status !== 'converted')
->requiresConfirmation()
->action(function (Lead $r) {
$deal = $r->convert();
Notification::make()
->title('Convertit în deal #' . $deal->id)
->success()
->send();
}),
Actions\EditAction::make(),
Actions\DeleteAction::make(),
])
->emptyStateHeading('Nicio cerere primită')
->emptyStateDescription('Aici apar cererile clienților potențiali. Convertește-le în deal-uri sau direct în programări de la butonul „Convertește".')
->emptyStateIcon('heroicon-o-inbox-arrow-down')
->defaultSort('created_at', 'desc');
}
public static function getPages(): array
{
return [
'index' => Pages\ListLeads::route('/'),
'create' => Pages\CreateLead::route('/create'),
'edit' => Pages\EditLead::route('/{record}/edit'),
];
}
}