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(),
|
->html(),
|
||||||
|
|
||||||
Column::make('Akitf?', 'is_active')
|
|
||||||
->format(fn ($value) => Blade::render('<flux:badge color="'.$value->color().'">'.$value->label().'</flux:badge>'))
|
|
||||||
->html(),
|
|
||||||
|
|
||||||
Column::make('Aksi')
|
Column::make('Aksi')
|
||||||
->label(function ($row) {
|
->label(function ($row) {
|
||||||
$actions = '';
|
$actions = '';
|
||||||
@ -115,6 +111,6 @@ public function columns(): array
|
|||||||
|
|
||||||
public function builder(): Builder
|
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;
|
namespace App\Livewire\Forms\Studio\Loyalty;
|
||||||
|
|
||||||
use App\Enums\IsActive;
|
|
||||||
use App\Enums\VoucherType;
|
use App\Enums\VoucherType;
|
||||||
use App\Models\Voucher;
|
use App\Models\Voucher;
|
||||||
use App\Rules\UnsignedInteger;
|
use App\Rules\UnsignedInteger;
|
||||||
@ -36,8 +35,6 @@ class VoucherForm extends Form
|
|||||||
|
|
||||||
public ?string $terms_conditions = null;
|
public ?string $terms_conditions = null;
|
||||||
|
|
||||||
public string $is_active = '1';
|
|
||||||
|
|
||||||
public array $outlet_ids = [];
|
public array $outlet_ids = [];
|
||||||
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
@ -70,10 +67,9 @@ public function rules(): array
|
|||||||
],
|
],
|
||||||
'quota' => ['nullable', new UnsignedInteger],
|
'quota' => ['nullable', new UnsignedInteger],
|
||||||
'limit_per_user' => ['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'],
|
'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
|
||||||
'terms_conditions' => ['nullable', 'string'],
|
'terms_conditions' => ['nullable', 'string'],
|
||||||
'is_active' => ['required', Rule::in(IsActive::values())],
|
|
||||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||||
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
||||||
];
|
];
|
||||||
@ -93,7 +89,6 @@ public function validationAttributes(): array
|
|||||||
'discount_amount' => 'Jumlah Diskon',
|
'discount_amount' => 'Jumlah Diskon',
|
||||||
'start_date' => 'tanggal mulai',
|
'start_date' => 'tanggal mulai',
|
||||||
'end_date' => 'tanggal selesai',
|
'end_date' => 'tanggal selesai',
|
||||||
'is_active' => 'aktif?',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +109,6 @@ public function setVoucher(Voucher $voucher)
|
|||||||
$this->terms_conditions = $this->voucher->terms_conditions;
|
$this->terms_conditions = $this->voucher->terms_conditions;
|
||||||
$this->start_date = $this->voucher->start_date;
|
$this->start_date = $this->voucher->start_date;
|
||||||
$this->end_date = $this->voucher->end_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();
|
$this->outlet_ids = $this->voucher->outlets->pluck('id')->toArray();
|
||||||
}
|
}
|
||||||
@ -124,6 +118,7 @@ public function store()
|
|||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
$data = $this->prepareSavedData();
|
$data = $this->prepareSavedData();
|
||||||
|
$data = sanitizeIntegers($data, ['min_purchase', 'max_discount', 'quota', 'limit_per_user']);
|
||||||
|
|
||||||
DB::transaction(function () use ($data) {
|
DB::transaction(function () use ($data) {
|
||||||
$voucher = Voucher::create($data);
|
$voucher = Voucher::create($data);
|
||||||
@ -158,7 +153,6 @@ private function prepareSavedData()
|
|||||||
'terms_conditions' => $this->terms_conditions,
|
'terms_conditions' => $this->terms_conditions,
|
||||||
'start_date' => $this->start_date,
|
'start_date' => $this->start_date,
|
||||||
'end_date' => $this->end_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')
|
$this->tiers = TierModel::orderBy('min_points', 'asc')
|
||||||
->get()
|
->get()
|
||||||
->map(fn($tier) => [
|
->map(fn ($tier) => [
|
||||||
'hash' => $tier->hash,
|
'hash' => $tier->hash,
|
||||||
'name' => $tier->name,
|
'name' => $tier->name,
|
||||||
'min_points' => currency($tier->min_points, ''),
|
'min_points' => currency($tier->min_points, ''),
|
||||||
@ -68,7 +68,7 @@ public function create()
|
|||||||
'max_points' => currency($tier->max_points, ''),
|
'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;
|
$this->tiers = $tiers;
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ public function delete(TierModel $tier)
|
|||||||
$tier->delete();
|
$tier->delete();
|
||||||
|
|
||||||
// update array tiers
|
// 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->tiers = $tiers;
|
||||||
|
|
||||||
$this->toast('Tier berhasil dihapus.');
|
$this->toast('Tier berhasil dihapus.');
|
||||||
|
|||||||
@ -31,8 +31,6 @@ public function save()
|
|||||||
|
|
||||||
$this->form->store();
|
$this->form->store();
|
||||||
|
|
||||||
$this->dispatch('refreshDatatable');
|
|
||||||
|
|
||||||
$this->toast('Voucher berhasil ditambahkan.');
|
$this->toast('Voucher berhasil ditambahkan.');
|
||||||
|
|
||||||
$this->redirectRoute('studio.loyalty.voucher.index', navigate: true);
|
$this->redirectRoute('studio.loyalty.voucher.index', navigate: true);
|
||||||
|
|||||||
@ -34,8 +34,6 @@ public function save()
|
|||||||
|
|
||||||
$this->form->update();
|
$this->form->update();
|
||||||
|
|
||||||
$this->dispatch('refreshDatatable');
|
|
||||||
|
|
||||||
$this->toast('Voucher berhasil diperbarui.');
|
$this->toast('Voucher berhasil diperbarui.');
|
||||||
|
|
||||||
$this->redirectRoute('studio.loyalty.voucher.index', navigate: true);
|
$this->redirectRoute('studio.loyalty.voucher.index', navigate: true);
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\IsActive;
|
|
||||||
use App\Enums\VoucherType;
|
use App\Enums\VoucherType;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -25,7 +24,6 @@ protected function casts(): array
|
|||||||
'max_discount' => 'int',
|
'max_discount' => 'int',
|
||||||
'quota' => 'int',
|
'quota' => 'int',
|
||||||
'limit_per_user' => 'int',
|
'limit_per_user' => 'int',
|
||||||
'is_active' => IsActive::class,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Enums\IsActive;
|
|
||||||
use App\Enums\VoucherType;
|
use App\Enums\VoucherType;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
@ -26,7 +25,6 @@ public function up(): void
|
|||||||
$table->unsignedInteger('limit_per_user')->nullable();
|
$table->unsignedInteger('limit_per_user')->nullable();
|
||||||
$table->date('start_date');
|
$table->date('start_date');
|
||||||
$table->date('end_date')->nullable();
|
$table->date('end_date')->nullable();
|
||||||
$table->enum('is_active', [IsActive::values()])->default(IsActive::ACTIVE)->comment(IsActive::comment());
|
|
||||||
$table->timestamp('created_at')->useCurrent();
|
$table->timestamp('created_at')->useCurrent();
|
||||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
||||||
$table->softDeletes();
|
$table->softDeletes();
|
||||||
|
|||||||
@ -28,7 +28,8 @@
|
|||||||
<flux:field>
|
<flux:field>
|
||||||
<flux:label>Kode <span class="text-red-500 ms-1">*</span></flux:label>
|
<flux:label>Kode <span class="text-red-500 ms-1">*</span></flux:label>
|
||||||
<flux:input placeholder="Masukkan kode voucher"
|
<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:error name="form.code" />
|
||||||
</flux:field>
|
</flux:field>
|
||||||
|
|
||||||
@ -69,14 +70,11 @@
|
|||||||
locale="id-ID" />
|
locale="id-ID" />
|
||||||
|
|
||||||
<div class="md:col-span-2">
|
<div class="md:col-span-2">
|
||||||
<flux:field>
|
<flux:editor label="Syarat dan Ketentuan"
|
||||||
<flux:label>Syarat dan Ketentuan <span class="text-red-500 ms-1">*</span>
|
wire:model.live.debounce.500ms="form.terms_conditions"
|
||||||
</flux:label>
|
placeholder="Masukkan syarat dan ketentuan" auotocomplete="off"
|
||||||
<flux:editor wire:model="form.terms_conditions"
|
class="**:data-[slot=content]:min-h-[100px]!" />
|
||||||
placeholder="Masukkan syarat dan ketentuan" auotocomplete="off"
|
<flux:error name="form.terms_conditions" />
|
||||||
class="**:data-[slot=content]:min-h-[100px]!" />
|
|
||||||
<flux:error name="form.terms_conditions" />
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</flux:card>
|
</flux:card>
|
||||||
@ -103,11 +101,11 @@ class="**:data-[slot=content]:min-h-[100px]!" />
|
|||||||
<flux:input.group>
|
<flux:input.group>
|
||||||
@if ($form->type == \App\Enums\VoucherType::FIXED->value)
|
@if ($form->type == \App\Enums\VoucherType::FIXED->value)
|
||||||
<flux:input.group.prefix>Rp</flux:input.group.prefix>
|
<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, ',')"
|
x-mask:dynamic="$money($input, ',')"
|
||||||
wire:model.live.debounce.500ms="form.discount_amount" autocomplete="off" />
|
wire:model.live.debounce.500ms="form.discount_amount" autocomplete="off" />
|
||||||
@else
|
@else
|
||||||
<flux:input placeholder="Masukkan Jumlah Diskon"
|
<flux:input placeholder="Masukkan jumlah diskon"
|
||||||
wire:model.live.debounce.500ms="form.discount_amount" autocomplete="off" />
|
wire:model.live.debounce.500ms="form.discount_amount" autocomplete="off" />
|
||||||
<flux:input.group.suffix>%</flux:input.group.suffix>
|
<flux:input.group.suffix>%</flux:input.group.suffix>
|
||||||
@endif
|
@endif
|
||||||
@ -129,21 +127,6 @@ class="**:data-[slot=content]:min-h-[100px]!" />
|
|||||||
@endif
|
@endif
|
||||||
</flux:card>
|
</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:card class="space-y-6 p-6">
|
||||||
<flux:field>
|
<flux:field>
|
||||||
<flux:label>Outlet <span class="text-red-500 ms-1">*</span></flux:label>
|
<flux:label>Outlet <span class="text-red-500 ms-1">*</span></flux:label>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user