Enable skill-based course creation on the courses page.
Wire the skill-based catalog to LMS program/course APIs so admins can create, edit, and manage courses without the proficiency-only guard. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
564fbf47a8
commit
687eb964cc
|
|
@ -22,15 +22,23 @@ import {
|
||||||
DialogClose,
|
DialogClose,
|
||||||
} from "../../components/ui/dialog";
|
} from "../../components/ui/dialog";
|
||||||
import { Input } from "../../components/ui/input";
|
import { Input } from "../../components/ui/input";
|
||||||
|
import { Textarea } from "../../components/ui/textarea";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { ResolvedImage } from "../../components/media/ResolvedImage";
|
import { ResolvedImage } from "../../components/media/ResolvedImage";
|
||||||
import {
|
import {
|
||||||
createExamPrepCatalogCourse,
|
createExamPrepCatalogCourse,
|
||||||
|
createProgramCourse,
|
||||||
|
deleteExamPrepCatalogCourse,
|
||||||
|
deleteTopLevelCourse,
|
||||||
getExamPrepCatalogCourses,
|
getExamPrepCatalogCourses,
|
||||||
|
getLearningPrograms,
|
||||||
|
getProgramCourses,
|
||||||
setExamPrepCatalogCourseAccessTier,
|
setExamPrepCatalogCourseAccessTier,
|
||||||
setExamPrepCatalogCoursePublishStatus,
|
setExamPrepCatalogCoursePublishStatus,
|
||||||
|
setProgramCourseAccessTier,
|
||||||
|
setProgramCoursePublishStatus,
|
||||||
updateExamPrepCatalogCourse,
|
updateExamPrepCatalogCourse,
|
||||||
deleteExamPrepCatalogCourse,
|
updateTopLevelCourse,
|
||||||
} from "../../api/courses.api";
|
} from "../../api/courses.api";
|
||||||
import { ContentPublishStatusChip } from "./components/ContentPublishStatusChip";
|
import { ContentPublishStatusChip } from "./components/ContentPublishStatusChip";
|
||||||
import { ContentAccessTierChip } from "./components/ContentAccessTierChip";
|
import { ContentAccessTierChip } from "./components/ContentAccessTierChip";
|
||||||
|
|
@ -39,7 +47,9 @@ import { ContentPageDescription } from "./components/ContentPageDescription";
|
||||||
import type {
|
import type {
|
||||||
ContentAccessTier,
|
ContentAccessTier,
|
||||||
ExamPrepCatalogCourseItem,
|
ExamPrepCatalogCourseItem,
|
||||||
|
LearningProgramListItem,
|
||||||
PracticePublishStatus,
|
PracticePublishStatus,
|
||||||
|
ProgramCourseListItem,
|
||||||
} from "../../types/course.types";
|
} from "../../types/course.types";
|
||||||
import {
|
import {
|
||||||
filterBySearchAndPublishStatus,
|
filterBySearchAndPublishStatus,
|
||||||
|
|
@ -55,19 +65,10 @@ import {
|
||||||
offsetPageFromListEnvelope,
|
offsetPageFromListEnvelope,
|
||||||
} from "../../lib/fetchAllOffsetPages";
|
} from "../../lib/fetchAllOffsetPages";
|
||||||
|
|
||||||
export function ProgramDetailPage() {
|
type CourseListRow = {
|
||||||
const navigate = useNavigate();
|
|
||||||
const { programType } = useParams<{ programType: string }>();
|
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
|
||||||
const [createName, setCreateName] = useState("");
|
|
||||||
const [createThumbnail, setCreateThumbnail] = useState("");
|
|
||||||
const [createThumbnailFromUpload, setCreateThumbnailFromUpload] = useState(false);
|
|
||||||
const [creating, setCreating] = useState(false);
|
|
||||||
const [uploadingThumbnail, setUploadingThumbnail] = useState(false);
|
|
||||||
const createThumbnailFileInputRef = useRef<HTMLInputElement>(null);
|
|
||||||
const [createdCourses, setCreatedCourses] = useState<
|
|
||||||
{
|
|
||||||
id: number;
|
id: number;
|
||||||
|
programId?: number;
|
||||||
|
programName?: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
thumbnail?: string | null;
|
thumbnail?: string | null;
|
||||||
|
|
@ -77,7 +78,24 @@ export function ProgramDetailPage() {
|
||||||
unitsCount: number;
|
unitsCount: number;
|
||||||
modulesCount: number;
|
modulesCount: number;
|
||||||
lessonsCount: number;
|
lessonsCount: number;
|
||||||
}[]
|
};
|
||||||
|
|
||||||
|
export function ProgramDetailPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { programType } = useParams<{ programType: string }>();
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [createName, setCreateName] = useState("");
|
||||||
|
const [createDescription, setCreateDescription] = useState("");
|
||||||
|
const [createSortOrder, setCreateSortOrder] = useState("");
|
||||||
|
const [createProgramId, setCreateProgramId] = useState("");
|
||||||
|
const [createThumbnail, setCreateThumbnail] = useState("");
|
||||||
|
const [createThumbnailFromUpload, setCreateThumbnailFromUpload] = useState(false);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
const [uploadingThumbnail, setUploadingThumbnail] = useState(false);
|
||||||
|
const createThumbnailFileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [createdCourses, setCreatedCourses] = useState<CourseListRow[]>([]);
|
||||||
|
const [learningPrograms, setLearningPrograms] = useState<
|
||||||
|
LearningProgramListItem[]
|
||||||
>([]);
|
>([]);
|
||||||
const [publishStatusUpdatingId, setPublishStatusUpdatingId] = useState<
|
const [publishStatusUpdatingId, setPublishStatusUpdatingId] = useState<
|
||||||
number | null
|
number | null
|
||||||
|
|
@ -88,6 +106,7 @@ export function ProgramDetailPage() {
|
||||||
const [catalogLoading, setCatalogLoading] = useState(false);
|
const [catalogLoading, setCatalogLoading] = useState(false);
|
||||||
const [editingCourseId, setEditingCourseId] = useState<number | null>(null);
|
const [editingCourseId, setEditingCourseId] = useState<number | null>(null);
|
||||||
const [editName, setEditName] = useState("");
|
const [editName, setEditName] = useState("");
|
||||||
|
const [editDescription, setEditDescription] = useState("");
|
||||||
const [editThumbnail, setEditThumbnail] = useState("");
|
const [editThumbnail, setEditThumbnail] = useState("");
|
||||||
const [editSortOrder, setEditSortOrder] = useState("1");
|
const [editSortOrder, setEditSortOrder] = useState("1");
|
||||||
const [savingEdit, setSavingEdit] = useState(false);
|
const [savingEdit, setSavingEdit] = useState(false);
|
||||||
|
|
@ -114,19 +133,10 @@ export function ProgramDetailPage() {
|
||||||
|
|
||||||
const currentProgram =
|
const currentProgram =
|
||||||
programs[programType || "proficiency"] || programs.proficiency;
|
programs[programType || "proficiency"] || programs.proficiency;
|
||||||
|
const isProficiency = programType === "proficiency";
|
||||||
|
const isSkillBased = programType === "skill-based";
|
||||||
|
|
||||||
const loadCatalogCourses = useCallback(async () => {
|
const mapExamPrepCourse = (row: ExamPrepCatalogCourseItem): CourseListRow => ({
|
||||||
if (programType !== "proficiency") return;
|
|
||||||
setCatalogLoading(true);
|
|
||||||
try {
|
|
||||||
const list = await fetchAllOffsetPages(async (offset, limit) =>
|
|
||||||
offsetPageFromListEnvelope<ExamPrepCatalogCourseItem>(
|
|
||||||
await getExamPrepCatalogCourses({ limit, offset }),
|
|
||||||
"catalog_courses",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
setCreatedCourses(
|
|
||||||
list.map((row) => ({
|
|
||||||
id: Number(row.id),
|
id: Number(row.id),
|
||||||
name: row.name?.trim() || `Course ${row.id}`,
|
name: row.name?.trim() || `Course ${row.id}`,
|
||||||
description: row.description?.trim() || "",
|
description: row.description?.trim() || "",
|
||||||
|
|
@ -137,25 +147,96 @@ export function ProgramDetailPage() {
|
||||||
unitsCount: Number(row.units_count ?? 0),
|
unitsCount: Number(row.units_count ?? 0),
|
||||||
modulesCount: Number(row.modules_count ?? 0),
|
modulesCount: Number(row.modules_count ?? 0),
|
||||||
lessonsCount: Number(row.lessons_count ?? 0),
|
lessonsCount: Number(row.lessons_count ?? 0),
|
||||||
})),
|
});
|
||||||
|
|
||||||
|
const mapProgramCourse = (
|
||||||
|
row: ProgramCourseListItem,
|
||||||
|
programName?: string,
|
||||||
|
): CourseListRow => ({
|
||||||
|
id: Number(row.id),
|
||||||
|
programId: Number(row.program_id),
|
||||||
|
programName: programName?.trim() || undefined,
|
||||||
|
name: row.name?.trim() || `Course ${row.id}`,
|
||||||
|
description: row.description?.trim() || "",
|
||||||
|
thumbnail: row.thumbnail?.trim() || row.thumbnail_url?.trim() || null,
|
||||||
|
sortOrder: Number(row.sort_order ?? 0),
|
||||||
|
publishStatus: row.publish_status ?? null,
|
||||||
|
accessTier: row.access_tier ?? null,
|
||||||
|
unitsCount: 0,
|
||||||
|
modulesCount: Number(row.module_count ?? row.modules_count ?? 0),
|
||||||
|
lessonsCount: Number(row.lesson_count ?? 0),
|
||||||
|
});
|
||||||
|
|
||||||
|
const loadCourses = useCallback(async () => {
|
||||||
|
if (!isProficiency && !isSkillBased) return;
|
||||||
|
setCatalogLoading(true);
|
||||||
|
try {
|
||||||
|
if (isProficiency) {
|
||||||
|
const list = await fetchAllOffsetPages(async (offset, limit) =>
|
||||||
|
offsetPageFromListEnvelope<ExamPrepCatalogCourseItem>(
|
||||||
|
await getExamPrepCatalogCourses({ limit, offset }),
|
||||||
|
"catalog_courses",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setCreatedCourses(list.map(mapExamPrepCourse));
|
||||||
|
setLearningPrograms([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const programsList = await fetchAllOffsetPages(async (offset, limit) =>
|
||||||
|
offsetPageFromListEnvelope<LearningProgramListItem>(
|
||||||
|
await getLearningPrograms({ limit, offset }),
|
||||||
|
"programs",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setLearningPrograms(programsList);
|
||||||
|
const programNameById = new Map(
|
||||||
|
programsList.map((program) => [program.id, program.name?.trim() || ""]),
|
||||||
|
);
|
||||||
|
|
||||||
|
const coursePages = await Promise.all(
|
||||||
|
programsList.map((program) =>
|
||||||
|
fetchAllOffsetPages(async (offset, limit) =>
|
||||||
|
offsetPageFromListEnvelope<ProgramCourseListItem>(
|
||||||
|
await getProgramCourses(program.id, { limit, offset }),
|
||||||
|
"courses",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
setCreatedCourses(
|
||||||
|
coursePages
|
||||||
|
.flat()
|
||||||
|
.map((row) =>
|
||||||
|
mapProgramCourse(row, programNameById.get(row.program_id)),
|
||||||
|
)
|
||||||
|
.sort((a, b) => a.sortOrder - b.sortOrder || a.id - b.id),
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
notifyApiError(error, "Failed to fetch catalog courses");
|
notifyApiError(
|
||||||
|
error,
|
||||||
|
isProficiency ? "Failed to fetch catalog courses" : "Failed to fetch courses",
|
||||||
|
);
|
||||||
setCreatedCourses([]);
|
setCreatedCourses([]);
|
||||||
|
if (isSkillBased) {
|
||||||
|
setLearningPrograms([]);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setCatalogLoading(false);
|
setCatalogLoading(false);
|
||||||
}
|
}
|
||||||
}, [programType]);
|
}, [isProficiency, isSkillBased]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void loadCatalogCourses();
|
void loadCourses();
|
||||||
}, [loadCatalogCourses]);
|
}, [loadCourses]);
|
||||||
const proficiencyCourses = useMemo(
|
const displayCourses = useMemo(
|
||||||
() => [
|
() =>
|
||||||
...currentProgram.courses,
|
createdCourses.map((course) => ({
|
||||||
...createdCourses.map((course) => ({
|
|
||||||
id: course.id,
|
id: course.id,
|
||||||
|
programId: course.programId,
|
||||||
|
programName: course.programName,
|
||||||
name: course.name,
|
name: course.name,
|
||||||
description: course.description,
|
description: course.description,
|
||||||
units_count: course.unitsCount,
|
units_count: course.unitsCount,
|
||||||
|
|
@ -168,22 +249,25 @@ export function ProgramDetailPage() {
|
||||||
access_tier: course.accessTier,
|
access_tier: course.accessTier,
|
||||||
buttonText: "View Detail",
|
buttonText: "View Detail",
|
||||||
})),
|
})),
|
||||||
],
|
[createdCourses],
|
||||||
[createdCourses, currentProgram.courses],
|
|
||||||
);
|
);
|
||||||
const [listSearch, setListSearch] = useState("");
|
const [listSearch, setListSearch] = useState("");
|
||||||
const [publishStatusFilter, setPublishStatusFilter] =
|
const [publishStatusFilter, setPublishStatusFilter] =
|
||||||
useState<PublishStatusFilter>("all");
|
useState<PublishStatusFilter>("all");
|
||||||
|
|
||||||
const filteredProficiencyCourses = useMemo(
|
const filteredCourses = useMemo(
|
||||||
() =>
|
() =>
|
||||||
filterBySearchAndPublishStatus(proficiencyCourses, {
|
filterBySearchAndPublishStatus(displayCourses, {
|
||||||
search: listSearch,
|
search: listSearch,
|
||||||
publishStatusFilter,
|
publishStatusFilter,
|
||||||
getSearchFields: (c) => [c.name, c.description],
|
getSearchFields: (c) => [
|
||||||
|
c.name,
|
||||||
|
c.description,
|
||||||
|
c.programName ?? "",
|
||||||
|
],
|
||||||
getPublishStatus: (c) => c.publish_status,
|
getPublishStatus: (c) => c.publish_status,
|
||||||
}),
|
}),
|
||||||
[listSearch, proficiencyCourses, publishStatusFilter],
|
[listSearch, displayCourses, publishStatusFilter],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCoursePublishStatus = async (
|
const handleCoursePublishStatus = async (
|
||||||
|
|
@ -192,9 +276,15 @@ export function ProgramDetailPage() {
|
||||||
) => {
|
) => {
|
||||||
setPublishStatusUpdatingId(courseId);
|
setPublishStatusUpdatingId(courseId);
|
||||||
try {
|
try {
|
||||||
|
if (isProficiency) {
|
||||||
await setExamPrepCatalogCoursePublishStatus(courseId, {
|
await setExamPrepCatalogCoursePublishStatus(courseId, {
|
||||||
publish_status: nextStatus,
|
publish_status: nextStatus,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
await setProgramCoursePublishStatus(courseId, {
|
||||||
|
publish_status: nextStatus,
|
||||||
|
});
|
||||||
|
}
|
||||||
setCreatedCourses((prev) =>
|
setCreatedCourses((prev) =>
|
||||||
prev.map((c) =>
|
prev.map((c) =>
|
||||||
c.id === courseId ? { ...c, publishStatus: nextStatus } : c,
|
c.id === courseId ? { ...c, publishStatus: nextStatus } : c,
|
||||||
|
|
@ -216,9 +306,15 @@ export function ProgramDetailPage() {
|
||||||
) => {
|
) => {
|
||||||
setAccessTierUpdatingId(courseId);
|
setAccessTierUpdatingId(courseId);
|
||||||
try {
|
try {
|
||||||
|
if (isProficiency) {
|
||||||
await setExamPrepCatalogCourseAccessTier(courseId, {
|
await setExamPrepCatalogCourseAccessTier(courseId, {
|
||||||
access_tier: nextTier,
|
access_tier: nextTier,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
await setProgramCourseAccessTier(courseId, {
|
||||||
|
access_tier: nextTier,
|
||||||
|
});
|
||||||
|
}
|
||||||
setCreatedCourses((prev) =>
|
setCreatedCourses((prev) =>
|
||||||
prev.map((c) =>
|
prev.map((c) =>
|
||||||
c.id === courseId ? { ...c, accessTier: nextTier } : c,
|
c.id === courseId ? { ...c, accessTier: nextTier } : c,
|
||||||
|
|
@ -283,11 +379,16 @@ export function ProgramDetailPage() {
|
||||||
return uploadedUrl;
|
return uploadedUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const clearCreateCourseForm = () => {
|
||||||
|
setCreateName("");
|
||||||
|
setCreateDescription("");
|
||||||
|
setCreateSortOrder("");
|
||||||
|
setCreateProgramId("");
|
||||||
|
setCreateThumbnail("");
|
||||||
|
setCreateThumbnailFromUpload(false);
|
||||||
|
};
|
||||||
|
|
||||||
const handleCreateCourse = async () => {
|
const handleCreateCourse = async () => {
|
||||||
if (programType !== "proficiency") {
|
|
||||||
toast.error("Create Course is supported only for proficiency catalog.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const name = createName.trim();
|
const name = createName.trim();
|
||||||
if (!name) {
|
if (!name) {
|
||||||
toast.error("Course name is required");
|
toast.error("Course name is required");
|
||||||
|
|
@ -310,6 +411,7 @@ export function ProgramDetailPage() {
|
||||||
thumbnailToSend = uploadedUrl;
|
thumbnailToSend = uploadedUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isProficiency) {
|
||||||
const response = await createExamPrepCatalogCourse({
|
const response = await createExamPrepCatalogCourse({
|
||||||
name,
|
name,
|
||||||
description: null,
|
description: null,
|
||||||
|
|
@ -319,24 +421,36 @@ export function ProgramDetailPage() {
|
||||||
if (!row?.id) {
|
if (!row?.id) {
|
||||||
throw new Error("Missing created course payload");
|
throw new Error("Missing created course payload");
|
||||||
}
|
}
|
||||||
setCreatedCourses((prev) => [
|
} else if (isSkillBased) {
|
||||||
{
|
const programId = Number(createProgramId);
|
||||||
id: row.id,
|
if (!Number.isFinite(programId) || programId < 1) {
|
||||||
name: row.name ?? name,
|
toast.error("Please select a program");
|
||||||
description: row.description?.trim() || "",
|
return;
|
||||||
thumbnail: row.thumbnail?.trim() || null,
|
}
|
||||||
sortOrder: Number(row.sort_order ?? 0),
|
const sortOrderRaw = createSortOrder.trim();
|
||||||
unitsCount: Number(row.units_count ?? 0),
|
if (!sortOrderRaw) {
|
||||||
modulesCount: Number(row.modules_count ?? 0),
|
toast.error("Sort order is required");
|
||||||
lessonsCount: Number(row.lessons_count ?? 0),
|
return;
|
||||||
},
|
}
|
||||||
...prev,
|
const sort_order = Number(sortOrderRaw);
|
||||||
]);
|
if (!Number.isInteger(sort_order) || sort_order < 0) {
|
||||||
await loadCatalogCourses();
|
toast.error("Sort order must be a whole number of 0 or greater");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await createProgramCourse(programId, {
|
||||||
|
name,
|
||||||
|
description: createDescription.trim(),
|
||||||
|
thumbnail: thumbnailToSend ?? "",
|
||||||
|
sort_order,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast.error("Unsupported program type");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await loadCourses();
|
||||||
toast.success("Course created");
|
toast.success("Course created");
|
||||||
setCreateName("");
|
clearCreateCourseForm();
|
||||||
setCreateThumbnail("");
|
|
||||||
setCreateThumbnailFromUpload(false);
|
|
||||||
setCreateOpen(false);
|
setCreateOpen(false);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
@ -346,11 +460,12 @@ export function ProgramDetailPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const openEditCourse = (course: (typeof proficiencyCourses)[number]) => {
|
const openEditCourse = (course: (typeof displayCourses)[number]) => {
|
||||||
const idNum = Number(course.id);
|
const idNum = Number(course.id);
|
||||||
if (!Number.isFinite(idNum)) return;
|
if (!Number.isFinite(idNum)) return;
|
||||||
setEditingCourseId(idNum);
|
setEditingCourseId(idNum);
|
||||||
setEditName(String(course.name ?? ""));
|
setEditName(String(course.name ?? ""));
|
||||||
|
setEditDescription(String(course.description ?? ""));
|
||||||
setEditThumbnail(String(course.thumbnail ?? ""));
|
setEditThumbnail(String(course.thumbnail ?? ""));
|
||||||
setEditSortOrder(String(course.sort_order ?? 1));
|
setEditSortOrder(String(course.sort_order ?? 1));
|
||||||
};
|
};
|
||||||
|
|
@ -359,6 +474,7 @@ export function ProgramDetailPage() {
|
||||||
if (savingEdit || uploadingEditThumbnail) return;
|
if (savingEdit || uploadingEditThumbnail) return;
|
||||||
setEditingCourseId(null);
|
setEditingCourseId(null);
|
||||||
setEditName("");
|
setEditName("");
|
||||||
|
setEditDescription("");
|
||||||
setEditThumbnail("");
|
setEditThumbnail("");
|
||||||
setEditSortOrder("1");
|
setEditSortOrder("1");
|
||||||
};
|
};
|
||||||
|
|
@ -406,7 +522,11 @@ export function ProgramDetailPage() {
|
||||||
const minioThumbnail = await resolveThumbnailToMinioUrl(editThumbnail);
|
const minioThumbnail = await resolveThumbnailToMinioUrl(editThumbnail);
|
||||||
const existing = createdCourses.find((c) => c.id === editingCourseId);
|
const existing = createdCourses.find((c) => c.id === editingCourseId);
|
||||||
const preservedDescription =
|
const preservedDescription =
|
||||||
typeof existing?.description === "string" ? existing.description.trim() || null : null;
|
typeof existing?.description === "string"
|
||||||
|
? existing.description.trim() || null
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (isProficiency) {
|
||||||
const response = await updateExamPrepCatalogCourse(editingCourseId, {
|
const response = await updateExamPrepCatalogCourse(editingCourseId, {
|
||||||
name,
|
name,
|
||||||
description: preservedDescription,
|
description: preservedDescription,
|
||||||
|
|
@ -420,17 +540,31 @@ export function ProgramDetailPage() {
|
||||||
? {
|
? {
|
||||||
...course,
|
...course,
|
||||||
name: row?.name ?? name,
|
name: row?.name ?? name,
|
||||||
description: row?.description?.trim() || preservedDescription || "",
|
description:
|
||||||
|
row?.description?.trim() || preservedDescription || "",
|
||||||
thumbnail: row?.thumbnail?.trim() || null,
|
thumbnail: row?.thumbnail?.trim() || null,
|
||||||
sortOrder: Number(row?.sort_order ?? sortOrderNum),
|
sortOrder: Number(row?.sort_order ?? sortOrderNum),
|
||||||
unitsCount: Number(row?.units_count ?? course.unitsCount ?? 0),
|
unitsCount: Number(row?.units_count ?? course.unitsCount ?? 0),
|
||||||
modulesCount: Number(row?.modules_count ?? course.modulesCount ?? 0),
|
modulesCount: Number(
|
||||||
lessonsCount: Number(row?.lessons_count ?? course.lessonsCount ?? 0),
|
row?.modules_count ?? course.modulesCount ?? 0,
|
||||||
|
),
|
||||||
|
lessonsCount: Number(
|
||||||
|
row?.lessons_count ?? course.lessonsCount ?? 0,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
: course,
|
: course,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await loadCatalogCourses();
|
} else {
|
||||||
|
await updateTopLevelCourse(editingCourseId, {
|
||||||
|
name,
|
||||||
|
description: editDescription.trim(),
|
||||||
|
thumbnail: minioThumbnail,
|
||||||
|
sort_order: sortOrderNum,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await loadCourses();
|
||||||
toast.success("Course updated");
|
toast.success("Course updated");
|
||||||
closeEditCourse();
|
closeEditCourse();
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
|
@ -445,8 +579,12 @@ export function ProgramDetailPage() {
|
||||||
if (!deletingCourseId) return;
|
if (!deletingCourseId) return;
|
||||||
setDeletingCourse(true);
|
setDeletingCourse(true);
|
||||||
try {
|
try {
|
||||||
|
if (isProficiency) {
|
||||||
await deleteExamPrepCatalogCourse(deletingCourseId);
|
await deleteExamPrepCatalogCourse(deletingCourseId);
|
||||||
await loadCatalogCourses();
|
} else {
|
||||||
|
await deleteTopLevelCourse(deletingCourseId);
|
||||||
|
}
|
||||||
|
await loadCourses();
|
||||||
toast.success("Course deleted");
|
toast.success("Course deleted");
|
||||||
setDeletingCourseId(null);
|
setDeletingCourseId(null);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
|
@ -517,6 +655,7 @@ export function ProgramDetailPage() {
|
||||||
open={createOpen}
|
open={createOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open && (creating || uploadingThumbnail)) return;
|
if (!open && (creating || uploadingThumbnail)) return;
|
||||||
|
if (!open) clearCreateCourseForm();
|
||||||
setCreateOpen(open);
|
setCreateOpen(open);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
@ -535,6 +674,72 @@ export function ProgramDetailPage() {
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="min-h-0 flex-1 space-y-8 overflow-y-auto p-8">
|
<div className="min-h-0 flex-1 space-y-8 overflow-y-auto p-8">
|
||||||
|
{isSkillBased ? (
|
||||||
|
<>
|
||||||
|
<div className="space-y-3">
|
||||||
|
<label className="text-[15px] text-grayScale-800">
|
||||||
|
Program
|
||||||
|
</label>
|
||||||
|
{learningPrograms.length === 0 ? (
|
||||||
|
<p className="text-sm text-grayScale-500">
|
||||||
|
No learning programs found. Create a program first
|
||||||
|
from{" "}
|
||||||
|
<Link
|
||||||
|
to="/new-content/learn-english"
|
||||||
|
className="font-semibold text-brand-500 hover:underline"
|
||||||
|
>
|
||||||
|
Learn English
|
||||||
|
</Link>
|
||||||
|
.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<select
|
||||||
|
value={createProgramId}
|
||||||
|
onChange={(e) => setCreateProgramId(e.target.value)}
|
||||||
|
className="h-12 w-full rounded-[8px] border border-grayScale-400 bg-white px-4 text-[15px] text-grayScale-900 focus:outline-none focus:ring-2 focus:ring-brand-500/20"
|
||||||
|
disabled={creating}
|
||||||
|
>
|
||||||
|
<option value="">Select a program…</option>
|
||||||
|
{learningPrograms.map((program) => (
|
||||||
|
<option key={program.id} value={String(program.id)}>
|
||||||
|
{program.name?.trim() || `Program ${program.id}`}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<label className="text-[15px] text-grayScale-800">
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<Textarea
|
||||||
|
value={createDescription}
|
||||||
|
onChange={(e) => setCreateDescription(e.target.value)}
|
||||||
|
placeholder="Short summary of the course"
|
||||||
|
rows={3}
|
||||||
|
className="min-h-[88px] resize-y rounded-[8px] border-grayScale-400 px-4 text-[15px]"
|
||||||
|
disabled={creating || uploadingThumbnail}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<label className="text-[15px] text-grayScale-800">
|
||||||
|
Sort Order
|
||||||
|
</label>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
value={createSortOrder}
|
||||||
|
onChange={(e) => setCreateSortOrder(e.target.value)}
|
||||||
|
placeholder="e.g. 1"
|
||||||
|
className="h-12 border-grayScale-400 rounded-[8px] px-4 placeholder:text-grayScale-400 text-[15px] focus:ring-brand-500/20"
|
||||||
|
disabled={creating}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<label className="text-[15px] text-grayScale-800">
|
<label className="text-[15px] text-grayScale-800">
|
||||||
Name
|
Name
|
||||||
|
|
@ -542,7 +747,11 @@ export function ProgramDetailPage() {
|
||||||
<Input
|
<Input
|
||||||
value={createName}
|
value={createName}
|
||||||
onChange={(e) => setCreateName(e.target.value)}
|
onChange={(e) => setCreateName(e.target.value)}
|
||||||
placeholder="e.g. TOEFL, IELTS"
|
placeholder={
|
||||||
|
isSkillBased
|
||||||
|
? "e.g. English For Professionals"
|
||||||
|
: "e.g. TOEFL, IELTS"
|
||||||
|
}
|
||||||
className="h-12 border-grayScale-400 rounded-[8px] px-4 placeholder:text-grayScale-400 text-[15px] focus:ring-brand-500/20"
|
className="h-12 border-grayScale-400 rounded-[8px] px-4 placeholder:text-grayScale-400 text-[15px] focus:ring-brand-500/20"
|
||||||
disabled={creating}
|
disabled={creating}
|
||||||
/>
|
/>
|
||||||
|
|
@ -625,7 +834,11 @@ export function ProgramDetailPage() {
|
||||||
</DialogClose>
|
</DialogClose>
|
||||||
<Button
|
<Button
|
||||||
className="h-11 px-8 rounded-[6px] bg-brand-500 text-white font-bold hover:bg-brand-600"
|
className="h-11 px-8 rounded-[6px] bg-brand-500 text-white font-bold hover:bg-brand-600"
|
||||||
disabled={creating || uploadingThumbnail}
|
disabled={
|
||||||
|
creating ||
|
||||||
|
uploadingThumbnail ||
|
||||||
|
(isSkillBased && learningPrograms.length === 0)
|
||||||
|
}
|
||||||
onClick={() => void handleCreateCourse()}
|
onClick={() => void handleCreateCourse()}
|
||||||
>
|
>
|
||||||
{creating ? "Creating..." : "Create Course"}
|
{creating ? "Creating..." : "Create Course"}
|
||||||
|
|
@ -654,33 +867,38 @@ export function ProgramDetailPage() {
|
||||||
|
|
||||||
{/* Cards Grid */}
|
{/* Cards Grid */}
|
||||||
<div className="mt-10 space-y-6">
|
<div className="mt-10 space-y-6">
|
||||||
{programType === "proficiency" && !catalogLoading && proficiencyCourses.length > 0 ? (
|
{!catalogLoading && displayCourses.length > 0 ? (
|
||||||
<ContentListSearchFilterBar
|
<ContentListSearchFilterBar
|
||||||
search={listSearch}
|
search={listSearch}
|
||||||
onSearchChange={setListSearch}
|
onSearchChange={setListSearch}
|
||||||
publishStatusFilter={publishStatusFilter}
|
publishStatusFilter={publishStatusFilter}
|
||||||
onPublishStatusFilterChange={setPublishStatusFilter}
|
onPublishStatusFilterChange={setPublishStatusFilter}
|
||||||
searchPlaceholder="Search courses by name or description…"
|
searchPlaceholder={
|
||||||
searchAriaLabel="Search catalog courses"
|
isSkillBased
|
||||||
|
? "Search courses by name, description, or program…"
|
||||||
|
: "Search courses by name or description…"
|
||||||
|
}
|
||||||
|
searchAriaLabel={
|
||||||
|
isSkillBased ? "Search skill-based courses" : "Search catalog courses"
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="flex flex-wrap gap-8">
|
<div className="flex flex-wrap gap-8">
|
||||||
{programType === "proficiency" && catalogLoading ? (
|
{catalogLoading ? (
|
||||||
<p className="text-sm text-grayScale-500">Loading catalog courses...</p>
|
<p className="text-sm text-grayScale-500">Loading courses...</p>
|
||||||
) : null}
|
) : null}
|
||||||
{(programType === "proficiency"
|
{displayCourses.length === 0 && !catalogLoading ? (
|
||||||
? proficiencyCourses
|
|
||||||
: currentProgram.courses
|
|
||||||
).length === 0 && !catalogLoading ? (
|
|
||||||
<div className="w-full rounded-xl border border-dashed border-grayScale-200 bg-grayScale-50/50 px-6 py-14 text-center">
|
<div className="w-full rounded-xl border border-dashed border-grayScale-200 bg-grayScale-50/50 px-6 py-14 text-center">
|
||||||
<p className="text-sm font-medium text-grayScale-600">
|
<p className="text-sm font-medium text-grayScale-600">
|
||||||
No catalog courses yet
|
{isSkillBased ? "No skill-based courses yet" : "No catalog courses yet"}
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-1 text-sm text-grayScale-400">
|
<p className="mt-1 text-sm text-grayScale-400">
|
||||||
Create your first Duolingo/IELTS catalog course to start organizing units, modules, and lessons.
|
{isSkillBased
|
||||||
|
? "Create your first course under a learning program to start organizing modules and lessons."
|
||||||
|
: "Create your first Duolingo/IELTS catalog course to start organizing units, modules, and lessons."}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : programType === "proficiency" && filteredProficiencyCourses.length === 0 ? (
|
) : filteredCourses.length === 0 ? (
|
||||||
<div className="w-full rounded-xl border border-dashed border-grayScale-200 bg-grayScale-50/50 px-6 py-14 text-center">
|
<div className="w-full rounded-xl border border-dashed border-grayScale-200 bg-grayScale-50/50 px-6 py-14 text-center">
|
||||||
<p className="text-sm font-medium text-grayScale-600">
|
<p className="text-sm font-medium text-grayScale-600">
|
||||||
No courses match your search or status filter
|
No courses match your search or status filter
|
||||||
|
|
@ -692,15 +910,11 @@ export function ProgramDetailPage() {
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
(programType === "proficiency"
|
filteredCourses.map((course: any) => (
|
||||||
? filteredProficiencyCourses
|
|
||||||
: currentProgram.courses
|
|
||||||
).map((course: any) => (
|
|
||||||
<Card
|
<Card
|
||||||
key={course.id}
|
key={course.id}
|
||||||
className="group relative bg-white w-[500px] rounded-[20px] border border-grayScale-100 p-6 flex flex-col items-start shadow-sm hover:shadow-md transition-shadow"
|
className="group relative bg-white w-[500px] rounded-[20px] border border-grayScale-100 p-6 flex flex-col items-start shadow-sm hover:shadow-md transition-shadow"
|
||||||
>
|
>
|
||||||
{programType === "proficiency" ? (
|
|
||||||
<div className="absolute right-3 top-3 z-10 flex translate-y-1 gap-1 opacity-0 pointer-events-none transition-all duration-300 ease-out group-hover:translate-y-0 group-hover:opacity-100 group-hover:pointer-events-auto">
|
<div className="absolute right-3 top-3 z-10 flex translate-y-1 gap-1 opacity-0 pointer-events-none transition-all duration-300 ease-out group-hover:translate-y-0 group-hover:opacity-100 group-hover:pointer-events-auto">
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -723,7 +937,6 @@ export function ProgramDetailPage() {
|
||||||
<Trash2 className="h-3.5 w-3.5" />
|
<Trash2 className="h-3.5 w-3.5" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
|
||||||
{/* Logo */}
|
{/* Logo */}
|
||||||
<div className="h-16 flex items-center">
|
<div className="h-16 flex items-center">
|
||||||
{course.thumbnail ? (
|
{course.thumbnail ? (
|
||||||
|
|
@ -743,7 +956,6 @@ export function ProgramDetailPage() {
|
||||||
|
|
||||||
{/* Content */}
|
{/* Content */}
|
||||||
<div className="space-y-4 pt-2 flex-1">
|
<div className="space-y-4 pt-2 flex-1">
|
||||||
{programType === "proficiency" ? (
|
|
||||||
<div className="flex flex-wrap gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
<ContentPublishStatusChip
|
<ContentPublishStatusChip
|
||||||
publishStatus={course.publish_status}
|
publishStatus={course.publish_status}
|
||||||
|
|
@ -762,6 +974,10 @@ export function ProgramDetailPage() {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{isSkillBased && course.programName ? (
|
||||||
|
<p className="text-[12px] font-semibold uppercase tracking-wide text-brand-500">
|
||||||
|
<SearchHighlight text={course.programName} query={listSearch} />
|
||||||
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
<h3 className="text-[18px] font-medium text-grayScale-900">
|
<h3 className="text-[18px] font-medium text-grayScale-900">
|
||||||
<SearchHighlight text={course.name} query={listSearch} />
|
<SearchHighlight text={course.name} query={listSearch} />
|
||||||
|
|
@ -773,12 +989,14 @@ export function ProgramDetailPage() {
|
||||||
|
|
||||||
{/* Badges/Stats */}
|
{/* Badges/Stats */}
|
||||||
<div className="flex items-center pt-4 gap-4">
|
<div className="flex items-center pt-4 gap-4">
|
||||||
|
{isProficiency ? (
|
||||||
<div className="h-10 px-4 rounded-[6px] bg-grayScale-100 border border-grayScale-100 flex items-center gap-2 text-grayScale-700">
|
<div className="h-10 px-4 rounded-[6px] bg-grayScale-100 border border-grayScale-100 flex items-center gap-2 text-grayScale-700">
|
||||||
<ClipboardList className="h-3 w-3 text-grayScale-400" />
|
<ClipboardList className="h-3 w-3 text-grayScale-400" />
|
||||||
<span className="text-[12px] ">
|
<span className="text-[12px] ">
|
||||||
{Number(course.units_count ?? 0)} Units
|
{Number(course.units_count ?? 0)} Units
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
<div className="h-10 px-4 rounded-[6px] bg-grayScale-100 border border-grayScale-100 flex items-center gap-2 text-grayScale-700">
|
<div className="h-10 px-4 rounded-[6px] bg-grayScale-100 border border-grayScale-100 flex items-center gap-2 text-grayScale-700">
|
||||||
<ListChecks className="h-3 w-3 text-grayScale-400" />
|
<ListChecks className="h-3 w-3 text-grayScale-400" />
|
||||||
<span className="text-[12px] ">
|
<span className="text-[12px] ">
|
||||||
|
|
@ -796,9 +1014,15 @@ export function ProgramDetailPage() {
|
||||||
{/* Action Button */}
|
{/* Action Button */}
|
||||||
<Button
|
<Button
|
||||||
className="w-full mt-4 h-10 bg-brand-500 text-white rounded-[6px] font-bold flex items-center justify-center gap-2 group/btn"
|
className="w-full mt-4 h-10 bg-brand-500 text-white rounded-[6px] font-bold flex items-center justify-center gap-2 group/btn"
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
navigate(`/new-content/courses/${programType}/${course.id}`)
|
if (isSkillBased && course.programId) {
|
||||||
|
navigate(
|
||||||
|
`/new-content/learn-english/${course.programId}/courses/${course.id}`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
navigate(`/new-content/courses/${programType}/${course.id}`);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{course.buttonText}
|
{course.buttonText}
|
||||||
<ChevronRight className="h-5 w-5 transition-transform group-hover/btn:translate-x-1" />
|
<ChevronRight className="h-5 w-5 transition-transform group-hover/btn:translate-x-1" />
|
||||||
|
|
@ -834,6 +1058,21 @@ export function ProgramDetailPage() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{isSkillBased ? (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<label className="text-[15px] text-grayScale-800">
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<Textarea
|
||||||
|
value={editDescription}
|
||||||
|
onChange={(e) => setEditDescription(e.target.value)}
|
||||||
|
rows={3}
|
||||||
|
className="min-h-[88px] resize-y rounded-[8px] border-grayScale-400 px-4 text-[15px]"
|
||||||
|
disabled={savingEdit || uploadingEditThumbnail}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<label className="text-[15px] text-grayScale-800">Sort Order</label>
|
<label className="text-[15px] text-grayScale-800">Sort Order</label>
|
||||||
<Input
|
<Input
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user