Refactor error handling utilities

- Replace `showError` with a more versatile `showToast` utility.
- Add specific toast functions (`showErrorToast`, `showSuccessToast`, etc.) for better message handling.
- Remove `showError.ts` and migrate logic to `showToast.ts` for cleaner structure.
- Update `ErrorBoundary` and `useErrorHandler` to use the new `showToast` functions.
This commit is contained in:
2025-07-11 19:15:08 +02:00
parent 18014ce9f0
commit c99e09056c
4 changed files with 180 additions and 127 deletions

View File

@@ -25,6 +25,7 @@ import {NewCustomerModal} from "@/components/customers/modal/NewCustomerModal";
import {Customer} from "@/services/customers/entities/customer";
import Link from "next/link";
import {useErrorHandler} from "@/components/error-boundary";
import {showError, showInfoToast} from "@/lib/ui/showToast";
export default function CustomersPage() {
const [customers, setCustomers] = useState<Customer[]>([]);
@@ -39,14 +40,17 @@ export default function CustomersPage() {
fetch('/api/customers')
.then(async (response) => {
if (!response.ok) {
showError("Failed to fetch customers data")
throw new Error(`Failed to fetch customers: ${response.statusText}`);
}
return response.json();
})
.then((data) => {
showInfoToast("Customers data loaded")
setCustomers(data);
})
.catch((error) => {
showError("Failed to fetch customers data (1)")
handleError(error);
setCustomers([]);
})