import { prisma } from "@/lib/prisma"; import { notFound } from "next/navigation"; import Link from "next/link"; import { FeedbackForm } from "./feedback-form"; import { ContentTabs } from "./content-tabs"; import { DeleteSubmissionButton } from "./delete-button"; interface Props { params: Promise<{ submissionId: string }>; } function formatSize(bytes: number) { if (bytes < 1024) return `${bytes} Б`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} КБ`; return `${(bytes / 1024 / 1024).toFixed(1)} МБ`; } function StatusBadge({ status }: { status: string }) { const map: Record = { PENDING: { label: "Новое", bg: "var(--foreground)", color: "var(--background)" }, REVIEWING: { label: "На рассмотрении", bg: "oklch(0.9 0.08 80)", color: "oklch(0.4 0.1 80)" }, APPROVED: { label: "Одобрено", bg: "oklch(0.88 0.1 145)", color: "oklch(0.35 0.15 145)" }, REJECTED: { label: "Отклонено", bg: "oklch(0.9 0.06 27)", color: "oklch(0.45 0.2 27)" }, }; const s = map[status] ?? map.PENDING; return ( {s.label} ); } export default async function SubmissionPage({ params }: Props) { const { submissionId } = await params; const submission = await prisma.homeworkSubmission.findUnique({ where: { id: submissionId }, include: { user: { select: { name: true, email: true } }, feedbacks: { include: { curator: { select: { name: true } } }, orderBy: { createdAt: "asc" }, }, homework: { include: { lesson: { select: { id: true, title: true, content: true, module: { select: { title: true, course: { select: { title: true, slug: true } }, }, }, }, }, }, }, }, }); if (!submission) notFound(); const files = (submission.files as { name: string; url: string; size: number }[]) ?? []; const lesson = submission.homework.lesson; const course = lesson.module.course; return (
{/* Breadcrumb */} {/* Meta table */}
{[ { label: "Автор", value: submission.user.name }, { label: "Логин", value: submission.user.email }, { label: "Урок", value: ( {lesson.title} ), }, { label: "Курс", value: course.title }, { label: "Статус", value: }, { label: "Время последнего изменения статуса", value: submission.statusAt ? new Date(submission.statusAt).toLocaleString("ru-RU") : new Date(submission.submittedAt).toLocaleString("ru-RU"), }, ].map(({ label, value }) => (
{label} {value}
))}
{/* Content tabs */}
{/* Student answer */}

Ответ студента

{submission.text ? (
{submission.text}
) : (

Текст не добавлен

)}
{/* Student audio */} {submission.audioUrl && (

Аудио студента

)} {/* Student files */} {files.length > 0 && (

Файлы студента

{files.map((f) => ( 📎 {f.name} {formatSize(f.size)} ))}
)} {/* Existing feedbacks */} {submission.feedbacks.length > 0 && (

История фидбека

{submission.feedbacks.map((fb) => { const fbFiles = (fb.files as { name: string; url: string; size: number }[]) ?? []; return (
{fb.curator.name} {new Date(fb.createdAt).toLocaleString("ru-RU")}

{fb.text}

{fbFiles.length > 0 && (
{fbFiles.map((f) => ( 📎 {f.name} {formatSize(f.size)} ))}
)} {fb.audioUrl && (
)}
); })}
)} {/* Feedback form */}
{/* Delete */}
); }