Fix coupon infolist enum formatting
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Filament\Resources\Coupons\Schemas;
|
||||
|
||||
use App\Enums\CouponStatus;
|
||||
use App\Enums\CouponType;
|
||||
use Filament\Infolists\Components\KeyValueEntry;
|
||||
use Filament\Infolists\Components\Section;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -22,11 +24,11 @@ class CouponInfolist
|
||||
TextEntry::make('status')
|
||||
->label(__('Status'))
|
||||
->badge()
|
||||
->formatStateUsing(fn ($state) => Str::headline($state)),
|
||||
->formatStateUsing(fn ($state) => static::formatEnumState($state)),
|
||||
TextEntry::make('type')
|
||||
->label(__('Discount type'))
|
||||
->badge()
|
||||
->formatStateUsing(fn ($state) => Str::headline($state)),
|
||||
->formatStateUsing(fn ($state) => static::formatEnumState($state)),
|
||||
TextEntry::make('amount')
|
||||
->label(__('Amount'))
|
||||
->formatStateUsing(fn ($state, $record) => $record?->type?->value === 'percentage'
|
||||
@@ -78,4 +80,21 @@ class CouponInfolist
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function formatEnumState(mixed $state): string
|
||||
{
|
||||
if ($state instanceof CouponType || $state instanceof CouponStatus) {
|
||||
return $state->label();
|
||||
}
|
||||
|
||||
if ($state instanceof \BackedEnum) {
|
||||
return Str::headline($state->value);
|
||||
}
|
||||
|
||||
if (is_string($state)) {
|
||||
return Str::headline($state);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user