41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { redirect } from "next/navigation";
|
|
import { TopNav } from "@/components/navigation/top-nav";
|
|
import { prisma } from "@/lib/db/prisma";
|
|
import { getActingStaff } from "@/lib/staff/get-acting-staff";
|
|
import { listTimeOff } from "@/services/staff/staff.service";
|
|
import { TimeOffList } from "@/features/staff/components/time-off-list";
|
|
|
|
export const metadata: Metadata = { title: "Time Off" };
|
|
export const dynamic = "force-dynamic";
|
|
|
|
function toCalendarDate(date: Date): string {
|
|
return date.toISOString().slice(0, 10);
|
|
}
|
|
|
|
export default async function StaffTimeOffPage() {
|
|
const staff = await getActingStaff();
|
|
if (!staff) redirect("/home");
|
|
|
|
const { upcoming, past } = await listTimeOff(prisma, staff.id);
|
|
// Whole-day rows only — partial-day "Block Time" entries are managed from the calendar (see block-time-button.tsx).
|
|
const wholeDay = (rows: typeof upcoming) => rows.filter((r) => r.startMinutes === null && r.endMinutes === null);
|
|
|
|
const toEditable = (rows: typeof upcoming) =>
|
|
wholeDay(rows).map((t) => ({
|
|
id: t.id,
|
|
startDate: toCalendarDate(t.startDate),
|
|
endDate: toCalendarDate(t.endDate),
|
|
reason: t.reason,
|
|
}));
|
|
|
|
return (
|
|
<div className="pb-12">
|
|
<TopNav title="Time Off" onBack sticky className="bg-stone" />
|
|
<main className="mx-auto max-w-2xl px-6 py-6">
|
|
<TimeOffList upcoming={toEditable(upcoming)} past={toEditable(past)} />
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|