From 48ffc88aecc1381f068e1d4e1372c1f379021b2b Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Tue, 6 Jan 2026 21:27:00 +0700 Subject: [PATCH] feat: enhance audit logs display with event status colors and localized date formatting --- app/Livewire/Studio/Catalog/Bottle/Audit.php | 25 +++++++++++++++++-- app/Livewire/Studio/Catalog/Perfume/Audit.php | 25 +++++++++++++++++-- app/Livewire/Studio/Catalog/Product/Audit.php | 25 +++++++++++++++++-- .../components/sections/ui/audit.blade.php | 12 +++------ 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/app/Livewire/Studio/Catalog/Bottle/Audit.php b/app/Livewire/Studio/Catalog/Bottle/Audit.php index 6d4dc72..9db237d 100644 --- a/app/Livewire/Studio/Catalog/Bottle/Audit.php +++ b/app/Livewire/Studio/Catalog/Bottle/Audit.php @@ -28,9 +28,30 @@ public function mount(Outlet $outlet, Bottle $bottle): void ->latest() ->get() ->map(function (Activity $activity) { + $status = match ($activity->event) { + 'increase' => AuditStockStatus::INCREASED, + 'decrease' => AuditStockStatus::DECREASED, + 'created' => AuditStockStatus::INCREASED, + 'updated' => AuditStockStatus::UPDATED, + 'deleted' => AuditStockStatus::DELETED, + default => AuditStockStatus::tryFrom($activity->event), + }; + + $color = $status?->color() ?? 'gray'; + $label = $status?->label() ?? ucfirst($activity->event); + + $classes = match ($color) { + 'emerald' => 'bg-emerald-200 text-emerald-800 dark:bg-emerald-800 dark:text-emerald-200', + 'orange' => 'bg-orange-200 text-orange-800 dark:bg-orange-800 dark:text-orange-200', + 'yellow' => 'bg-yellow-200 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-200', + 'red' => 'bg-red-200 text-red-800 dark:bg-red-800 dark:text-red-200', + default => 'bg-gray-200 text-gray-800 dark:bg-gray-800 dark:text-gray-200', + }; + $activity->event = [ - 'label' => $activity->event, - 'color' => AuditStockStatus::from($activity->event)->color(), + 'label' => $label, + 'color' => $color, + 'classes' => $classes, ]; return $activity; diff --git a/app/Livewire/Studio/Catalog/Perfume/Audit.php b/app/Livewire/Studio/Catalog/Perfume/Audit.php index 3ff00fe..655a040 100644 --- a/app/Livewire/Studio/Catalog/Perfume/Audit.php +++ b/app/Livewire/Studio/Catalog/Perfume/Audit.php @@ -28,9 +28,30 @@ public function mount(Outlet $outlet, Perfume $perfume): void ->latest() ->get() ->map(function (Activity $activity) { + $status = match ($activity->event) { + 'increase' => AuditStockStatus::INCREASED, + 'decrease' => AuditStockStatus::DECREASED, + 'created' => AuditStockStatus::INCREASED, + 'updated' => AuditStockStatus::UPDATED, + 'deleted' => AuditStockStatus::DELETED, + default => AuditStockStatus::tryFrom($activity->event), + }; + + $color = $status?->color() ?? 'gray'; + $label = $status?->label() ?? ucfirst($activity->event); + + $classes = match ($color) { + 'emerald' => 'bg-emerald-200 text-emerald-800 dark:bg-emerald-800 dark:text-emerald-200', + 'orange' => 'bg-orange-200 text-orange-800 dark:bg-orange-800 dark:text-orange-200', + 'yellow' => 'bg-yellow-200 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-200', + 'red' => 'bg-red-200 text-red-800 dark:bg-red-800 dark:text-red-200', + default => 'bg-gray-200 text-gray-800 dark:bg-gray-800 dark:text-gray-200', + }; + $activity->event = [ - 'label' => $activity->event, - 'color' => AuditStockStatus::from($activity->event)->color(), + 'label' => $label, + 'color' => $color, + 'classes' => $classes, ]; return $activity; diff --git a/app/Livewire/Studio/Catalog/Product/Audit.php b/app/Livewire/Studio/Catalog/Product/Audit.php index 8b4eea8..ee6360c 100644 --- a/app/Livewire/Studio/Catalog/Product/Audit.php +++ b/app/Livewire/Studio/Catalog/Product/Audit.php @@ -28,9 +28,30 @@ public function mount(Outlet $outlet, Product $product): void ->latest() ->get() ->map(function (Activity $activity) { + $status = match ($activity->event) { + 'increase' => AuditStockStatus::INCREASED, + 'decrease' => AuditStockStatus::DECREASED, + 'created' => AuditStockStatus::INCREASED, + 'updated' => AuditStockStatus::UPDATED, + 'deleted' => AuditStockStatus::DELETED, + default => AuditStockStatus::tryFrom($activity->event), + }; + + $color = $status?->color() ?? 'gray'; + $label = $status?->label() ?? ucfirst($activity->event); + + $classes = match ($color) { + 'emerald' => 'bg-emerald-200 text-emerald-800 dark:bg-emerald-800 dark:text-emerald-200', + 'orange' => 'bg-orange-200 text-orange-800 dark:bg-orange-800 dark:text-orange-200', + 'yellow' => 'bg-yellow-200 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-200', + 'red' => 'bg-red-200 text-red-800 dark:bg-red-800 dark:text-red-200', + default => 'bg-gray-200 text-gray-800 dark:bg-gray-800 dark:text-gray-200', + }; + $activity->event = [ - 'label' => $activity->event, - 'color' => AuditStockStatus::from($activity->event)->color(), + 'label' => $label, + 'color' => $color, + 'classes' => $classes, ]; return $activity; diff --git a/resources/views/components/sections/ui/audit.blade.php b/resources/views/components/sections/ui/audit.blade.php index e3a61cc..0e5abd6 100644 --- a/resources/views/components/sections/ui/audit.blade.php +++ b/resources/views/components/sections/ui/audit.blade.php @@ -15,18 +15,14 @@
{{ $log->log_name }}
-
{{ $log->created_at }}
+
{{ formatDateLocalized($log->created_at) }}
{{ $log->causer?->employee?->full_name }}
- + {{ $log->event['label'] }}
- +
Stok Sebelumnya: {{ formatCurrencyNumber($log->properties['previous_stock']) }}
@@ -38,7 +34,7 @@ class="px-2 py-1 inline-flex text-xs font-semibold rounded-full -

+

{{ $log->description }}