refactor(voucher): remove is_active field and related logic from forms and views
This commit is contained in:
parent
d622dba2f4
commit
8cb5d7e7cf
@ -85,10 +85,6 @@ public function columns(): array
|
||||
})
|
||||
->html(),
|
||||
|
||||
Column::make('Akitf?', 'is_active')
|
||||
->format(fn ($value) => Blade::render('<flux:badge color="'.$value->color().'">'.$value->label().'</flux:badge>'))
|
||||
->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');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.');
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\VoucherType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@ -26,7 +25,6 @@ public function up(): void
|
||||
$table->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();
|
||||
|
||||
@ -28,7 +28,8 @@
|
||||
<flux:field>
|
||||
<flux:label>Kode <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input placeholder="Masukkan kode voucher"
|
||||
wire:model.live.debounce.500ms="form.code" autocomplete="off" copyable />
|
||||
wire:model.live.debounce.500ms="form.code" autocomplete="off" copyable
|
||||
oninput="this.value = this.value.toUpperCase()" />
|
||||
<flux:error name="form.code" />
|
||||
</flux:field>
|
||||
|
||||
@ -69,14 +70,11 @@
|
||||
locale="id-ID" />
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<flux:field>
|
||||
<flux:label>Syarat dan Ketentuan <span class="text-red-500 ms-1">*</span>
|
||||
</flux:label>
|
||||
<flux:editor wire:model="form.terms_conditions"
|
||||
placeholder="Masukkan syarat dan ketentuan" auotocomplete="off"
|
||||
class="**:data-[slot=content]:min-h-[100px]!" />
|
||||
<flux:error name="form.terms_conditions" />
|
||||
</flux:field>
|
||||
<flux:editor label="Syarat dan Ketentuan"
|
||||
wire:model.live.debounce.500ms="form.terms_conditions"
|
||||
placeholder="Masukkan syarat dan ketentuan" auotocomplete="off"
|
||||
class="**:data-[slot=content]:min-h-[100px]!" />
|
||||
<flux:error name="form.terms_conditions" />
|
||||
</div>
|
||||
</div>
|
||||
</flux:card>
|
||||
@ -103,11 +101,11 @@ class="**:data-[slot=content]:min-h-[100px]!" />
|
||||
<flux:input.group>
|
||||
@if ($form->type == \App\Enums\VoucherType::FIXED->value)
|
||||
<flux:input.group.prefix>Rp</flux:input.group.prefix>
|
||||
<flux:input placeholder="Masukkan Jumlah Diskon"
|
||||
<flux:input placeholder="Masukkan jumlah diskon"
|
||||
x-mask:dynamic="$money($input, ',')"
|
||||
wire:model.live.debounce.500ms="form.discount_amount" autocomplete="off" />
|
||||
@else
|
||||
<flux:input placeholder="Masukkan Jumlah Diskon"
|
||||
<flux:input placeholder="Masukkan jumlah diskon"
|
||||
wire:model.live.debounce.500ms="form.discount_amount" autocomplete="off" />
|
||||
<flux:input.group.suffix>%</flux:input.group.suffix>
|
||||
@endif
|
||||
@ -129,21 +127,6 @@ class="**:data-[slot=content]:min-h-[100px]!" />
|
||||
@endif
|
||||
</flux:card>
|
||||
|
||||
<flux:card class="space-y-6 p-6">
|
||||
<flux:field>
|
||||
<flux:label>Aktif? <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:radio.group wire:model.live="form.is_active" variant="buttons"
|
||||
class="w-full *:flex-1">
|
||||
@foreach (\App\Enums\IsActive::cases() as $item)
|
||||
<flux:radio value="{{ $item->value }}">
|
||||
{{ $item->label() }}
|
||||
</flux:radio>
|
||||
@endforeach
|
||||
</flux:radio.group>
|
||||
<flux:error name="form.is_active" />
|
||||
</flux:field>
|
||||
</flux:card>
|
||||
|
||||
<flux:card class="space-y-6 p-6">
|
||||
<flux:field>
|
||||
<flux:label>Outlet <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user