From 700aa8f260b218661ab6dcba61d888a4147c2d1c Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 2 Oct 2025 20:13:03 +0700 Subject: [PATCH] feat(trait): membuat trait untuk toast agar reusable -mengubah cara menulis toast diubah menjadi memanggil toast yang ada --- app/Livewire/Auth/Login.php | 20 ++++------------ app/Livewire/Auth/Register.php | 14 +++++------ app/Livewire/Studio/Catalog/Bottle/Create.php | 11 +++------ app/Livewire/Studio/Catalog/Bottle/Edit.php | 11 +++------ app/Livewire/Studio/Catalog/Bottle/Index.php | 9 +++----- app/Livewire/Studio/Catalog/Brand.php | 23 ++++--------------- app/Livewire/Studio/Catalog/Category.php | 23 ++++--------------- .../Studio/Catalog/Perfume/Create.php | 11 +++------ app/Livewire/Studio/Catalog/Perfume/Edit.php | 11 +++------ app/Livewire/Studio/Catalog/Perfume/Index.php | 9 +++----- .../Studio/Catalog/Product/Create.php | 11 +++------ app/Livewire/Studio/Catalog/Product/Edit.php | 11 +++------ app/Livewire/Studio/Catalog/Product/Index.php | 9 +++----- app/Livewire/Studio/Finance/Expense.php | 23 ++++--------------- app/Livewire/Studio/Loyalty/Customer.php | 23 ++++--------------- app/Livewire/Studio/Loyalty/Tier.php | 23 ++++--------------- .../Studio/Loyalty/Voucher/Create.php | 11 +++------ app/Livewire/Studio/Loyalty/Voucher/Edit.php | 11 +++------ app/Livewire/Studio/Loyalty/Voucher/Index.php | 9 +++----- app/Livewire/Studio/Master/Outlet/Create.php | 11 +++------ app/Livewire/Studio/Master/Outlet/Edit.php | 11 +++------ app/Livewire/Studio/Master/Outlet/Index.php | 9 +++----- app/Livewire/Studio/Master/User/Create.php | 11 +++------ app/Livewire/Studio/Master/User/Edit.php | 11 +++------ app/Livewire/Studio/Master/User/Index.php | 9 +++----- app/Livewire/Studio/Setting/Account.php | 11 +++------ app/Livewire/Studio/Setting/Password.php | 18 ++++----------- app/Livewire/Studio/Setting/Profile.php | 11 +++------ app/Traits/WithToast.php | 18 +++++++++++++++ 29 files changed, 118 insertions(+), 275 deletions(-) create mode 100644 app/Traits/WithToast.php diff --git a/app/Livewire/Auth/Login.php b/app/Livewire/Auth/Login.php index bcd6b1c..25bd03e 100644 --- a/app/Livewire/Auth/Login.php +++ b/app/Livewire/Auth/Login.php @@ -3,8 +3,8 @@ namespace App\Livewire\Auth; use App\Enums\UserStatus; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Layout; use Livewire\Attributes\Validate; use Livewire\Component; @@ -14,7 +14,7 @@ ])] class Login extends Component { - use WithUpdatedData; + use WithToast, WithUpdatedData; #[Validate(['required', 'string'], attribute: 'nama pengguna atau alamat surel')] public string $login = ''; @@ -31,13 +31,7 @@ public function auth() if (! auth()->attempt( [$identifier => $this->login, 'password' => $this->password], )) { - - Flux::toast( - heading: 'Gagal', - text: 'Nama pengguna, email atau kata sandi salah.', - variant: 'danger', - duration: 3000 - ); + $this->toast('Nama pengguna, email atau kata sandi salah.', 'Gagal', 'danger'); return; } @@ -48,14 +42,10 @@ public function auth() return; } - Flux::toast( - heading: 'Berhasil', - text: 'Selamat datang, '.auth()->user()?->employee?->full_name.'. Semoga harimu menyenangkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Selamat datang, '.auth()->user()?->employee?->full_name.'. Semoga harimu menyenangkan.'); session()->regenerate(); + $this->redirectIntended('/studio/dashboard/overview', navigate: true); } diff --git a/app/Livewire/Auth/Register.php b/app/Livewire/Auth/Register.php index 1152b1d..d7093e3 100644 --- a/app/Livewire/Auth/Register.php +++ b/app/Livewire/Auth/Register.php @@ -2,8 +2,9 @@ namespace App\Livewire\Auth; -use App\Livewire\Forms\RegisterForm; -use Flux\Flux; +use App\Livewire\Forms\Auth\RegisterForm; +use App\Traits\WithToast; +use App\Traits\WithUpdatedData; use Illuminate\Support\Str; use Livewire\Attributes\Layout; use Livewire\Component; @@ -13,6 +14,8 @@ ])] class Register extends Component { + use WithToast, WithUpdatedData; + public RegisterForm $form; public array $steps = []; @@ -75,12 +78,7 @@ public function register() { $this->form->auth(); - Flux::toast( - heading: 'Berhasil', - text: 'Selamat, akun Anda berhasil didaftarkan. Silakan cek email Anda untuk melakukan verifikasi.', - variant: 'success', - duration: 3000 - ); + $this->toast('Selamat, akun Anda berhasil didaftarkan. Silakan cek email Anda untuk melakukan verifikasi.'); $this->redirectIntended('/customer/dashboard/overview', navigate: true); } diff --git a/app/Livewire/Studio/Catalog/Bottle/Create.php b/app/Livewire/Studio/Catalog/Bottle/Create.php index c953a98..f02a329 100644 --- a/app/Livewire/Studio/Catalog/Bottle/Create.php +++ b/app/Livewire/Studio/Catalog/Bottle/Create.php @@ -5,15 +5,15 @@ use App\Livewire\Forms\Studio\Catalog\BottleForm; use App\Models\Outlet; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Tambah Botol')] class Create extends Component { - use WithOutletSelector, WithUpdatedData; + use WithOutletSelector, WithToast, WithUpdatedData; public BottleForm $form; @@ -30,12 +30,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Botol berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Botol berhasil ditambahkan.'); $this->redirectRoute('studio.catalog.bottle.index', navigate: true); } diff --git a/app/Livewire/Studio/Catalog/Bottle/Edit.php b/app/Livewire/Studio/Catalog/Bottle/Edit.php index e8b146a..bb75718 100644 --- a/app/Livewire/Studio/Catalog/Bottle/Edit.php +++ b/app/Livewire/Studio/Catalog/Bottle/Edit.php @@ -6,15 +6,15 @@ use App\Models\Bottle; use App\Models\Outlet; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Ubah Botol')] class Edit extends Component { - use WithOutletSelector, WithUpdatedData; + use WithOutletSelector, WithToast, WithUpdatedData; public BottleForm $form; @@ -33,12 +33,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Botol berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Botol berhasil diperbarui.'); $this->redirectRoute('studio.catalog.bottle.index', navigate: true); } diff --git a/app/Livewire/Studio/Catalog/Bottle/Index.php b/app/Livewire/Studio/Catalog/Bottle/Index.php index ec466ea..698ea3a 100644 --- a/app/Livewire/Studio/Catalog/Bottle/Index.php +++ b/app/Livewire/Studio/Catalog/Bottle/Index.php @@ -4,6 +4,7 @@ use App\Models\Bottle; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; @@ -11,7 +12,7 @@ #[Title('Botol')] class Index extends Component { - use WithConfirmation; + use WithConfirmation, WithToast; public function delete(Bottle $bottle) { @@ -19,11 +20,7 @@ public function delete(Bottle $bottle) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Botol berhasil dihapus.', - variant: 'success', - ); + $this->toast('Botol berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Catalog/Brand.php b/app/Livewire/Studio/Catalog/Brand.php index 740f2b1..6ddfcf6 100644 --- a/app/Livewire/Studio/Catalog/Brand.php +++ b/app/Livewire/Studio/Catalog/Brand.php @@ -6,6 +6,7 @@ use App\Models\Brand as BrandModel; use App\Traits\WithCloseModal; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; use Flux\Flux; use Livewire\Attributes\On; @@ -15,7 +16,7 @@ #[Title('Merek')] class Brand extends Component { - use WithCloseModal, WithConfirmation, WithUpdatedData; + use WithCloseModal, WithConfirmation, WithToast, WithUpdatedData; public BrandForm $form; @@ -43,12 +44,7 @@ public function create() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Merek berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Merek berhasil ditambahkan.'); Flux::modals()->close(); } @@ -59,12 +55,7 @@ public function update() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Merek berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Merek berhasil diperbarui.'); Flux::modals()->close(); } @@ -77,11 +68,7 @@ public function delete(BrandModel $brand) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Merek berhasil dihapus.', - variant: 'success', - ); + $this->toast('Merek berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Catalog/Category.php b/app/Livewire/Studio/Catalog/Category.php index 7b961d0..f6ffa26 100644 --- a/app/Livewire/Studio/Catalog/Category.php +++ b/app/Livewire/Studio/Catalog/Category.php @@ -6,6 +6,7 @@ use App\Models\Category as CategoryModel; use App\Traits\WithCloseModal; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; use Flux\Flux; use Livewire\Attributes\On; @@ -15,7 +16,7 @@ #[Title('Kategori')] class Category extends Component { - use WithCloseModal, WithConfirmation, WithUpdatedData; + use WithCloseModal, WithConfirmation, WithToast, WithUpdatedData; public CategoryForm $form; @@ -43,12 +44,7 @@ public function create() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Kategori berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Kategori berhasil ditambahkan.'); Flux::modals()->close(); } @@ -59,12 +55,7 @@ public function update() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Kategori berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Kategori berhasil diperbarui.'); Flux::modals()->close(); } @@ -77,11 +68,7 @@ public function delete(CategoryModel $category) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Kategori berhasil dihapus.', - variant: 'success', - ); + $this->toast('Kategori berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Catalog/Perfume/Create.php b/app/Livewire/Studio/Catalog/Perfume/Create.php index 4581133..867aac7 100644 --- a/app/Livewire/Studio/Catalog/Perfume/Create.php +++ b/app/Livewire/Studio/Catalog/Perfume/Create.php @@ -8,15 +8,15 @@ use App\Models\Outlet; use App\Traits\WithCategorySelector; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Tambah Parfum')] class Create extends Component { - use WithCategorySelector, WithOutletSelector, WithUpdatedData; + use WithCategorySelector, WithOutletSelector, WithToast, WithUpdatedData; public PerfumeForm $form; @@ -41,12 +41,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Parfum berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Parfum berhasil ditambahkan.'); $this->redirectRoute('studio.catalog.perfume.index', navigate: true); } diff --git a/app/Livewire/Studio/Catalog/Perfume/Edit.php b/app/Livewire/Studio/Catalog/Perfume/Edit.php index 66dd289..4e731d9 100644 --- a/app/Livewire/Studio/Catalog/Perfume/Edit.php +++ b/app/Livewire/Studio/Catalog/Perfume/Edit.php @@ -9,15 +9,15 @@ use App\Models\Perfume; use App\Traits\WithCategorySelector; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Ubah Parfum')] class Edit extends Component { - use WithCategorySelector, WithOutletSelector, WithUpdatedData; + use WithCategorySelector, WithOutletSelector, WithToast, WithUpdatedData; public PerfumeForm $form; @@ -44,12 +44,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Parfum berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Parfum berhasil diperbarui.'); $this->redirectRoute('studio.catalog.perfume.index', navigate: true); } diff --git a/app/Livewire/Studio/Catalog/Perfume/Index.php b/app/Livewire/Studio/Catalog/Perfume/Index.php index cab80bc..2cb84cd 100644 --- a/app/Livewire/Studio/Catalog/Perfume/Index.php +++ b/app/Livewire/Studio/Catalog/Perfume/Index.php @@ -4,6 +4,7 @@ use App\Models\Perfume; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; @@ -11,7 +12,7 @@ #[Title('Parfum')] class Index extends Component { - use WithConfirmation; + use WithConfirmation, WithToast; public function delete(Perfume $perfume) { @@ -19,11 +20,7 @@ public function delete(Perfume $perfume) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Parfum berhasil dihapus.', - variant: 'success', - ); + $this->toast('Parfum berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Catalog/Product/Create.php b/app/Livewire/Studio/Catalog/Product/Create.php index a838094..35576fc 100644 --- a/app/Livewire/Studio/Catalog/Product/Create.php +++ b/app/Livewire/Studio/Catalog/Product/Create.php @@ -5,15 +5,15 @@ use App\Livewire\Forms\Studio\Catalog\ProductForm; use App\Models\Outlet; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Tambah Produk')] class Create extends Component { - use WithOutletSelector, WithUpdatedData; + use WithOutletSelector, WithToast, WithUpdatedData; public ProductForm $form; @@ -30,12 +30,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Produk berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Produk berhasil ditambahkan.'); $this->redirectRoute('studio.catalog.product.index', navigate: true); } diff --git a/app/Livewire/Studio/Catalog/Product/Edit.php b/app/Livewire/Studio/Catalog/Product/Edit.php index 7eabeb0..5f3a251 100644 --- a/app/Livewire/Studio/Catalog/Product/Edit.php +++ b/app/Livewire/Studio/Catalog/Product/Edit.php @@ -6,15 +6,15 @@ use App\Models\Outlet; use App\Models\Product; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Ubah Produk')] class Edit extends Component { - use WithOutletSelector, WithUpdatedData; + use WithOutletSelector, WithToast, WithUpdatedData; public ProductForm $form; @@ -33,12 +33,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Produk berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Produk berhasil diperbarui.'); $this->redirectRoute('studio.catalog.product.index', navigate: true); } diff --git a/app/Livewire/Studio/Catalog/Product/Index.php b/app/Livewire/Studio/Catalog/Product/Index.php index 1fdb424..07c70d6 100644 --- a/app/Livewire/Studio/Catalog/Product/Index.php +++ b/app/Livewire/Studio/Catalog/Product/Index.php @@ -4,6 +4,7 @@ use App\Models\Product; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; @@ -11,7 +12,7 @@ #[Title('Produk')] class Index extends Component { - use WithConfirmation; + use WithConfirmation, WithToast; public function delete(Product $product) { @@ -19,11 +20,7 @@ public function delete(Product $product) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Produk berhasil dihapus.', - variant: 'success', - ); + $this->toast('Produk berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Finance/Expense.php b/app/Livewire/Studio/Finance/Expense.php index d6afd73..5dd778f 100644 --- a/app/Livewire/Studio/Finance/Expense.php +++ b/app/Livewire/Studio/Finance/Expense.php @@ -6,6 +6,7 @@ use App\Models\Expense as ExpenseModel; use App\Traits\WithCloseModal; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; use Flux\Flux; use Livewire\Attributes\On; @@ -15,7 +16,7 @@ #[Title('Pengeluaran')] class Expense extends Component { - use WithCloseModal, WithConfirmation, WithUpdatedData; + use WithCloseModal, WithConfirmation, WithToast, WithUpdatedData; public ExpenseForm $form; @@ -43,12 +44,7 @@ public function create() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Pengeluaran berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Pengeluaran berhasil ditambahkan.'); Flux::modals()->close(); } @@ -59,12 +55,7 @@ public function update() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Pengeluaran berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Pengeluaran berhasil diperbarui.'); Flux::modals()->close(); } @@ -75,11 +66,7 @@ public function delete(ExpenseModel $expense) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Pengeluaran berhasil dihapus.', - variant: 'success', - ); + $this->toast('Pengeluaran berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Loyalty/Customer.php b/app/Livewire/Studio/Loyalty/Customer.php index c3e826d..4cb9c55 100644 --- a/app/Livewire/Studio/Loyalty/Customer.php +++ b/app/Livewire/Studio/Loyalty/Customer.php @@ -6,6 +6,7 @@ use App\Models\Customer as CustomerModel; use App\Traits\WithCloseModal; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; use Flux\Flux; use Livewire\Attributes\On; @@ -15,7 +16,7 @@ #[Title('Customer')] class Customer extends Component { - use WithCloseModal, WithConfirmation, WithUpdatedData; + use WithCloseModal, WithConfirmation, WithToast, WithUpdatedData; public CustomerForm $form; @@ -43,12 +44,7 @@ public function create() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Customer berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Customer berhasil ditambahkan.'); Flux::modals()->close(); } @@ -59,12 +55,7 @@ public function update() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Customer berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Customer berhasil diperbarui.'); Flux::modals()->close(); } @@ -75,11 +66,7 @@ public function delete(CustomerModel $customer) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Customer berhasil dihapus.', - variant: 'success', - ); + $this->toast('Customer berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Loyalty/Tier.php b/app/Livewire/Studio/Loyalty/Tier.php index 348cdf1..833ba84 100644 --- a/app/Livewire/Studio/Loyalty/Tier.php +++ b/app/Livewire/Studio/Loyalty/Tier.php @@ -6,6 +6,7 @@ use App\Models\Tier as TierModel; use App\Traits\WithCloseModal; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; use Flux\Flux; use Livewire\Attributes\On; @@ -15,7 +16,7 @@ #[Title('Tier')] class Tier extends Component { - use WithCloseModal, WithConfirmation, WithUpdatedData; + use WithCloseModal, WithConfirmation, WithToast, WithUpdatedData; public TierForm $form; @@ -43,12 +44,7 @@ public function create() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Tier berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Tier berhasil ditambahkan.'); Flux::modals()->close(); } @@ -59,12 +55,7 @@ public function update() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Tier berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Tier berhasil diperbarui.'); Flux::modals()->close(); } @@ -75,11 +66,7 @@ public function delete(TierModel $tier) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Tier berhasil dihapus.', - variant: 'success', - ); + $this->toast('Tier berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Loyalty/Voucher/Create.php b/app/Livewire/Studio/Loyalty/Voucher/Create.php index 31f3fcf..ec15454 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Create.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Create.php @@ -5,15 +5,15 @@ use App\Livewire\Forms\Studio\Loyalty\VoucherForm; use App\Models\Outlet; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Tambah Voucher')] class Create extends Component { - use WithOutletSelector, WithUpdatedData; + use WithOutletSelector, WithToast, WithUpdatedData; public VoucherForm $form; @@ -30,12 +30,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Voucher berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $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 fa12f75..125737d 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Edit.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Edit.php @@ -6,15 +6,15 @@ use App\Models\Outlet; use App\Models\Voucher; use App\Traits\WithOutletSelector; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Ubah Voucher')] class Edit extends Component { - use WithOutletSelector, WithUpdatedData; + use WithOutletSelector, WithToast, WithUpdatedData; public VoucherForm $form; @@ -33,12 +33,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Voucher berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Voucher berhasil diperbarui.'); $this->redirectRoute('studio.loyalty.voucher.index', navigate: true); } diff --git a/app/Livewire/Studio/Loyalty/Voucher/Index.php b/app/Livewire/Studio/Loyalty/Voucher/Index.php index a16d084..a6cf55b 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Index.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Index.php @@ -4,6 +4,7 @@ use App\Models\Voucher; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; @@ -11,7 +12,7 @@ #[Title('Voucher')] class Index extends Component { - use WithConfirmation; + use WithConfirmation, WithToast; public function delete(Voucher $voucher) { @@ -19,11 +20,7 @@ public function delete(Voucher $voucher) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Voucher berhasil dihapus.', - variant: 'success', - ); + $this->toast('Voucher berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Master/Outlet/Create.php b/app/Livewire/Studio/Master/Outlet/Create.php index 0485f9e..66b81d4 100644 --- a/app/Livewire/Studio/Master/Outlet/Create.php +++ b/app/Livewire/Studio/Master/Outlet/Create.php @@ -5,15 +5,15 @@ use App\Enums\Day; use App\Livewire\Forms\Studio\Master\OutletForm; use App\Traits\Outlet\WithFacilityHandler; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Tambah Outlet')] class Create extends Component { - use WithFacilityHandler, WithUpdatedData; + use WithFacilityHandler, WithToast, WithUpdatedData; public OutletForm $form; @@ -35,12 +35,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Outlet berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Outlet berhasil ditambahkan.'); $this->redirectRoute('studio.master.outlet.index', navigate: true); } diff --git a/app/Livewire/Studio/Master/Outlet/Edit.php b/app/Livewire/Studio/Master/Outlet/Edit.php index 217b54f..03ae298 100644 --- a/app/Livewire/Studio/Master/Outlet/Edit.php +++ b/app/Livewire/Studio/Master/Outlet/Edit.php @@ -6,15 +6,15 @@ use App\Livewire\Forms\Studio\Master\OutletForm; use App\Models\Outlet; use App\Traits\Outlet\WithFacilityHandler; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Ubah Outlet')] class Edit extends Component { - use WithFacilityHandler, WithUpdatedData; + use WithFacilityHandler, WithToast, WithUpdatedData; public OutletForm $form; @@ -33,12 +33,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Outlet berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Outlet berhasil diperbarui.'); $this->redirectRoute('studio.master.outlet.index', navigate: true); } diff --git a/app/Livewire/Studio/Master/Outlet/Index.php b/app/Livewire/Studio/Master/Outlet/Index.php index 5989d5e..6e28efe 100644 --- a/app/Livewire/Studio/Master/Outlet/Index.php +++ b/app/Livewire/Studio/Master/Outlet/Index.php @@ -4,6 +4,7 @@ use App\Models\Outlet; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; @@ -11,7 +12,7 @@ #[Title('Outlet')] class Index extends Component { - use WithConfirmation; + use WithConfirmation, WithToast; public function delete(Outlet $outlet) { @@ -19,11 +20,7 @@ public function delete(Outlet $outlet) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Outlet berhasil dihapus.', - variant: 'success', - ); + $this->toast('Outlet berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Master/User/Create.php b/app/Livewire/Studio/Master/User/Create.php index 6fc7088..446837a 100644 --- a/app/Livewire/Studio/Master/User/Create.php +++ b/app/Livewire/Studio/Master/User/Create.php @@ -3,15 +3,15 @@ namespace App\Livewire\Studio\Master\User; use App\Livewire\Forms\Studio\Master\UserForm; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Tambah Pegawai')] class Create extends Component { - use WithUpdatedData; + use WithToast, WithUpdatedData; public UserForm $form; @@ -21,12 +21,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Pegawai berhasil ditambahkan.', - variant: 'success', - duration: 3000 - ); + $this->toast('Pegawai berhasil ditambahkan.'); $this->redirectRoute('studio.master.user.index', navigate: true); } diff --git a/app/Livewire/Studio/Master/User/Edit.php b/app/Livewire/Studio/Master/User/Edit.php index 9ef1425..5625156 100644 --- a/app/Livewire/Studio/Master/User/Edit.php +++ b/app/Livewire/Studio/Master/User/Edit.php @@ -4,15 +4,15 @@ use App\Livewire\Forms\Studio\Master\UserForm; use App\Models\User; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Ubah Pegawai')] class Edit extends Component { - use WithUpdatedData; + use WithToast, WithUpdatedData; public UserForm $form; @@ -27,12 +27,7 @@ public function save() $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Pegawai berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Pegawai berhasil diperbarui.'); $this->redirectRoute('studio.master.user.index', navigate: true); } diff --git a/app/Livewire/Studio/Master/User/Index.php b/app/Livewire/Studio/Master/User/Index.php index c26bb93..2ea6c2f 100644 --- a/app/Livewire/Studio/Master/User/Index.php +++ b/app/Livewire/Studio/Master/User/Index.php @@ -4,6 +4,7 @@ use App\Models\User; use App\Traits\WithConfirmation; +use App\Traits\WithToast; use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; @@ -11,7 +12,7 @@ #[Title('Pegawai')] class Index extends Component { - use WithConfirmation; + use WithConfirmation, WithToast; public function delete(User $user) { @@ -19,11 +20,7 @@ public function delete(User $user) $this->dispatch('refreshDatatable'); - Flux::toast( - heading: 'Berhasil', - text: 'Pegawai berhasil dihapus.', - variant: 'success', - ); + $this->toast('Pegawai berhasil dihapus.'); Flux::modals()->close(); } diff --git a/app/Livewire/Studio/Setting/Account.php b/app/Livewire/Studio/Setting/Account.php index 8b150f7..c7daa94 100644 --- a/app/Livewire/Studio/Setting/Account.php +++ b/app/Livewire/Studio/Setting/Account.php @@ -4,15 +4,15 @@ use App\Livewire\Forms\Studio\Setting\AccountForm; use App\Models\User; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Akun')] class Account extends Component { - use WithUpdatedData; + use WithToast, WithUpdatedData; public AccountForm $form; @@ -25,12 +25,7 @@ public function update() { $this->form->update(); - Flux::toast( - heading: 'Berhasil', - text: 'Akun berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Akun berhasil diperbarui.'); } public function render() diff --git a/app/Livewire/Studio/Setting/Password.php b/app/Livewire/Studio/Setting/Password.php index 9e24fd0..84ed9f5 100644 --- a/app/Livewire/Studio/Setting/Password.php +++ b/app/Livewire/Studio/Setting/Password.php @@ -4,8 +4,8 @@ use App\Livewire\Forms\Studio\Setting\PasswordForm; use App\Models\User; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Illuminate\Support\Facades\Hash; use Livewire\Attributes\Title; use Livewire\Component; @@ -13,7 +13,7 @@ #[Title('Kata Sandi')] class Password extends Component { - use WithUpdatedData; + use WithToast, WithUpdatedData; public PasswordForm $form; @@ -25,12 +25,7 @@ public function mount(User $user) public function update() { if (! Hash::check($this->form->current_password, $this->form->user->password)) { - Flux::toast( - heading: 'Gagal', - text: 'Kata sandi yang Anda masukkan tidak sesuai dengan kata sandi saat ini.', - variant: 'danger', - duration: 3000 - ); + $this->toast('Kata sandi yang Anda masukkan tidak sesuai dengan kata sandi saat ini.', 'Gagal', 'danger'); return; } @@ -43,12 +38,7 @@ public function update() session()->invalidate(); session()->regenerateToken(); - Flux::toast( - heading: 'Berhasil', - text: 'Kata sandi berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Kata sandi berhasil diperbarui.'); $this->redirectRoute('login', navigate: true); } diff --git a/app/Livewire/Studio/Setting/Profile.php b/app/Livewire/Studio/Setting/Profile.php index 4f65bd3..e2228d1 100644 --- a/app/Livewire/Studio/Setting/Profile.php +++ b/app/Livewire/Studio/Setting/Profile.php @@ -4,15 +4,15 @@ use App\Livewire\Forms\Studio\Setting\ProfileForm; use App\Models\Employee; +use App\Traits\WithToast; use App\Traits\WithUpdatedData; -use Flux\Flux; use Livewire\Attributes\Title; use Livewire\Component; #[Title('Profil')] class Profile extends Component { - use WithUpdatedData; + use WithToast, WithUpdatedData; public ProfileForm $form; @@ -25,12 +25,7 @@ public function update() { $this->form->update(); - Flux::toast( - heading: 'Berhasil', - text: 'Profil berhasil diperbarui.', - variant: 'success', - duration: 3000 - ); + $this->toast('Profil berhasil diperbarui.'); } public function render() diff --git a/app/Traits/WithToast.php b/app/Traits/WithToast.php new file mode 100644 index 0000000..aa0ad4f --- /dev/null +++ b/app/Traits/WithToast.php @@ -0,0 +1,18 @@ +