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:
@@ -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};
|
||||
|
||||
@@ -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});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export const customerRoutes = {
|
||||
create: "/customers",
|
||||
validate: "/customers/validate",
|
||||
getById: (id: string) => `/customers/${id}`,
|
||||
};
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import {useState, useEffect, useMemo} from "react";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import {Card, CardContent} from "@/components/ui/card";
|
||||
@@ -25,9 +24,9 @@ import {ArrowRight} from "lucide-react";
|
||||
import {NewCustomerModal} from "@/components/customers/modal/NewCustomerModal";
|
||||
import axios from "axios";
|
||||
import {Customer} from "@/services/customers/entities/customer";
|
||||
import Link from "next/link";
|
||||
|
||||
export default function CustomersPage() {
|
||||
const router = useRouter();
|
||||
const [customers, setCustomers] = useState<Customer[]>([]);
|
||||
const [search, setSearch] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -50,7 +49,7 @@ export default function CustomersPage() {
|
||||
}, []);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if(customers.length === 0) return [];
|
||||
if (customers.length === 0) return [];
|
||||
|
||||
return customers.filter(
|
||||
(c) =>
|
||||
@@ -143,13 +142,11 @@ export default function CustomersPage() {
|
||||
<TableCell>{customer.city}</TableCell>
|
||||
<TableCell>{new Date(customer.createdAt).toLocaleString()}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => router.push(`/customers/${customer.id}`)}
|
||||
>
|
||||
<ArrowRight className="w-4 h-4"/>
|
||||
</Button>
|
||||
<Link href={`/customers/${customer.id}`}>
|
||||
<Button variant="ghost" size="icon">
|
||||
<ArrowRight className="w-4 h-4"/>
|
||||
</Button>
|
||||
</Link>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {Separator} from "@/components/ui/separator";
|
||||
import {DynamicBreadcrumb} from "@/components/dynamic-breadcrumb";
|
||||
import {getServerSession} from "next-auth";
|
||||
import LoginScreen from "@/components/login-screen";
|
||||
import {authOptions} from "@/lib/auth/authOptions";
|
||||
import {authOptions} from "@/lib/api/auth/authOptions";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Internal | Rhein Software",
|
||||
|
||||
Reference in New Issue
Block a user