Add practice unlink/delete on course and module tabs and disable Add Practice when full.
Show disabled Add Practice controls with tooltips when a parent already has a practice, and wire course/module practice cards to unlink or permanently delete from the overflow menu. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2fd5a96ea5
commit
483ec8c15e
|
|
@ -67,6 +67,27 @@ export function resolveModuleContextUnlinkParent(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parent row to DELETE when removing a practice from a course's practice tab. */
|
||||||
|
export function resolveCourseContextUnlinkParent(
|
||||||
|
practice: ParentContextPractice,
|
||||||
|
courseId: number,
|
||||||
|
moduleIdsInCourse: number[],
|
||||||
|
): PracticeParent | null {
|
||||||
|
const parents = parentsFromPractice(practice)
|
||||||
|
const courseLink = parents.find(
|
||||||
|
(p) => p.parent_kind === "COURSE" && p.parent_id === courseId,
|
||||||
|
)
|
||||||
|
if (courseLink) return courseLink
|
||||||
|
|
||||||
|
const moduleIds = new Set(moduleIdsInCourse.filter((id) => id > 0))
|
||||||
|
const moduleLink = parents.find(
|
||||||
|
(p) => p.parent_kind === "MODULE" && moduleIds.has(p.parent_id),
|
||||||
|
)
|
||||||
|
if (moduleLink) return moduleLink
|
||||||
|
|
||||||
|
return parents.find((p) => p.parent_kind === "LESSON") ?? null
|
||||||
|
}
|
||||||
|
|
||||||
export async function unlinkPracticeFromParent(opts: {
|
export async function unlinkPracticeFromParent(opts: {
|
||||||
practiceId: number
|
practiceId: number
|
||||||
parent: PracticeParent
|
parent: PracticeParent
|
||||||
|
|
|
||||||
|
|
@ -156,3 +156,6 @@ export function primaryPracticeParent(parents: PracticeParent[]): PracticeParent
|
||||||
export function newParentRow(kind: PracticeParentKind = "LESSON"): PracticeParent {
|
export function newParentRow(kind: PracticeParentKind = "LESSON"): PracticeParent {
|
||||||
return { parent_kind: kind, parent_id: 0 }
|
return { parent_kind: kind, parent_id: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const learnEnglishPracticeLimitHint =
|
||||||
|
"This location already has a practice. Remove or unlink it before adding another."
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import spinnerSrc from "../../assets/Circular-indeterminate progress indicator.s
|
||||||
import alertSrc from "../../assets/Alert.svg";
|
import alertSrc from "../../assets/Alert.svg";
|
||||||
import {
|
import {
|
||||||
deleteTopLevelCourseModule,
|
deleteTopLevelCourseModule,
|
||||||
|
deleteParentLinkedPractice,
|
||||||
getPracticesByParentCourse,
|
getPracticesByParentCourse,
|
||||||
getProgramCourses,
|
getProgramCourses,
|
||||||
getTopLevelCourseModules,
|
getTopLevelCourseModules,
|
||||||
|
|
@ -41,6 +42,7 @@ import { refreshFileUrl, resolveFileUrl } from "../../api/files.api";
|
||||||
import type {
|
import type {
|
||||||
ParentContextPractice,
|
ParentContextPractice,
|
||||||
ContentAccessTier,
|
ContentAccessTier,
|
||||||
|
PracticeParent,
|
||||||
PracticePublishStatus,
|
PracticePublishStatus,
|
||||||
ProgramCourseListItem,
|
ProgramCourseListItem,
|
||||||
TopLevelCourseModuleItem,
|
TopLevelCourseModuleItem,
|
||||||
|
|
@ -63,6 +65,12 @@ import { ModuleIconUploadField } from "./components/ModuleIconUploadField";
|
||||||
import { ModulePracticeCard } from "./components/ModulePracticeCard";
|
import { ModulePracticeCard } from "./components/ModulePracticeCard";
|
||||||
import { PublishPracticeButton } from "./components/PublishPracticeButton";
|
import { PublishPracticeButton } from "./components/PublishPracticeButton";
|
||||||
import { DisplayValue } from "../../lib/displayValue"
|
import { DisplayValue } from "../../lib/displayValue"
|
||||||
|
import { learnEnglishPracticeLimitHint, parentsFromPractice } from "../../lib/practiceParents"
|
||||||
|
import {
|
||||||
|
isPracticeParentUnlinkNotLinkedError,
|
||||||
|
resolveCourseContextUnlinkParent,
|
||||||
|
unlinkPracticeFromParent,
|
||||||
|
} from "../../lib/practiceParentUnlink"
|
||||||
import { SearchHighlight } from "../../components/SearchHighlight"
|
import { SearchHighlight } from "../../components/SearchHighlight"
|
||||||
|
|
||||||
const MODULE_CARD_GRADIENT = "from-[#8E44AD] to-[#C39BD3]" as const;
|
const MODULE_CARD_GRADIENT = "from-[#8E44AD] to-[#C39BD3]" as const;
|
||||||
|
|
@ -197,6 +205,12 @@ export function CourseDetailPage() {
|
||||||
const [publishStatusPracticeId, setPublishStatusPracticeId] = useState<
|
const [publishStatusPracticeId, setPublishStatusPracticeId] = useState<
|
||||||
number | null
|
number | null
|
||||||
>(null);
|
>(null);
|
||||||
|
const [practiceToUnlink, setPracticeToUnlink] =
|
||||||
|
useState<ParentContextPractice | null>(null);
|
||||||
|
const [practiceToDelete, setPracticeToDelete] =
|
||||||
|
useState<ParentContextPractice | null>(null);
|
||||||
|
const [unlinkingPractice, setUnlinkingPractice] = useState(false);
|
||||||
|
const [deletingPractice, setDeletingPractice] = useState(false);
|
||||||
const [publishStatusModuleId, setPublishStatusModuleId] = useState<
|
const [publishStatusModuleId, setPublishStatusModuleId] = useState<
|
||||||
number | null
|
number | null
|
||||||
>(null);
|
>(null);
|
||||||
|
|
@ -396,6 +410,65 @@ export function CourseDetailPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const courseModuleIds = useMemo(
|
||||||
|
() => modules.map((module) => module.id).filter((id) => id > 0),
|
||||||
|
[modules],
|
||||||
|
);
|
||||||
|
|
||||||
|
const practiceUnlinkParent = useMemo((): PracticeParent | null => {
|
||||||
|
if (!practiceToUnlink || !Number.isFinite(courseIdNum) || courseIdNum < 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return resolveCourseContextUnlinkParent(
|
||||||
|
practiceToUnlink,
|
||||||
|
courseIdNum,
|
||||||
|
courseModuleIds,
|
||||||
|
);
|
||||||
|
}, [courseIdNum, courseModuleIds, practiceToUnlink]);
|
||||||
|
|
||||||
|
const confirmUnlinkPractice = async () => {
|
||||||
|
if (!practiceToUnlink || !practiceUnlinkParent) {
|
||||||
|
toast.error("This practice is not linked to this course.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setUnlinkingPractice(true);
|
||||||
|
try {
|
||||||
|
await unlinkPracticeFromParent({
|
||||||
|
practiceId: practiceToUnlink.id,
|
||||||
|
parent: practiceUnlinkParent,
|
||||||
|
isExamPrep: false,
|
||||||
|
});
|
||||||
|
toast.success(`Practice removed from ${displayTitle}`);
|
||||||
|
setPracticeToUnlink(null);
|
||||||
|
await loadCoursePractices();
|
||||||
|
} catch (e) {
|
||||||
|
if (isPracticeParentUnlinkNotLinkedError(e)) {
|
||||||
|
toast.info("This location was already removed.");
|
||||||
|
setPracticeToUnlink(null);
|
||||||
|
await loadCoursePractices();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
notifyApiError(e, "Could not remove from course");
|
||||||
|
} finally {
|
||||||
|
setUnlinkingPractice(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmDeletePractice = async () => {
|
||||||
|
if (!practiceToDelete) return;
|
||||||
|
setDeletingPractice(true);
|
||||||
|
try {
|
||||||
|
await deleteParentLinkedPractice(practiceToDelete.id);
|
||||||
|
toast.success("Practice deleted");
|
||||||
|
setPracticeToDelete(null);
|
||||||
|
await loadCoursePractices();
|
||||||
|
} catch (e: unknown) {
|
||||||
|
notifyApiError(e, "Failed to delete practice");
|
||||||
|
} finally {
|
||||||
|
setDeletingPractice(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleModulePublishStatus = async (
|
const handleModulePublishStatus = async (
|
||||||
moduleId: number,
|
moduleId: number,
|
||||||
nextStatus: PracticePublishStatus,
|
nextStatus: PracticePublishStatus,
|
||||||
|
|
@ -550,7 +623,6 @@ export function CourseDetailPage() {
|
||||||
</ContentPageDescription>
|
</ContentPageDescription>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
{practices.length === 0 ? (
|
|
||||||
<PracticeActionButton
|
<PracticeActionButton
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="rounded-[6px] border-brand-500 text-brand-500 "
|
className="rounded-[6px] border-brand-500 text-brand-500 "
|
||||||
|
|
@ -561,11 +633,14 @@ export function CourseDetailPage() {
|
||||||
backTo: "modules",
|
backTo: "modules",
|
||||||
}}
|
}}
|
||||||
parentLabel={displayTitle}
|
parentLabel={displayTitle}
|
||||||
|
disabled={practices.length > 0}
|
||||||
|
title={
|
||||||
|
practices.length > 0 ? learnEnglishPracticeLimitHint : undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Calendar className="h-4 w-4" />
|
<Calendar className="h-4 w-4" />
|
||||||
Add Practice
|
Add Practice
|
||||||
</PracticeActionButton>
|
</PracticeActionButton>
|
||||||
) : null}
|
|
||||||
<Button
|
<Button
|
||||||
className="rounded-[6px] bg-brand-500 font-semibold hover:bg-brand-600"
|
className="rounded-[6px] bg-brand-500 font-semibold hover:bg-brand-600"
|
||||||
onClick={() => setIsAddModuleOpen(true)}
|
onClick={() => setIsAddModuleOpen(true)}
|
||||||
|
|
@ -884,6 +959,8 @@ export function CourseDetailPage() {
|
||||||
onSaveAsDraft={() =>
|
onSaveAsDraft={() =>
|
||||||
void handlePracticePublishStatus(practice.id, "DRAFT")
|
void handlePracticePublishStatus(practice.id, "DRAFT")
|
||||||
}
|
}
|
||||||
|
onUnlink={() => setPracticeToUnlink(practice)}
|
||||||
|
onDelete={() => setPracticeToDelete(practice)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -925,6 +1002,90 @@ export function CourseDetailPage() {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{practiceToUnlink && practiceUnlinkParent ? (
|
||||||
|
<Dialog
|
||||||
|
open={practiceToUnlink != null}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open && !unlinkingPractice) setPracticeToUnlink(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="max-w-md rounded-2xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Remove from this course?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
<span className="font-semibold text-grayScale-800">
|
||||||
|
{practiceToUnlink.title}
|
||||||
|
</span>{" "}
|
||||||
|
will be detached from{" "}
|
||||||
|
<span className="font-semibold text-grayScale-800">
|
||||||
|
{displayTitle}
|
||||||
|
</span>
|
||||||
|
.
|
||||||
|
{parentsFromPractice(practiceToUnlink).filter(
|
||||||
|
(p) =>
|
||||||
|
!(
|
||||||
|
p.parent_kind === practiceUnlinkParent.parent_kind &&
|
||||||
|
p.parent_id === practiceUnlinkParent.parent_id
|
||||||
|
),
|
||||||
|
).length === 0
|
||||||
|
? " The practice will be unlinked until re-attached."
|
||||||
|
: " Other locations are unaffected."}
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter className="gap-2 border-t border-grayScale-100 px-6 py-4 sm:justify-end">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setPracticeToUnlink(null)}
|
||||||
|
disabled={unlinkingPractice}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => void confirmUnlinkPractice()}
|
||||||
|
disabled={unlinkingPractice}
|
||||||
|
>
|
||||||
|
{unlinkingPractice ? "Removing…" : "Remove from course"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={practiceToDelete != null}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open && !deletingPractice) setPracticeToDelete(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="max-w-md rounded-2xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Delete this practice permanently?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
<span className="font-semibold text-grayScale-800">
|
||||||
|
{practiceToDelete?.title}
|
||||||
|
</span>{" "}
|
||||||
|
and all of its questions will be deleted. This cannot be undone.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter className="gap-2 border-t border-grayScale-100 px-6 py-4 sm:justify-end">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setPracticeToDelete(null)}
|
||||||
|
disabled={deletingPractice}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
className="bg-red-500 hover:bg-red-600"
|
||||||
|
onClick={() => void confirmDeletePractice()}
|
||||||
|
disabled={deletingPractice}
|
||||||
|
>
|
||||||
|
{deletingPractice ? "Deleting…" : "Delete practice"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{deletingModule && (
|
{deletingModule && (
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
|
||||||
<div className="mx-4 w-full max-w-sm animate-in fade-in zoom-in-95 rounded-2xl bg-white shadow-2xl">
|
<div className="mx-4 w-full max-w-sm animate-in fade-in zoom-in-95 rounded-2xl bg-white shadow-2xl">
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,10 @@ import {
|
||||||
setExamPrepPracticePublishStatus,
|
setExamPrepPracticePublishStatus,
|
||||||
setLearnEnglishPracticePublishStatus,
|
setLearnEnglishPracticePublishStatus,
|
||||||
} from "../../api/courses.api";
|
} from "../../api/courses.api";
|
||||||
import { parentsFromPractice } from "../../lib/practiceParents";
|
import {
|
||||||
|
learnEnglishPracticeLimitHint,
|
||||||
|
parentsFromPractice,
|
||||||
|
} from "../../lib/practiceParents";
|
||||||
import {
|
import {
|
||||||
isPracticeParentUnlinkNotLinkedError,
|
isPracticeParentUnlinkNotLinkedError,
|
||||||
unlinkPracticeFromParent,
|
unlinkPracticeFromParent,
|
||||||
|
|
@ -312,8 +315,7 @@ export function LessonPracticesPage() {
|
||||||
</ContentPageDescription>
|
</ContentPageDescription>
|
||||||
{!isExamPrep && practices.length >= 1 ? (
|
{!isExamPrep && practices.length >= 1 ? (
|
||||||
<p className="mt-2 text-sm text-grayScale-500">
|
<p className="mt-2 text-sm text-grayScale-500">
|
||||||
This lesson already has a practice. Remove or unlink it before adding
|
{learnEnglishPracticeLimitHint}
|
||||||
another.
|
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
{!loading && !loadError ? (
|
{!loading && !loadError ? (
|
||||||
|
|
@ -339,16 +341,20 @@ export function LessonPracticesPage() {
|
||||||
/>
|
/>
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
{!isExamPrep && practices.length === 0 ? (
|
|
||||||
<PracticeActionButton
|
<PracticeActionButton
|
||||||
className="rounded-[6px] bg-brand-500 font-semibold hover:bg-brand-600"
|
className="rounded-[6px] bg-brand-500 font-semibold hover:bg-brand-600"
|
||||||
pathOptions={practicePathOptions}
|
pathOptions={practicePathOptions}
|
||||||
parentLabel={displayTitle}
|
parentLabel={displayTitle}
|
||||||
|
disabled={!isExamPrep && practices.length >= 1}
|
||||||
|
title={
|
||||||
|
!isExamPrep && practices.length >= 1
|
||||||
|
? learnEnglishPracticeLimitHint
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Calendar className="h-4 w-4" />
|
<Calendar className="h-4 w-4" />
|
||||||
Add Practice
|
Add Practice
|
||||||
</PracticeActionButton>
|
</PracticeActionButton>
|
||||||
) : null}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { ArrowLeft, Video, Calendar, Trash2, X } from "lucide-react";
|
||||||
import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
|
import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import {
|
import {
|
||||||
|
deleteParentLinkedPractice,
|
||||||
deleteTopLevelModuleLesson,
|
deleteTopLevelModuleLesson,
|
||||||
getModuleLessons,
|
getModuleLessons,
|
||||||
getPracticesByParentModule,
|
getPracticesByParentModule,
|
||||||
|
|
@ -25,7 +26,7 @@ import {
|
||||||
fetchAllOffsetPages,
|
fetchAllOffsetPages,
|
||||||
offsetPageFromListEnvelope,
|
offsetPageFromListEnvelope,
|
||||||
} from "../../lib/fetchAllOffsetPages";
|
} from "../../lib/fetchAllOffsetPages";
|
||||||
import { parentsFromPractice } from "../../lib/practiceParents";
|
import { learnEnglishPracticeLimitHint, parentsFromPractice } from "../../lib/practiceParents";
|
||||||
import {
|
import {
|
||||||
isPracticeParentUnlinkNotLinkedError,
|
isPracticeParentUnlinkNotLinkedError,
|
||||||
resolveModuleContextUnlinkParent,
|
resolveModuleContextUnlinkParent,
|
||||||
|
|
@ -138,7 +139,10 @@ export function ModuleDetailPage() {
|
||||||
>(null);
|
>(null);
|
||||||
const [practiceToUnlink, setPracticeToUnlink] =
|
const [practiceToUnlink, setPracticeToUnlink] =
|
||||||
useState<ParentContextPractice | null>(null);
|
useState<ParentContextPractice | null>(null);
|
||||||
|
const [practiceToDelete, setPracticeToDelete] =
|
||||||
|
useState<ParentContextPractice | null>(null);
|
||||||
const [unlinkingPractice, setUnlinkingPractice] = useState(false);
|
const [unlinkingPractice, setUnlinkingPractice] = useState(false);
|
||||||
|
const [deletingPractice, setDeletingPractice] = useState(false);
|
||||||
const [loadedModuleName, setLoadedModuleName] = useState<string | null>(null);
|
const [loadedModuleName, setLoadedModuleName] = useState<string | null>(null);
|
||||||
const [loadedModuleDescription, setLoadedModuleDescription] = useState<
|
const [loadedModuleDescription, setLoadedModuleDescription] = useState<
|
||||||
string | null
|
string | null
|
||||||
|
|
@ -395,6 +399,21 @@ export function ModuleDetailPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const confirmDeletePractice = async () => {
|
||||||
|
if (!practiceToDelete) return;
|
||||||
|
setDeletingPractice(true);
|
||||||
|
try {
|
||||||
|
await deleteParentLinkedPractice(practiceToDelete.id);
|
||||||
|
toast.success("Practice deleted");
|
||||||
|
setPracticeToDelete(null);
|
||||||
|
await loadModulePractices();
|
||||||
|
} catch (e: unknown) {
|
||||||
|
notifyApiError(e, "Failed to delete practice");
|
||||||
|
} finally {
|
||||||
|
setDeletingPractice(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const openEditLesson = (lesson: TopLevelModuleLessonItem) => {
|
const openEditLesson = (lesson: TopLevelModuleLessonItem) => {
|
||||||
setEditingLesson(lesson);
|
setEditingLesson(lesson);
|
||||||
setEditLessonTitle(lesson.title ?? "");
|
setEditLessonTitle(lesson.title ?? "");
|
||||||
|
|
@ -541,17 +560,19 @@ export function ModuleDetailPage() {
|
||||||
</ContentPageDescription>
|
</ContentPageDescription>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
{practices.length === 0 ? (
|
|
||||||
<PracticeActionButton
|
<PracticeActionButton
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="rounded-[6px] border-brand-500 text-brand-500 "
|
className="rounded-[6px] border-brand-500 text-brand-500 "
|
||||||
pathOptions={modulePracticePathOptions}
|
pathOptions={modulePracticePathOptions}
|
||||||
parentLabel={displayModuleName}
|
parentLabel={displayModuleName}
|
||||||
|
disabled={practices.length > 0}
|
||||||
|
title={
|
||||||
|
practices.length > 0 ? learnEnglishPracticeLimitHint : undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Calendar className="h-4 w-4" />
|
<Calendar className="h-4 w-4" />
|
||||||
Add Practice
|
Add Practice
|
||||||
</PracticeActionButton>
|
</PracticeActionButton>
|
||||||
) : null}
|
|
||||||
<Button
|
<Button
|
||||||
className="rounded-[6px] bg-brand-500 font-semibold hover:bg-brand-600"
|
className="rounded-[6px] bg-brand-500 font-semibold hover:bg-brand-600"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|
@ -646,10 +667,7 @@ export function ModuleDetailPage() {
|
||||||
onEdit={() => openEditLesson(lesson)}
|
onEdit={() => openEditLesson(lesson)}
|
||||||
onDelete={() => setDeletingLesson(lesson)}
|
onDelete={() => setDeletingLesson(lesson)}
|
||||||
description={lesson.description}
|
description={lesson.description}
|
||||||
onAddPractice={
|
onAddPractice={() =>
|
||||||
lesson.has_practice
|
|
||||||
? undefined
|
|
||||||
: () =>
|
|
||||||
setLessonPracticeChoice({
|
setLessonPracticeChoice({
|
||||||
isExamPrep: false,
|
isExamPrep: false,
|
||||||
level,
|
level,
|
||||||
|
|
@ -660,6 +678,7 @@ export function ModuleDetailPage() {
|
||||||
backTo: "lesson",
|
backTo: "lesson",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
addPracticeDisabled={!!lesson.has_practice}
|
||||||
onViewPractices={() =>
|
onViewPractices={() =>
|
||||||
navigate(
|
navigate(
|
||||||
`/new-content/learn-english/${level}/courses/${courseId}/modules/${moduleId}/lessons/${lesson.id}/practices?lessonTitle=${encodeURIComponent(lesson.title ?? "")}`,
|
`/new-content/learn-english/${level}/courses/${courseId}/modules/${moduleId}/lessons/${lesson.id}/practices?lessonTitle=${encodeURIComponent(lesson.title ?? "")}`,
|
||||||
|
|
@ -749,6 +768,7 @@ export function ModuleDetailPage() {
|
||||||
void handlePracticePublishStatus(practice.id, "DRAFT")
|
void handlePracticePublishStatus(practice.id, "DRAFT")
|
||||||
}
|
}
|
||||||
onUnlink={() => setPracticeToUnlink(practice)}
|
onUnlink={() => setPracticeToUnlink(practice)}
|
||||||
|
onDelete={() => setPracticeToDelete(practice)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -992,6 +1012,41 @@ export function ModuleDetailPage() {
|
||||||
</Dialog>
|
</Dialog>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={practiceToDelete != null}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open && !deletingPractice) setPracticeToDelete(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="max-w-md rounded-2xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Delete this practice permanently?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
<span className="font-semibold text-grayScale-800">
|
||||||
|
{practiceToDelete?.title}
|
||||||
|
</span>{" "}
|
||||||
|
and all of its questions will be deleted. This cannot be undone.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter className="gap-2 border-t border-grayScale-100 px-6 py-4 sm:justify-end">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setPracticeToDelete(null)}
|
||||||
|
disabled={deletingPractice}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
className="bg-red-500 hover:bg-red-600"
|
||||||
|
onClick={() => void confirmDeletePractice()}
|
||||||
|
disabled={deletingPractice}
|
||||||
|
>
|
||||||
|
{deletingPractice ? "Deleting…" : "Delete practice"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{lessonPracticeChoice && lessonPracticeChoicePaths ? (
|
{lessonPracticeChoice && lessonPracticeChoicePaths ? (
|
||||||
<PracticeActionChoiceDialog
|
<PracticeActionChoiceDialog
|
||||||
open={lessonPracticeChoice != null}
|
open={lessonPracticeChoice != null}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import {
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "../../../components/ui/dialog";
|
} from "../../../components/ui/dialog";
|
||||||
import { isAdminOrSuperAdminRole } from "../../../lib/sessionRole";
|
import { isAdminOrSuperAdminRole } from "../../../lib/sessionRole";
|
||||||
|
import { learnEnglishPracticeLimitHint } from "../../../lib/practiceParents";
|
||||||
import { cn } from "../../../lib/utils";
|
import { cn } from "../../../lib/utils";
|
||||||
import { SearchHighlight } from "../../../components/SearchHighlight";
|
import { SearchHighlight } from "../../../components/SearchHighlight";
|
||||||
import {
|
import {
|
||||||
|
|
@ -85,6 +86,8 @@ interface VideoCardProps {
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
/** When set (e.g. on module lesson cards), shows an "Add practice" control scoped to this lesson. */
|
/** When set (e.g. on module lesson cards), shows an "Add practice" control scoped to this lesson. */
|
||||||
onAddPractice?: () => void;
|
onAddPractice?: () => void;
|
||||||
|
/** When true, the lesson card shows a disabled "Add practice" control. */
|
||||||
|
addPracticeDisabled?: boolean;
|
||||||
/** When set with hoverModuleActions, shows a book icon next to edit/delete on thumbnail hover. */
|
/** When set with hoverModuleActions, shows a book icon next to edit/delete on thumbnail hover. */
|
||||||
onViewPractices?: () => void;
|
onViewPractices?: () => void;
|
||||||
onPublish?: () => void;
|
onPublish?: () => void;
|
||||||
|
|
@ -113,6 +116,7 @@ export function VideoCard({
|
||||||
onDelete,
|
onDelete,
|
||||||
onPublish,
|
onPublish,
|
||||||
onAddPractice,
|
onAddPractice,
|
||||||
|
addPracticeDisabled = false,
|
||||||
onViewPractices,
|
onViewPractices,
|
||||||
onTogglePublishStatus,
|
onTogglePublishStatus,
|
||||||
publishStatusUpdating = false,
|
publishStatusUpdating = false,
|
||||||
|
|
@ -575,8 +579,11 @@ export function VideoCard({
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="h-9 w-full rounded-[6px] border-brand-200 text-[12px] font-bold text-brand-600 hover:bg-brand-50"
|
className="h-9 w-full rounded-[6px] border-brand-200 text-[12px] font-bold text-brand-600 hover:bg-brand-50"
|
||||||
|
disabled={addPracticeDisabled}
|
||||||
|
title={addPracticeDisabled ? learnEnglishPracticeLimitHint : undefined}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
if (addPracticeDisabled) return;
|
||||||
onAddPractice();
|
onAddPractice();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user