From 1c3811b01f7c1893858563a5f5e048add50b6f9c Mon Sep 17 00:00:00 2001 From: Kazem Alghasi Date: Tue, 4 Aug 2026 04:44:24 +0330 Subject: [PATCH] feat(ui): localize filament admin panel and refactor settings page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor the IfnexSettingsPage to use a custom Blade view and implement manual property binding for system settings. Additionally, localize navigation labels and groups to Persian for the Filament admin interface. - Implement `ifnex-settings.blade.php` for custom settings management - Localize navigation labels for Countries, Shipment Items, Shipments, and Shipping Rates - Update navigation groups to Persian (تنظیمات, عملیات) - Refactor `IfnexSettingsPage` to load settings from `SystemSetting` model during `mount` - Fix type hinting for `ShipmentDirection` enum in `ShipmentResource` table columns --- .../app/Filament/Pages/IfnexSettingsPage.php | 140 +++++++----------- .../Filament/Resources/CountryResource.php | 4 +- .../Resources/ShipmentItemResource.php | 4 +- .../Filament/Resources/ShipmentResource.php | 6 +- .../Resources/ShippingRateResource.php | 4 +- .../filament/pages/ifnex-settings.blade.php | 50 +++++++ 6 files changed, 113 insertions(+), 95 deletions(-) create mode 100644 04_Laravel/resources/views/filament/pages/ifnex-settings.blade.php diff --git a/04_Laravel/app/Filament/Pages/IfnexSettingsPage.php b/04_Laravel/app/Filament/Pages/IfnexSettingsPage.php index 8e758ec..aaa1ebc 100644 --- a/04_Laravel/app/Filament/Pages/IfnexSettingsPage.php +++ b/04_Laravel/app/Filament/Pages/IfnexSettingsPage.php @@ -3,107 +3,75 @@ namespace App\Filament\Pages; use App\Models\SystemSetting; -use Filament\Forms; use Filament\Pages\Page; class IfnexSettingsPage extends Page { protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth'; - - protected static ?string $navigationLabel = 'Settings'; - - protected static ?string $navigationGroup = 'Settings'; - + protected static ?string $navigationLabel = 'تنظیمات سیستم'; + protected static ?string $navigationGroup = 'تنظیمات'; protected static ?int $navigationSort = 1; - protected static string $view = 'filament::page'; + protected static string $view = 'filament.pages.ifnex-settings'; + + public float $vat_rate = 0.09; + public float $packing_cost_default = 100000; + public float $profit_margin = 1.25; + public float $aed_to_irr = 455000; + public float $usd_to_irr = 0; + public float $cny_to_irr = 0; + public float $eur_to_irr = 0; public function mount(): void { - $this->fillForms(); + $settings = SystemSetting::all()->pluck('value', 'key')->toArray(); + + if (isset($settings['vat_rate'])) $this->vat_rate = (float) $settings['vat_rate']; + if (isset($settings['packing_cost_default'])) $this->packing_cost_default = (float) $settings['packing_cost_default']; + if (isset($settings['profit_margin'])) $this->profit_margin = (float) $settings['profit_margin']; + if (isset($settings['aed_to_irr'])) $this->aed_to_irr = (float) $settings['aed_to_irr']; + if (isset($settings['usd_to_irr'])) $this->usd_to_irr = (float) $settings['usd_to_irr']; + if (isset($settings['cny_to_irr'])) $this->cny_to_irr = (float) $settings['cny_to_irr']; + if (isset($settings['eur_to_irr'])) $this->eur_to_irr = (float) $settings['eur_to_irr']; } - protected function getFormSchema(): array - { - return [ - Forms\Components\TextInput::make('vat_rate') - ->label('VAT Rate') - ->required() - ->numeric() - ->step(0.01) - ->default(0.09) - ->helperText('Example: 0.09 for 9%') - ->live(), - Forms\Components\TextInput::make('packing_cost_default') - ->label('Default Packing Cost (IRR)') - ->required() - ->numeric() - ->default(100000), - Forms\Components\TextInput::make('profit_margin') - ->label('Profit Margin') - ->required() - ->numeric() - ->step(0.01) - ->default(1.25) - ->helperText('Example: 1.25 for 25% margin'), - Forms\Components\TextInput::make('aed_to_irr') - ->label('AED to IRR') - ->required() - ->numeric() - ->default(455000), - Forms\Components\TextInput::make('usd_to_irr') - ->label('USD to IRR') - ->required() - ->numeric() - ->default(0), - Forms\Components\TextInput::make('cny_to_irr') - ->label('CNY to IRR') - ->required() - ->numeric() - ->default(0), - Forms\Components\TextInput::make('eur_to_irr') - ->label('EUR to IRR') - ->required() - ->numeric() - ->default(0), - ]; - } - - protected function mutateFormDataBeforeSave(array $data): array + public function save(): void { $userId = auth()->id(); - foreach ($data as $key => $value) { - if (is_numeric($value)) { - SystemSetting::updateOrCreate( - ['key' => $key], - ['value' => $value, 'updated_by' => $userId] - ); - } - } + SystemSetting::updateOrCreate( + ['key' => 'vat_rate'], + ['value' => $this->vat_rate, 'updated_by' => $userId] + ); + SystemSetting::updateOrCreate( + ['key' => 'packing_cost_default'], + ['value' => $this->packing_cost_default, 'updated_by' => $userId] + ); + SystemSetting::updateOrCreate( + ['key' => 'profit_margin'], + ['value' => $this->profit_margin, 'updated_by' => $userId] + ); + SystemSetting::updateOrCreate( + ['key' => 'aed_to_irr'], + ['value' => $this->aed_to_irr, 'updated_by' => $userId] + ); + SystemSetting::updateOrCreate( + ['key' => 'usd_to_irr'], + ['value' => $this->usd_to_irr, 'updated_by' => $userId] + ); + SystemSetting::updateOrCreate( + ['key' => 'cny_to_irr'], + ['value' => $this->cny_to_irr, 'updated_by' => $userId] + ); + SystemSetting::updateOrCreate( + ['key' => 'eur_to_irr'], + ['value' => $this->eur_to_irr, 'updated_by' => $userId] + ); - return []; - } - - protected function fillForms(): void - { - $settings = SystemSetting::all()->pluck('value', 'key')->toArray(); - - $defaults = [ - 'vat_rate' => 0.09, - 'packing_cost_default' => 100000, - 'profit_margin' => 1.25, - 'aed_to_irr' => 455000, - 'usd_to_irr' => 0, - 'cny_to_irr' => 0, - 'eur_to_irr' => 0, - ]; - - $this->data = array_merge($defaults, $settings); - } - - protected function getFormStatePath(): string - { - return 'data'; + \Filament\Notifications\Notification::make() + ->title('Success') + ->body('Settings saved successfully.') + ->success() + ->send(); } } diff --git a/04_Laravel/app/Filament/Resources/CountryResource.php b/04_Laravel/app/Filament/Resources/CountryResource.php index 63ad914..3e472fa 100644 --- a/04_Laravel/app/Filament/Resources/CountryResource.php +++ b/04_Laravel/app/Filament/Resources/CountryResource.php @@ -16,8 +16,8 @@ class CountryResource extends Resource protected static ?string $navigationIcon = 'heroicon-o-globe-alt'; - protected static ?string $navigationLabel = 'Countries'; - protected static ?string $navigationGroup = 'Settings'; + protected static ?string $navigationLabel = 'کشورها'; + protected static ?string $navigationGroup = 'تنظیمات'; public static function form(Form $form): Form { diff --git a/04_Laravel/app/Filament/Resources/ShipmentItemResource.php b/04_Laravel/app/Filament/Resources/ShipmentItemResource.php index 5dd49e9..fd3d674 100644 --- a/04_Laravel/app/Filament/Resources/ShipmentItemResource.php +++ b/04_Laravel/app/Filament/Resources/ShipmentItemResource.php @@ -16,8 +16,8 @@ class ShipmentItemResource extends Resource protected static ?string $navigationIcon = 'heroicon-o-clipboard-document-list'; - protected static ?string $navigationLabel = 'Shipment Items'; - protected static ?string $navigationGroup = 'Operations'; + protected static ?string $navigationLabel = 'اقلام مرسوله'; + protected static ?string $navigationGroup = 'عملیات'; public static function form(Form $form): Form { diff --git a/04_Laravel/app/Filament/Resources/ShipmentResource.php b/04_Laravel/app/Filament/Resources/ShipmentResource.php index 50b625a..c2c3d46 100644 --- a/04_Laravel/app/Filament/Resources/ShipmentResource.php +++ b/04_Laravel/app/Filament/Resources/ShipmentResource.php @@ -16,8 +16,8 @@ class ShipmentResource extends Resource protected static ?string $navigationIcon = 'heroicon-o-truck'; - protected static ?string $navigationLabel = 'Shipments'; - protected static ?string $navigationGroup = 'Operations'; + protected static ?string $navigationLabel = 'مرسولات'; + protected static ?string $navigationGroup = 'عملیات'; public static function form(Form $form): Form { @@ -159,7 +159,7 @@ class ShipmentResource extends Resource return $table ->columns([ Tables\Columns\TextColumn::make('awb_no')->searchable()->label('AWB No.')->sortable(), - Tables\Columns\TextColumn::make('direction')->badge()->color(fn (string $state): string => match ($state) { + Tables\Columns\TextColumn::make('direction')->badge()->color(fn (\App\Enums\ShipmentDirection $state): string => match ($state->value) { 'import' => 'success', 'export' => 'info', default => 'gray', diff --git a/04_Laravel/app/Filament/Resources/ShippingRateResource.php b/04_Laravel/app/Filament/Resources/ShippingRateResource.php index 0782acf..a45db02 100644 --- a/04_Laravel/app/Filament/Resources/ShippingRateResource.php +++ b/04_Laravel/app/Filament/Resources/ShippingRateResource.php @@ -16,8 +16,8 @@ class ShippingRateResource extends Resource protected static ?string $navigationIcon = 'heroicon-o-currency-dollar'; - protected static ?string $navigationLabel = 'Shipping Rates'; - protected static ?string $navigationGroup = 'Settings'; + protected static ?string $navigationLabel = 'نرخ‌های حمل'; + protected static ?string $navigationGroup = 'تنظیمات'; public static function form(Form $form): Form { diff --git a/04_Laravel/resources/views/filament/pages/ifnex-settings.blade.php b/04_Laravel/resources/views/filament/pages/ifnex-settings.blade.php new file mode 100644 index 0000000..73715eb --- /dev/null +++ b/04_Laravel/resources/views/filament/pages/ifnex-settings.blade.php @@ -0,0 +1,50 @@ + +
+ +
+
+ + +

Example: 0.09 for 9%

+
+ +
+ + +
+ +
+ + +

Example: 1.25 for 25% margin

+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+ +
+
+
+