Stage 2: student lesson viewer, Kinescope player, PDF files, prev/next nav, My Courses dashboard
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { redirect } from "next/navigation";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { notFound } from "next/navigation";
|
||||
import { CourseSidebar } from "@/components/student/course-sidebar";
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
export default async function CourseLayout({ children, params }: Props) {
|
||||
const { slug } = await params;
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session) redirect("/login");
|
||||
|
||||
const course = await prisma.course.findUnique({
|
||||
where: { slug, published: true },
|
||||
include: {
|
||||
modules: {
|
||||
orderBy: { order: "asc" },
|
||||
include: {
|
||||
lessons: {
|
||||
where: { published: true },
|
||||
orderBy: { order: "asc" },
|
||||
select: { id: true, title: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!course) notFound();
|
||||
|
||||
const enrollment = await prisma.courseEnrollment.findUnique({
|
||||
where: { userId_courseId: { userId: session.user.id, courseId: course.id } },
|
||||
});
|
||||
|
||||
if (!enrollment) redirect("/dashboard");
|
||||
|
||||
if (enrollment.expiresAt && enrollment.expiresAt < new Date()) {
|
||||
redirect("/dashboard?expired=1");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-1">
|
||||
<CourseSidebar course={course} />
|
||||
<main className="flex-1 min-w-0 overflow-y-auto">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user