Refactor navigation structure and API routes

- Centralize user menu, sidebar items, and breadcrumb logic.
- Map consistent API endpoints in `customerRoutes`.
- Replace inline route definitions with reusable constants.
- Refactor auth configuration file location.
- Improve `<Link>` usage to replace static `<a>` elements.
- Adjust sidebar and dropdown components to use dynamic navigation configurations.
This commit is contained in:
2025-07-07 19:49:58 +02:00
parent 7ba92dc66c
commit e42b352216
15 changed files with 127 additions and 88 deletions

View File

@@ -1,5 +1,5 @@
import NextAuth from "next-auth";
import {authOptions} from "@/lib/auth/authOptions";
import {authOptions} from "@/lib/api/auth/authOptions";
const handler = NextAuth(authOptions);
export {handler as GET, handler as POST};

View File

@@ -1,9 +1,10 @@
import {NextRequest, NextResponse} from "next/server";
import {serverCall} from "@/lib/api/serverCall";
import {customerRoutes} from "@/app/api/customers/customerRoutes";
export async function GET(request: NextRequest) {
const id = request.url.split('/').pop();
const response = await serverCall(`/customers/${id}`, "GET");
const response = await serverCall(customerRoutes.getById(id!), "GET");
if (!response.ok) {
return NextResponse.json({error: "Customer not found"}, {status: 404});

View File

@@ -1,4 +1,5 @@
export const customerRoutes = {
create: "/customers",
validate: "/customers/validate",
getById: (id: string) => `/customers/${id}`,
};

View File

@@ -1,14 +1,15 @@
import {NextRequest, NextResponse} from "next/server";
import {serverCall} from "@/lib/api/serverCall";
import {customerRoutes} from "@/app/api/customers/customerRoutes";
export async function GET() {
const data = await serverCall("/customers", "GET");
const data = await serverCall(customerRoutes.create, "GET");
const customers = await data.json();
return NextResponse.json(customers);
}
export async function POST(req: NextRequest) {
const body = await req.json()
const result = await serverCall("/customers", "POST", body);
const result = await serverCall(customerRoutes.create, "POST", body);
return NextResponse.json(result.json());
}