refactor: streamline toast message handling by chaining return statements
This commit is contained in:
parent
cc112ef253
commit
fbca04bce6
@ -503,9 +503,7 @@ ### ZONK — Tidak Ada Logic di Controller
|
|||||||
{
|
{
|
||||||
$this->service->store($request->validated());
|
$this->service->store($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil ditambahkan']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil ditambahkan'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,9 +516,7 @@ ### ZONK — Tidak Ada Logic di Controller
|
|||||||
{
|
{
|
||||||
$this->service->resetPassword($user, $request->validated());
|
$this->service->resetPassword($user, $request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Password berhasil direset']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Password berhasil direset'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -565,9 +561,7 @@ ### Return ke Halaman yang Sama — Gunakan `back()`
|
|||||||
{
|
{
|
||||||
$this->service->destroy($product);
|
$this->service->destroy($product);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil dihapus']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil dihapus'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ❌ JANGAN pakai ->with()
|
// ❌ JANGAN pakai ->with()
|
||||||
@ -622,9 +616,7 @@ ### DB Transaction — Gunakan `handleAction()` untuk 2+ Query
|
|||||||
{
|
{
|
||||||
$this->service->destroy($product);
|
$this->service->destroy($product);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil dihapus']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil dihapus'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -32,35 +32,27 @@ public function updateSystem(UpdateSystemRequest $request): RedirectResponse
|
|||||||
{
|
{
|
||||||
$this->service->updateSystem($request->validated());
|
$this->service->updateSystem($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan sistem berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan sistem berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateHomepage(UpdateHomepageRequest $request): RedirectResponse
|
public function updateHomepage(UpdateHomepageRequest $request): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->updateHomepage($request->validated());
|
$this->service->updateHomepage($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan homepage berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan homepage berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateSocialMedia(UpdateSocialMediaRequest $request): RedirectResponse
|
public function updateSocialMedia(UpdateSocialMediaRequest $request): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->updateSocialMedia($request->validated());
|
$this->service->updateSocialMedia($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan media sosial berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan media sosial berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateHR(UpdateHRRequest $request): RedirectResponse
|
public function updateHR(UpdateHRRequest $request): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->updateHR($request->validated());
|
$this->service->updateHR($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan HR berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan HR berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,9 +86,7 @@ public function toggleActive(User $user): RedirectResponse
|
|||||||
$employee = $this->service->toggleActive($user);
|
$employee = $this->service->toggleActive($user);
|
||||||
$status = $employee->is_active ? 'diaktifkan' : 'dinonaktifkan';
|
$status = $employee->is_active ? 'diaktifkan' : 'dinonaktifkan';
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => "Pegawai berhasil {$status}."]);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => "Pegawai berhasil {$status}."])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetPassword(User $user): RedirectResponse
|
public function resetPassword(User $user): RedirectResponse
|
||||||
|
|||||||
@ -28,26 +28,20 @@ public function store(CategoryRequest $request): RedirectResponse
|
|||||||
{
|
{
|
||||||
$this->service->store($request->validated());
|
$this->service->store($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil ditambahkan.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil ditambahkan.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(CategoryRequest $request, Category $category): RedirectResponse
|
public function update(CategoryRequest $request, Category $category): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->update($category, $request->validated());
|
$this->service->update($category, $request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Category $category): RedirectResponse
|
public function destroy(Category $category): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->destroy($category);
|
$this->service->destroy($category);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil dihapus.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil dihapus.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,26 +28,20 @@ public function store(CustomerRequest $request): RedirectResponse
|
|||||||
{
|
{
|
||||||
$this->service->store($request->validated());
|
$this->service->store($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Customer berhasil ditambahkan.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Customer berhasil ditambahkan.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(CustomerRequest $request, Customer $customer): RedirectResponse
|
public function update(CustomerRequest $request, Customer $customer): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->update($customer, $request->validated());
|
$this->service->update($customer, $request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Customer berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Customer berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Customer $customer): RedirectResponse
|
public function destroy(Customer $customer): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->destroy($customer);
|
$this->service->destroy($customer);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Customer berhasil dihapus.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Customer berhasil dihapus.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,9 +84,7 @@ public function toggleStatus(Product $product): RedirectResponse
|
|||||||
$this->service->toggleStatus($product);
|
$this->service->toggleStatus($product);
|
||||||
$status = $product->fresh()->status;
|
$status = $product->fresh()->status;
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => "Status produk berhasil diubah menjadi {$status->label()}."]);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => "Status produk berhasil diubah menjadi {$status->label()}."])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleFeatured(Product $product): RedirectResponse
|
public function toggleFeatured(Product $product): RedirectResponse
|
||||||
@ -94,18 +92,14 @@ public function toggleFeatured(Product $product): RedirectResponse
|
|||||||
$this->service->toggleFeatured($product);
|
$this->service->toggleFeatured($product);
|
||||||
$featured = $product->fresh()->is_featured;
|
$featured = $product->fresh()->is_featured;
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => $featured ? 'Produk berhasil ditampilkan di halaman depan.' : 'Produk berhasil disembunyikan dari halaman depan.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => $featured ? 'Produk berhasil ditampilkan di halaman depan.' : 'Produk berhasil disembunyikan dari halaman depan.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function approve(Product $product): RedirectResponse
|
public function approve(Product $product): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->approve($product);
|
$this->service->approve($product);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil disetujui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil disetujui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reject(Product $product): RedirectResponse
|
public function reject(Product $product): RedirectResponse
|
||||||
@ -113,18 +107,14 @@ public function reject(Product $product): RedirectResponse
|
|||||||
$reason = request()->input('rejection_reason', '');
|
$reason = request()->input('rejection_reason', '');
|
||||||
$this->service->reject($product, $reason);
|
$this->service->reject($product, $reason);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil ditolak.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil ditolak.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resubmit(Product $product): RedirectResponse
|
public function resubmit(Product $product): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->resubmit($product);
|
$this->service->resubmit($product);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil diajukan ulang.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil diajukan ulang.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function variants(Product $product): JsonResponse
|
public function variants(Product $product): JsonResponse
|
||||||
|
|||||||
@ -81,9 +81,7 @@ public function toggleStatus(RawMaterial $rawMaterial): RedirectResponse
|
|||||||
$this->service->toggleStatus($rawMaterial);
|
$this->service->toggleStatus($rawMaterial);
|
||||||
$status = $rawMaterial->fresh()->is_active ? 'Aktif' : 'Non Aktif';
|
$status = $rawMaterial->fresh()->is_active ? 'Aktif' : 'Non Aktif';
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => "Status bahan baku berhasil diubah menjadi {$status}."]);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => "Status bahan baku berhasil diubah menjadi {$status}."])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function variants(RawMaterial $rawMaterial): JsonResponse
|
public function variants(RawMaterial $rawMaterial): JsonResponse
|
||||||
|
|||||||
@ -28,26 +28,20 @@ public function store(SupplierRequest $request): RedirectResponse
|
|||||||
{
|
{
|
||||||
$this->service->store($request->validated());
|
$this->service->store($request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Supplier berhasil ditambahkan.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Supplier berhasil ditambahkan.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(SupplierRequest $request, Supplier $supplier): RedirectResponse
|
public function update(SupplierRequest $request, Supplier $supplier): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->update($supplier, $request->validated());
|
$this->service->update($supplier, $request->validated());
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Supplier berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Supplier berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Supplier $supplier): RedirectResponse
|
public function destroy(Supplier $supplier): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->destroy($supplier);
|
$this->service->destroy($supplier);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Supplier berhasil dihapus.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Supplier berhasil dihapus.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,8 +61,6 @@ public function destroy(Role $role): RedirectResponse
|
|||||||
{
|
{
|
||||||
$this->service->destroy($role);
|
$this->service->destroy($role);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Role berhasil dihapus.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Role berhasil dihapus.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,8 +22,6 @@ public function update(PasswordUpdateRequest $request): RedirectResponse
|
|||||||
{
|
{
|
||||||
$request->user()->update(['password' => $request->password]);
|
$request->user()->update(['password' => $request->password]);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kata sandi berhasil diperbarui.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Kata sandi berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
return back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user