54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import { auth } from "@/auth";
|
|
import { TopNav } from "@/components/navigation/top-nav";
|
|
import { prisma } from "@/lib/db/prisma";
|
|
import { hasPermission } from "@/lib/auth/permissions";
|
|
import { Permission } from "@/generated/prisma/enums";
|
|
import { getActingBusinessContext } from "@/lib/business/get-acting-business-context";
|
|
import { listBreaks } from "@/services/staff/staff.service";
|
|
import { BreaksList } from "@/features/staff/components/breaks-list";
|
|
import { createOwnerBreakActionSet } from "@/features/owner/actions/break-action-set";
|
|
|
|
export const metadata: Metadata = { title: "Staff Breaks" };
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function OwnerStaffBreaksPage({ params }: { params: Promise<{ id: string }> }) {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/sign-in");
|
|
|
|
const canManage = await hasPermission(session.user.id, Permission.MANAGE_STAFF);
|
|
if (!canManage) redirect("/staff");
|
|
|
|
const context = await getActingBusinessContext();
|
|
if (!context) redirect("/staff");
|
|
|
|
const { id } = await params;
|
|
const target = await prisma.staffProfile.findFirst({
|
|
where: { id, businessId: context.businessId },
|
|
include: { user: { select: { name: true } } },
|
|
});
|
|
if (!target) notFound();
|
|
|
|
const breaks = await listBreaks(prisma, id);
|
|
|
|
return (
|
|
<div className="pb-12">
|
|
<TopNav title={`${target.user.name ?? "Staff"} — Breaks`} onBack sticky className="bg-stone" />
|
|
<main className="mx-auto max-w-2xl px-6 py-6">
|
|
<BreaksList
|
|
breaks={breaks.map((b) => ({
|
|
id: b.id,
|
|
label: b.label,
|
|
startMinutes: b.startMinutes,
|
|
endMinutes: b.endMinutes,
|
|
days: b.days.map((d) => d.dayOfWeek),
|
|
}))}
|
|
actions={createOwnerBreakActionSet(id)}
|
|
appointmentHrefBase="/owner/appointments"
|
|
/>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|