Introduce ErrorBoundary component for improved error handling

- Add `ErrorBoundary` component to handle rendering fallback UI during errors.
- Integrate `ErrorBoundary` into main layout and critical pages for global error handling.
- Create `useErrorHandler` hook to handle async errors consistently across components.
- Refactor `NewCustomerModal` and `CustomersPage` to leverage `useErrorHandler` for improved error management.
- Add a fallback dialog UI for user-friendly error reporting and resolution.
This commit is contained in:
2025-07-11 19:06:07 +02:00
parent 2a95efb75f
commit 18014ce9f0
4 changed files with 196 additions and 42 deletions

View File

@@ -24,6 +24,7 @@ import {ArrowRight} from "lucide-react";
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";
export default function CustomersPage() {
const [customers, setCustomers] = useState<Customer[]>([]);
@@ -31,6 +32,7 @@ export default function CustomersPage() {
const [loading, setLoading] = useState(true);
const [page, setPage] = useState(1);
const pageSize = 15;
const handleError = useErrorHandler();
useEffect(() => {
setLoading(true);
@@ -45,13 +47,13 @@ export default function CustomersPage() {
setCustomers(data);
})
.catch((error) => {
console.error('Error fetching customers:', error);
handleError(error);
setCustomers([]);
})
.finally(() => {
setLoading(false);
});
}, []);
}, [handleError]);
const filtered = useMemo(() => {
if (customers.length === 0) return [];