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:
@@ -11,7 +11,6 @@ import CustomerInformationContent from "@/components/customers/details/sub/Conta
|
||||
import CustomerPhoneNumberContent from "@/components/customers/details/sub/CustomerPhoneNumberContent";
|
||||
import CustomerNotesContent from "@/components/customers/details/sub/CustomerNotesContent";
|
||||
import {Customer} from "@/services/customers/entities/customer";
|
||||
import {CustomerRepository} from "@/services/customers/repositories/customerRepository";
|
||||
|
||||
export default function CustomerDetailPage() {
|
||||
const router = useRouter();
|
||||
@@ -33,16 +32,22 @@ export default function CustomerDetailPage() {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
CustomerRepository.getById(id)
|
||||
.then((result) => {
|
||||
fetch(`/api/customers/${id}`)
|
||||
.then(async (response) => {
|
||||
if (!isMounted) return;
|
||||
|
||||
if (!result) {
|
||||
if (response.status === 404) {
|
||||
setError("Kunde nicht gefunden");
|
||||
setCustomer(null);
|
||||
} else {
|
||||
setCustomer(result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch customer: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
setCustomer(result);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!isMounted) return;
|
||||
@@ -164,4 +169,4 @@ export default function CustomerDetailPage() {
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user