From d266acae85221152731fe1fde22c27127010b7eb Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Mon, 15 Dec 2025 21:16:18 +0700 Subject: [PATCH] refactor(article): merubah cara mengirim notifikasi setelah create dan update --- app/Livewire/Studio/Manage/Article/Create.php | 8 +++----- app/Livewire/Studio/Manage/Article/Edit.php | 6 +++--- app/Livewire/Studio/Manage/Article/Index.php | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/Livewire/Studio/Manage/Article/Create.php b/app/Livewire/Studio/Manage/Article/Create.php index 20e81cd..2ea26c7 100644 --- a/app/Livewire/Studio/Manage/Article/Create.php +++ b/app/Livewire/Studio/Manage/Article/Create.php @@ -34,11 +34,9 @@ public function save(): void ], ); - $this->dispatch('refreshDatatable'); - - $this->toast('Artikel berhasil ditambahkan.'); - - $this->redirectRoute('studio.manage.article.index'); + $this->redirectRoute('studio.manage.article.index', [ + 'notification' => 'Artikel berhasil ditambahkan.', + ], navigate: true); } public function render(): View diff --git a/app/Livewire/Studio/Manage/Article/Edit.php b/app/Livewire/Studio/Manage/Article/Edit.php index 8c84fe3..c2f373e 100644 --- a/app/Livewire/Studio/Manage/Article/Edit.php +++ b/app/Livewire/Studio/Manage/Article/Edit.php @@ -29,9 +29,9 @@ public function save(): void $this->form->update(); - $this->toast('Artikel berhasil diperbarui.'); - - $this->redirectRoute('studio.manage.article.index'); + $this->redirectRoute('studio.manage.article.index', [ + 'notification' => 'Artikel berhasil diperbarui.', + ], navigate: true); } public function render(): View diff --git a/app/Livewire/Studio/Manage/Article/Index.php b/app/Livewire/Studio/Manage/Article/Index.php index 1a0470c..c5be92d 100644 --- a/app/Livewire/Studio/Manage/Article/Index.php +++ b/app/Livewire/Studio/Manage/Article/Index.php @@ -17,6 +17,21 @@ class Index extends Component { use WithAuthorization, WithConfirmation, WithSubscribeNotification, WithToast; + 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); + } + } + public function delete(Article $article): void { $this->canOrAbort('delete article');