From 8cb5d7e7cfd3a6fa32e7a41fbccfe18245822682 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 16 Oct 2025 20:43:36 +0700 Subject: [PATCH] refactor(voucher): remove is_active field and related logic from forms and views --- .../Studio/Loyalty/VouchersTable.php | 6 +--- .../Forms/Studio/Loyalty/VoucherForm.php | 10 ++---- app/Livewire/Studio/Loyalty/Tier.php | 6 ++-- .../Studio/Loyalty/Voucher/Create.php | 2 -- app/Livewire/Studio/Loyalty/Voucher/Edit.php | 2 -- app/Models/Voucher.php | 2 -- ...025_09_25_125559_create_vouchers_table.php | 2 -- .../studio/loyalty/voucher/form.blade.php | 35 +++++-------------- 8 files changed, 15 insertions(+), 50 deletions(-) diff --git a/app/Livewire/Datatable/Studio/Loyalty/VouchersTable.php b/app/Livewire/Datatable/Studio/Loyalty/VouchersTable.php index 67f6e71..5ebdc61 100644 --- a/app/Livewire/Datatable/Studio/Loyalty/VouchersTable.php +++ b/app/Livewire/Datatable/Studio/Loyalty/VouchersTable.php @@ -85,10 +85,6 @@ public function columns(): array }) ->html(), - Column::make('Akitf?', 'is_active') - ->format(fn ($value) => Blade::render(''.$value->label().'')) - ->html(), - Column::make('Aksi') ->label(function ($row) { $actions = ''; @@ -115,6 +111,6 @@ public function columns(): array public function builder(): Builder { - return Voucher::select('id', 'name', 'code', 'min_purchase', 'discount_amount', 'max_discount', 'quota', 'limit_per_user', 'start_date', 'end_date', 'is_active', 'type')->with('outlets'); + return Voucher::select('id', 'name', 'code', 'min_purchase', 'discount_amount', 'max_discount', 'quota', 'limit_per_user', 'start_date', 'end_date', 'type')->with('outlets'); } } diff --git a/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php b/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php index efa1e3e..88f45bd 100644 --- a/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php +++ b/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php @@ -2,7 +2,6 @@ namespace App\Livewire\Forms\Studio\Loyalty; -use App\Enums\IsActive; use App\Enums\VoucherType; use App\Models\Voucher; use App\Rules\UnsignedInteger; @@ -36,8 +35,6 @@ class VoucherForm extends Form public ?string $terms_conditions = null; - public string $is_active = '1'; - public array $outlet_ids = []; public function rules(): array @@ -70,10 +67,9 @@ public function rules(): array ], 'quota' => ['nullable', new UnsignedInteger], 'limit_per_user' => ['nullable', new UnsignedInteger], - 'start_date' => ['required', 'date'], + 'start_date' => ['required', 'date', 'after:yesterday'], 'end_date' => ['nullable', 'date', 'after_or_equal:start_date'], 'terms_conditions' => ['nullable', 'string'], - 'is_active' => ['required', Rule::in(IsActive::values())], 'outlet_ids' => ['required', 'array', 'min:1'], 'outlet_ids.*' => Rule::exists('outlets', 'id'), ]; @@ -93,7 +89,6 @@ public function validationAttributes(): array 'discount_amount' => 'Jumlah Diskon', 'start_date' => 'tanggal mulai', 'end_date' => 'tanggal selesai', - 'is_active' => 'aktif?', ]; } @@ -114,7 +109,6 @@ public function setVoucher(Voucher $voucher) $this->terms_conditions = $this->voucher->terms_conditions; $this->start_date = $this->voucher->start_date; $this->end_date = $this->voucher->end_date; - $this->is_active = $this->voucher->is_active->value; $this->outlet_ids = $this->voucher->outlets->pluck('id')->toArray(); } @@ -124,6 +118,7 @@ public function store() $this->validate(); $data = $this->prepareSavedData(); + $data = sanitizeIntegers($data, ['min_purchase', 'max_discount', 'quota', 'limit_per_user']); DB::transaction(function () use ($data) { $voucher = Voucher::create($data); @@ -158,7 +153,6 @@ private function prepareSavedData() 'terms_conditions' => $this->terms_conditions, 'start_date' => $this->start_date, 'end_date' => $this->end_date, - 'is_active' => $this->is_active, ]; } } diff --git a/app/Livewire/Studio/Loyalty/Tier.php b/app/Livewire/Studio/Loyalty/Tier.php index 58c2403..3c01c9f 100644 --- a/app/Livewire/Studio/Loyalty/Tier.php +++ b/app/Livewire/Studio/Loyalty/Tier.php @@ -31,7 +31,7 @@ public function mount() { $this->tiers = TierModel::orderBy('min_points', 'asc') ->get() - ->map(fn($tier) => [ + ->map(fn ($tier) => [ 'hash' => $tier->hash, 'name' => $tier->name, 'min_points' => currency($tier->min_points, ''), @@ -68,7 +68,7 @@ public function create() 'max_points' => currency($tier->max_points, ''), ]; - usort($tiers, fn($a, $b) => replaceCurrency($a['min_points']) <=> replaceCurrency($b['min_points'])); + usort($tiers, fn ($a, $b) => replaceCurrency($a['min_points']) <=> replaceCurrency($b['min_points'])); $this->tiers = $tiers; @@ -108,7 +108,7 @@ public function delete(TierModel $tier) $tier->delete(); // update array tiers - $tiers = array_values(array_filter($this->tiers, fn($item) => $item['hash'] !== $tier->hash)); + $tiers = array_values(array_filter($this->tiers, fn ($item) => $item['hash'] !== $tier->hash)); $this->tiers = $tiers; $this->toast('Tier berhasil dihapus.'); diff --git a/app/Livewire/Studio/Loyalty/Voucher/Create.php b/app/Livewire/Studio/Loyalty/Voucher/Create.php index fdd9799..8c606a6 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Create.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Create.php @@ -31,8 +31,6 @@ public function save() $this->form->store(); - $this->dispatch('refreshDatatable'); - $this->toast('Voucher berhasil ditambahkan.'); $this->redirectRoute('studio.loyalty.voucher.index', navigate: true); diff --git a/app/Livewire/Studio/Loyalty/Voucher/Edit.php b/app/Livewire/Studio/Loyalty/Voucher/Edit.php index 70964f7..3d5b02f 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Edit.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Edit.php @@ -34,8 +34,6 @@ public function save() $this->form->update(); - $this->dispatch('refreshDatatable'); - $this->toast('Voucher berhasil diperbarui.'); $this->redirectRoute('studio.loyalty.voucher.index', navigate: true); diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php index ec59d2f..735df56 100644 --- a/app/Models/Voucher.php +++ b/app/Models/Voucher.php @@ -2,7 +2,6 @@ namespace App\Models; -use App\Enums\IsActive; use App\Enums\VoucherType; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -25,7 +24,6 @@ protected function casts(): array 'max_discount' => 'int', 'quota' => 'int', 'limit_per_user' => 'int', - 'is_active' => IsActive::class, ]; } diff --git a/database/migrations/2025_09_25_125559_create_vouchers_table.php b/database/migrations/2025_09_25_125559_create_vouchers_table.php index e4b53f9..bbb80e1 100644 --- a/database/migrations/2025_09_25_125559_create_vouchers_table.php +++ b/database/migrations/2025_09_25_125559_create_vouchers_table.php @@ -1,6 +1,5 @@ unsignedInteger('limit_per_user')->nullable(); $table->date('start_date'); $table->date('end_date')->nullable(); - $table->enum('is_active', [IsActive::values()])->default(IsActive::ACTIVE)->comment(IsActive::comment()); $table->timestamp('created_at')->useCurrent(); $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate(); $table->softDeletes(); diff --git a/resources/views/livewire/studio/loyalty/voucher/form.blade.php b/resources/views/livewire/studio/loyalty/voucher/form.blade.php index 2c4cb45..9ff1fde 100644 --- a/resources/views/livewire/studio/loyalty/voucher/form.blade.php +++ b/resources/views/livewire/studio/loyalty/voucher/form.blade.php @@ -28,7 +28,8 @@ Kode * + wire:model.live.debounce.500ms="form.code" autocomplete="off" copyable + oninput="this.value = this.value.toUpperCase()" /> @@ -69,14 +70,11 @@ locale="id-ID" />
- - Syarat dan Ketentuan * - - - - + +
@@ -103,11 +101,11 @@ class="**:data-[slot=content]:min-h-[100px]!" /> @if ($form->type == \App\Enums\VoucherType::FIXED->value) Rp - @else - % @endif @@ -129,21 +127,6 @@ class="**:data-[slot=content]:min-h-[100px]!" /> @endif - - - Aktif? * - - @foreach (\App\Enums\IsActive::cases() as $item) - - {{ $item->label() }} - - @endforeach - - - - - Outlet *