51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { redirect } from "next/navigation";
|
|
import { auth } from "@/auth";
|
|
import { prisma } from "@/lib/db/prisma";
|
|
import { hasPermission } from "@/lib/auth/permissions";
|
|
import { Permission } from "@/generated/prisma/enums";
|
|
import { getActingStaff } from "@/lib/staff/get-acting-staff";
|
|
import { listCategories } from "@/services/catalogue/service-catalogue.service";
|
|
import { CatalogueManager } from "@/features/owner/components/catalogue-manager";
|
|
|
|
export const metadata: Metadata = { title: "Services" };
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function OwnerServicesPage() {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/sign-in");
|
|
|
|
const canManage = await hasPermission(session.user.id, Permission.MANAGE_SERVICES);
|
|
if (!canManage) redirect("/staff");
|
|
|
|
const owner = await getActingStaff();
|
|
if (!owner) redirect("/staff");
|
|
|
|
const categories = await listCategories(prisma, owner.businessId);
|
|
|
|
return (
|
|
<div className="px-6 pt-12 pb-12 lg:max-w-3xl">
|
|
<h1 className="mb-6 text-2xl font-bold tracking-tight">Services</h1>
|
|
<CatalogueManager
|
|
categories={categories.map((c) => ({
|
|
id: c.id,
|
|
name: c.name,
|
|
isActive: c.isActive,
|
|
services: c.services.map((s) => ({
|
|
id: s.id,
|
|
categoryId: s.categoryId,
|
|
name: s.name,
|
|
description: s.description ?? "",
|
|
durationMinutes: s.durationMinutes,
|
|
price: s.price.toString(),
|
|
bufferBeforeMinutes: s.bufferBeforeMinutes,
|
|
bufferAfterMinutes: s.bufferAfterMinutes,
|
|
isActive: s.isActive,
|
|
allowOnlineBooking: s.allowOnlineBooking,
|
|
})),
|
|
}))}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|