Availability based on permissions
This commit is contained in:
@@ -1,25 +1,21 @@
|
||||
"use client";
|
||||
"use server";
|
||||
import getMe from "@/lib/getMe";
|
||||
import hasPermissions from "@/lib/hasPermissions";
|
||||
import { redirect } from "next/navigation";
|
||||
import PlanningPage from "./_planning";
|
||||
|
||||
import Planning from "@/components/planning";
|
||||
import { useApi } from "@/hooks/use-api";
|
||||
import ICalendarEvent from "@/interfaces/ICalendarEvent";
|
||||
import { Loader2 } from "lucide-react";
|
||||
export default async function Page() {
|
||||
const me = await getMe();
|
||||
if (
|
||||
!me ||
|
||||
me.status === "Error" ||
|
||||
!me.data ||
|
||||
!hasPermissions(me.data.roles, {
|
||||
events: ["get"],
|
||||
})
|
||||
) {
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
export default function Page() {
|
||||
const {
|
||||
data: requestedEvents,
|
||||
isLoading,
|
||||
success,
|
||||
mutate,
|
||||
} = useApi<ICalendarEvent[]>("/events", undefined, false, false);
|
||||
|
||||
if (isLoading) return <Loader2 className="animate-spin" />;
|
||||
if (success)
|
||||
return (
|
||||
<Planning
|
||||
modifiable
|
||||
events={requestedEvents ?? []}
|
||||
mutate={mutate}
|
||||
/>
|
||||
);
|
||||
return <PlanningPage user={me.data} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user