diff --git a/app/Livewire/Datatable/Loyalty/VouchersTable.php b/app/Livewire/Datatable/Loyalty/VouchersTable.php index 34a68a0..66d8608 100644 --- a/app/Livewire/Datatable/Loyalty/VouchersTable.php +++ b/app/Livewire/Datatable/Loyalty/VouchersTable.php @@ -122,7 +122,6 @@ public function columns(): array if (auth()->user()->can('delete voucher')) { $actions .= view('components.actions.table.delete', [ 'id' => $row->hash, - 'deleteRoute' => route('studio.loyalty.voucher.delete', $row->hash), ])->render(); } diff --git a/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php b/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php index d04f778..200fc84 100644 --- a/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php +++ b/app/Livewire/Forms/Studio/Loyalty/VoucherForm.php @@ -125,9 +125,9 @@ public function store(): void $data = $this->prepareSavedData(); - foreach (['min_purchase', 'max_discount', 'quota', 'limit_per_user'] as $field) { - if ($this->$field === '') { - $this->$field = null; + foreach (['min_purchase', 'max_discount', 'quota', 'limit_per_user'] as $key) { + if ($data[$key] === '') { + $data[$key] = null; } } @@ -163,7 +163,7 @@ private function prepareSavedData(): array 'min_purchase' => replaceCurrency($this->min_purchase), 'max_discount' => $this->type == VoucherType::PERCENTAGE->value ? replaceCurrency($this->max_discount) : null, 'quota' => $this->quota, - 'available_count' => $this->quota ?? 0, + 'available_count' => empty($this->quota) ? 0 : $this->quota, 'limit_per_user' => $this->limit_per_user, 'summary' => $this->summary, 'start_date' => $this->start_date, diff --git a/app/Livewire/Studio/Loyalty/Voucher/Create.php b/app/Livewire/Studio/Loyalty/Voucher/Create.php index 8c2523c..d1ad3ee 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Create.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Create.php @@ -10,6 +10,7 @@ use App\Traits\WithOutletSelector; use App\Traits\WithToast; use App\Traits\WithUpdatedData; +use Illuminate\Contracts\View\View; use Livewire\Attributes\Title; use Livewire\Component; @@ -22,12 +23,12 @@ class Create extends Component public array $outlets; - public function mount() + public function mount(): void { $this->outlets = Outlet::pluck('name', 'id')->toArray(); } - public function save() + public function save(): void { $this->canOrAbort('create voucher'); @@ -41,12 +42,12 @@ public function save() ], ); - $this->toast('Voucher berhasil ditambahkan.'); - - $this->redirectRoute('studio.loyalty.voucher.index'); + $this->redirectRoute('studio.loyalty.voucher.index', [ + 'notification' => 'Voucher berhasil ditambahkan.', + ], navigate: true); } - public function render() + public function render(): View { return view('livewire.studio.loyalty.voucher.form', [ 'pageTitle' => 'Tambah Voucher', diff --git a/app/Livewire/Studio/Loyalty/Voucher/Edit.php b/app/Livewire/Studio/Loyalty/Voucher/Edit.php index c8fcd3a..8e60390 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Edit.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Edit.php @@ -9,6 +9,7 @@ use App\Traits\WithOutletSelector; use App\Traits\WithToast; use App\Traits\WithUpdatedData; +use Illuminate\Contracts\View\View; use Livewire\Attributes\Title; use Livewire\Component; @@ -21,25 +22,25 @@ class Edit extends Component public array $outlets; - public function mount(Voucher $voucher) + public function mount(Voucher $voucher): void { $this->form->setVoucher($voucher); $this->outlets = Outlet::pluck('name', 'id')->toArray(); } - public function save() + public function save(): void { $this->canOrAbort('update voucher'); $this->form->update(); - $this->toast('Voucher berhasil diperbarui.'); - - $this->redirectRoute('studio.loyalty.voucher.index'); + $this->redirectRoute('studio.loyalty.voucher.index', [ + 'notification' => 'Voucher berhasil diperbarui.', + ], navigate: true); } - public function render() + public function render(): View { return view('livewire.studio.loyalty.voucher.form', [ 'pageTitle' => 'Ubah Voucher', diff --git a/app/Livewire/Studio/Loyalty/Voucher/Index.php b/app/Livewire/Studio/Loyalty/Voucher/Index.php index 840f9ff..815edb5 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Index.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Index.php @@ -4,21 +4,35 @@ use App\Models\Voucher; use App\Traits\Notification\WithSubscribeNotification; +use App\Traits\WithAuthorization; use App\Traits\WithConfirmation; use App\Traits\WithToast; use Flux\Flux; +use Illuminate\Contracts\View\View; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Voucher')] class Index extends Component { - use WithConfirmation, WithSubscribeNotification, WithToast; + use WithAuthorization, WithConfirmation, WithSubscribeNotification, WithToast; public array $stats = []; - public function mount() + public function mount(): void { + $hasNotification = request()->get('notification'); + + if ($hasNotification) { + $this->js(<<<'JS' + const url = new URL(window.location); + url.search = ''; + window.history.replaceState({}, '', url); + JS); + + $this->toast($hasNotification); + } + $this->stats = [ [ 'title' => 'Total Voucher', @@ -39,18 +53,19 @@ public function mount() ]; } - public function delete(Voucher $voucher) + public function delete(Voucher $voucher): void { + $this->canOrAbbort('delete voucher'); + $voucher->delete(); $this->dispatch('refreshDatatable'); $this->toast('Voucher berhasil dihapus.'); - Flux::modals()->close(); } - public function render() + public function render(): View { return view('livewire.studio.loyalty.voucher.index', [ 'pageTitle' => 'Voucher',