Gate order-list filters behind CompanySettings.orderFilterEnabled
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
getCustomerOrderYears,
|
||||
ORDER_STATUS_LABEL,
|
||||
} from "../../lib/customerAuth";
|
||||
import { getOrderFilterEnabled } from "../../lib/payload";
|
||||
import { OrderStatusBadge } from "../components/OrderStatusBadge";
|
||||
import { PaymentStatusBadge } from "../components/PaymentStatusBadge";
|
||||
import { LogoutButton } from "../components/LogoutButton";
|
||||
@@ -47,7 +48,11 @@ export default async function KontoBestellungenPage({
|
||||
const session = await getSessionCustomer();
|
||||
if (!session) redirect("/konto/login");
|
||||
|
||||
const { status, paymentStatus, year } = await searchParams;
|
||||
const orderFilterEnabled = await getOrderFilterEnabled();
|
||||
const rawSearchParams = await searchParams;
|
||||
const status = orderFilterEnabled ? rawSearchParams.status : undefined;
|
||||
const paymentStatus = orderFilterEnabled ? rawSearchParams.paymentStatus : undefined;
|
||||
const year = orderFilterEnabled ? rawSearchParams.year : undefined;
|
||||
|
||||
const [orders, availableYears] = await Promise.all([
|
||||
getCustomerOrders(session.token, session.customer.id, true, { status, paymentStatus, year }),
|
||||
@@ -65,7 +70,7 @@ export default async function KontoBestellungenPage({
|
||||
Eingeloggt als {session.customer.email} (Kundennummer {session.customer.customerNumber})
|
||||
</p>
|
||||
|
||||
{availableYears.length > 0 && (
|
||||
{orderFilterEnabled && availableYears.length > 0 && (
|
||||
<Suspense fallback={null}>
|
||||
<OrderFilters statusOptions={STATUS_OPTIONS} paymentStatusOptions={PAYMENT_STATUS_OPTIONS} years={availableYears} />
|
||||
</Suspense>
|
||||
|
||||
@@ -1070,6 +1070,21 @@ export async function getBlogFilterEnabled(): Promise<boolean> {
|
||||
return data.docs?.[0]?.blogFilterEnabled ?? false;
|
||||
}
|
||||
|
||||
// Same pattern — gates /konto/bestellungen's status/paymentStatus/year filters.
|
||||
export async function getOrderFilterEnabled(): Promise<boolean> {
|
||||
const params = new URLSearchParams({ "where[tenant.slug][equals]": TENANT_SLUG, limit: "1" });
|
||||
const res = await fetch(`${PAYLOAD_URL}/api/company-settings?${params}`, {
|
||||
headers: { "x-order-service-secret": process.env.ORDER_SERVICE_SECRET || "" },
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
if (!res.ok) {
|
||||
console.error(`getOrderFilterEnabled: Payload returned ${res.status} ${res.statusText}`);
|
||||
return false;
|
||||
}
|
||||
const data: { docs?: { orderFilterEnabled?: boolean }[] } = await res.json();
|
||||
return data.docs?.[0]?.orderFilterEnabled ?? false;
|
||||
}
|
||||
|
||||
export type SeoSettings = {
|
||||
defaultTitle: string | null;
|
||||
titleTemplate: string | null;
|
||||
|
||||
Reference in New Issue
Block a user