Remove CustomerRepository and replace with direct API calls
- Remove `CustomerRepository` and its methods for customer management and caching. - Refactor customer-related pages (`[id]/page.tsx`, `customers/page.tsx`) to use direct `fetch` API calls. - Update breadcrumb resolver to fetch data directly from the API. - Simplify `addCustomer` use case to avoid repository dependency.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import {CustomerRepository} from "@/services/customers/repositories/customerRepository";
|
||||
|
||||
export const breadcrumbMap: Record<string, string> = {
|
||||
'dashboard': 'Dashboard',
|
||||
'settings': 'Settings',
|
||||
@@ -10,11 +8,21 @@ export const breadcrumbMap: Record<string, string> = {
|
||||
|
||||
export const breadcrumbResolvers: Record<string, (id: string) => Promise<string>> = {
|
||||
"customers": async (id: string) => {
|
||||
const customer = await CustomerRepository.getById(id);
|
||||
if (!customer) return `ID: ${id}`;
|
||||
try {
|
||||
const response = await fetch(`/api/customers/${id}`);
|
||||
if (!response.ok) {
|
||||
return `ID: ${id}`;
|
||||
}
|
||||
|
||||
if (customer.companyName) return `Firma: ${customer.companyName}`;
|
||||
if (customer.name) return `Name: ${customer.name}`;
|
||||
return `ID: ${id}`;
|
||||
const customer = await response.json();
|
||||
if (!customer) return `ID: ${id}`;
|
||||
|
||||
if (customer.companyName) return `Firma: ${customer.companyName}`;
|
||||
if (customer.name) return `Name: ${customer.name}`;
|
||||
return `ID: ${id}`;
|
||||
} catch (error) {
|
||||
console.error('Error fetching customer for breadcrumb:', error);
|
||||
return `ID: ${id}`;
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user