From 3ed7bc147b34ec694c7edf304416092cfc42bd9d Mon Sep 17 00:00:00 2001 From: dmitriylaukhin Date: Sun, 26 Apr 2026 14:00:47 +0500 Subject: [PATCH] Add lesson complete button with homework-aware logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Show "Отметить как пройденный" button only on lessons without homework - Show static "Пройдено" badge on homework lessons completed via approval - Auto-create LessonProgress when curator/admin approves homework submission - Revalidate student lesson, course, and dashboard pages on approval Co-Authored-By: Claude Sonnet 4.6 --- .../[slug]/lessons/[lessonId]/page.tsx | 5 +- .../homework/[submissionId]/actions.ts | 75 ++++++++++++------- .../student/lesson-complete-button.tsx | 11 +++ 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx b/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx index 10f7132..9af3191 100644 --- a/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx +++ b/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx @@ -179,9 +179,12 @@ export default async function LessonPage({ params }: Props) {
)} - {!isAdmin && ( + {!isAdmin && !lesson.homework && ( )} + {!isAdmin && lesson.homework && isCompleted && ( + + )} {nextLesson ? ( { + await tx.homeworkFeedback.create({ + data: { + submissionId, + curatorId: session.user.id, + text: data.text, + files: data.files ?? [], + audioUrl: data.audioUrl ?? null, + }, + }); + await tx.homeworkSubmission.update({ + where: { id: submissionId }, + data: { status, statusAt: new Date() }, + }); + if (status === "APPROVED") { + await tx.lessonProgress.upsert({ + where: { + userId_lessonId: { + userId: submission.user.id, + lessonId: submission.homework.lesson.id, + }, + }, + create: { + userId: submission.user.id, + lessonId: submission.homework.lesson.id, + }, + update: {}, + }); + } + }); + + const { lesson } = submission.homework; + const lessonUrl = `${process.env.BETTER_AUTH_URL ?? "https://school.second-brain.ru"}/courses/${lesson.module.course.slug}/lessons/${lesson.id}`; + await sendFeedbackReceivedEmail( + submission.user.email, + submission.user.name, + lesson.title, + data.text, + lessonUrl + ); revalidatePath("/curator/homework"); revalidatePath(`/curator/homework/${submissionId}`); + revalidatePath(`/courses/${lesson.module.course.slug}/lessons/${lesson.id}`); + revalidatePath(`/courses/${lesson.module.course.slug}`); + revalidatePath("/dashboard"); } export async function setReviewing(submissionId: string) { diff --git a/src/components/student/lesson-complete-button.tsx b/src/components/student/lesson-complete-button.tsx index 5c820c0..0280e47 100644 --- a/src/components/student/lesson-complete-button.tsx +++ b/src/components/student/lesson-complete-button.tsx @@ -8,13 +8,24 @@ export function LessonCompleteButton({ lessonId, slug, isCompleted, + readOnly = false, }: { lessonId: string; slug: string; isCompleted: boolean; + readOnly?: boolean; }) { const [pending, startTransition] = useTransition(); + if (readOnly) { + return ( +
+ + Пройдено +
+ ); + } + return (