Skip to content

Commit 7a55b34

Browse files
author
Rajat
committed
Preview is disabled for Quiz lessons
1 parent ec20b1b commit 7a55b34

3 files changed

Lines changed: 39 additions & 26 deletions

File tree

  • apps/web

apps/web/app/(with-contexts)/dashboard/(sidebar)/product/[id]/content/section/[section]/lesson/page.tsx

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -604,32 +604,34 @@ export default function LessonPage() {
604604
/>
605605
</>
606606
)}
607-
{product?.type?.toLowerCase() !==
608-
UIConstants.COURSE_TYPE_DOWNLOAD && (
609-
<div className="flex items-center justify-between">
610-
<div className="space-y-0.5">
611-
<Label
612-
htmlFor="preview"
613-
className="font-semibold"
614-
>
615-
{LESSON_PREVIEW}
616-
</Label>
617-
<p className="text-sm text-muted-foreground">
618-
Allow students to preview this
619-
lesson without enrolling
620-
</p>
607+
{product?.type?.toLowerCase() ===
608+
Constants.CourseType.COURSE &&
609+
lesson.type !== Constants.LessonType.QUIZ && (
610+
<div className="flex items-center justify-between">
611+
<div className="space-y-0.5">
612+
<Label
613+
htmlFor="preview"
614+
className="font-semibold"
615+
>
616+
{LESSON_PREVIEW}
617+
</Label>
618+
<p className="text-sm text-muted-foreground">
619+
Allow students to preview this
620+
lesson without enrolling
621+
</p>
622+
</div>
623+
<Switch
624+
id="preview"
625+
checked={!lesson.requiresEnrollment}
626+
onCheckedChange={(checked) =>
627+
updateLesson({
628+
requiresEnrollment:
629+
!checked,
630+
})
631+
}
632+
/>
621633
</div>
622-
<Switch
623-
id="preview"
624-
checked={!lesson.requiresEnrollment}
625-
onCheckedChange={(checked) =>
626-
updateLesson({
627-
requiresEnrollment: !checked,
628-
})
629-
}
630-
/>
631-
</div>
632-
)}
634+
)}
633635
<div className="flex items-center justify-between">
634636
<div className="space-y-0.5">
635637
<Label

apps/web/config/strings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export const responses = {
139139
certificate_invalid_settings: "Certificate can only be enabled for courses",
140140
sso_provider_already_exists:
141141
"A SSO provider with the same provider ID already exists",
142+
quiz_cannot_be_previewed: "Quiz cannot be previewed",
142143

143144
// api responses
144145
digital_download_no_files:

apps/web/graphql/lessons/helpers.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { text, audio, video, pdf, embed, quiz, file } = constants;
99

1010
type LessonValidatorProps = Pick<
1111
LessonWithStringContent,
12-
"content" | "type" | "media"
12+
"content" | "type" | "media" | "requiresEnrollment"
1313
>;
1414

1515
export const lessonValidator = (lessonData: LessonValidatorProps) => {
@@ -38,6 +38,16 @@ export function validateTextContent(lessonData: LessonValidatorProps) {
3838
}
3939

4040
if (lessonData.type === quiz) {
41+
if (
42+
Object.prototype.hasOwnProperty.call(
43+
lessonData,
44+
"requiresEnrollment",
45+
) &&
46+
!lessonData.requiresEnrollment
47+
) {
48+
throw new Error(responses.quiz_cannot_be_previewed);
49+
}
50+
4151
if (content && content.questions) {
4252
validateQuizContent(content.questions);
4353
}

0 commit comments

Comments
 (0)