ifnex/04_Laravel/app/Filament/Widgets/RecentShipmentsWidget.php
Kazem Alghasi c54530d8da refactor(admin): optimize dashboard layout and enhance sidebar UX
Refactor the Filament admin dashboard by decoupling the recent shipments
logic into a dedicated widget and improving the sidebar navigation
experience. Additionally, implement several improvements to the
WordPress theme for better client-side usability.

Laravel/Filament:
- Extract `RecentShipmentsWidget` from `DashboardInfoWidget` to improve
  modularization and dashboard performance.
- Update widget sorting and layout to accommodate the new structure.
- Inject custom CSS and Alpine.js logic into the admin head to provide
  sidebar group toggling and a "collapse all" utility.
- Improve sidebar group label visibility and hover states.

WordPress:
- Implement `ifnex_login_url()` to support Polylang-aware, language-specific
  login pages.
- Hide the WordPress admin bar for non-administrator users to provide a
  cleaner client interface.
- Add conditional rendering for the registration link in the login
  template based on WordPress user registration settings.
2026-10-03 07:01:54 +03:30

74 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Widgets;
use App\Models\Shipment;
use Filament\Widgets\Widget;
use Morilog\Jalali\Jalalian;
/**
* جدول آخرین ۵ سفارش — تمام‌عرض، زیر کارت تاریخ/ساعت.
*/
class RecentShipmentsWidget extends Widget
{
protected static ?int $sort = 2;
protected static bool $isLazy = false;
protected int | string | array $columnSpan = 'full';
protected static string $view = 'filament.widgets.recent-shipments';
protected function getViewData(): array
{
$recentShipments = Shipment::query()
->with(['fromCountry', 'toCountry'])
->orderBy('created_at', 'desc')
->limit(5)
->get()
->map(function ($s) {
return [
'awb' => $s->awb_no,
'route' => ($s->fromCountry?->name ?? '?') . ' → ' . ($s->toCountry?->name ?? '?'),
'status' => $s->status?->value ?? '—',
'status_label' => $this->statusLabel($s->status?->value),
'status_color' => $this->statusColor($s->status?->value),
'date' => Jalalian::fromCarbon($s->created_at)->format('Y/m/d'),
'amount' => $s->total_fee ? number_format($s->total_fee) . ' ریال' : '—',
];
});
return [
'recentShipments' => $recentShipments,
];
}
private function statusLabel(?string $status): string
{
return match($status) {
'processed' => 'پردازش شده',
'picked_up' => 'تحویل گرفته شده',
'in_transit' => 'در حال حمل',
'out_for_delivery' => 'در مسیر تحویل',
'delivered' => 'تحویل داده شده',
'failed' => 'ناموفق',
'returned' => 'برگشتی',
default => '—',
};
}
private function statusColor(?string $status): string
{
return match($status) {
'processed' => 'bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300',
'picked_up' => 'bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300',
'in_transit' => 'bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300',
'out_for_delivery' => 'bg-purple-100 text-purple-700 dark:bg-purple-900 dark:text-purple-300',
'delivered' => 'bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300',
'failed' => 'bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-300',
'returned' => 'bg-orange-100 text-orange-700 dark:bg-orange-900 dark:text-orange-300',
default => 'bg-gray-100 text-gray-700',
};
}
}