Integrate chapter learning management and public course discovery
This commit is contained in:
parent
3106c85e50
commit
b9d221024e
|
|
@ -6,6 +6,7 @@
|
|||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"test:learning": "node --test scripts/learning-integration.test.mjs",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
|
|
|
|||
109
scripts/learning-integration.test.mjs
Normal file
109
scripts/learning-integration.test.mjs
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
import assert from "node:assert/strict"
|
||||
import { test } from "node:test"
|
||||
import { build } from "esbuild"
|
||||
|
||||
async function loadModule(path, http = {}) {
|
||||
const key = `learningTest${Math.random().toString(36).slice(2)}`
|
||||
globalThis[key] = http
|
||||
const result = await build({
|
||||
entryPoints: [path], bundle: true, write: false, platform: "node", format: "esm",
|
||||
define: { "import.meta.env": "{}" },
|
||||
plugins: [{ name: "http-fixture", setup(builder) {
|
||||
builder.onResolve({ filter: /(^|\/)http$/ }, () => ({ path: "http", namespace: "fixture" }))
|
||||
builder.onLoad({ filter: /.*/, namespace: "fixture" }, () => ({ contents: `export default globalThis[${JSON.stringify(key)}]` }))
|
||||
} }],
|
||||
})
|
||||
const module = await import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString("base64")}`)
|
||||
return module
|
||||
}
|
||||
|
||||
test("chapter lesson pagination uses the public collection key", async () => {
|
||||
const calls = []
|
||||
const api = await loadModule("src/api/learningHierarchy.api.ts", { get: async (path, options) => {
|
||||
calls.push([path, options.params])
|
||||
const offset = options.params.offset
|
||||
return { data: { data: { lessons: Array.from({ length: offset === 0 ? 200 : 1 }, (_, i) => ({ id: offset + i + 1 })), total_count: 201 } } }
|
||||
} })
|
||||
assert.equal((await api.listLearningItems("/chapters/7/lessons", "lessons")).length, 201)
|
||||
assert.deepEqual(calls.map((call) => call[1].offset), [0, 200])
|
||||
assert.ok(calls.every((call) => call[0] === "/chapters/7/lessons"))
|
||||
})
|
||||
|
||||
test("quiz publication updates both statuses without replacing questions", async () => {
|
||||
const calls = []
|
||||
const api = await loadModule("src/api/learningHierarchy.api.ts", { put: async (...args) => calls.push(args) })
|
||||
await api.updateChapterQuiz(9, { publish_status: "PUBLISHED" })
|
||||
assert.deepEqual(calls, [["/quizzes/9/full", { practice: { publish_status: "PUBLISHED" }, question_set: { status: "PUBLISHED" } }]])
|
||||
})
|
||||
|
||||
test("quiz creation uses a QUIZ set and cleans it up if chapter linking fails", async () => {
|
||||
const calls = []
|
||||
const failure = new Error("chapter unavailable")
|
||||
const api = await loadModule("src/api/learningHierarchy.api.ts", {
|
||||
post: async (path, body) => {
|
||||
calls.push([path, body])
|
||||
if (path === "/question-sets") return { data: { data: { id: 12 } } }
|
||||
throw failure
|
||||
},
|
||||
delete: async (path) => calls.push([path]),
|
||||
})
|
||||
await assert.rejects(api.createChapterQuiz(7, "Review"), failure)
|
||||
assert.deepEqual(calls, [
|
||||
["/question-sets", { title: "Review", set_type: "QUIZ", status: "DRAFT" }],
|
||||
["/chapters/7/quizzes", { title: "Review", question_set_id: 12, publish_status: "DRAFT" }],
|
||||
["/question-sets/12"],
|
||||
])
|
||||
})
|
||||
|
||||
test("public CHAPTER parents survive practice normalization", async () => {
|
||||
const parents = await loadModule("src/lib/practiceParents.ts")
|
||||
assert.deepEqual(parents.normalizePracticeParents({ parents: [{ parent_kind: "CHAPTER", parent_id: 7 }] }), [{ parent_kind: "CHAPTER", parent_id: 7 }])
|
||||
assert.equal(parents.formatPracticeParentLabel({ parent_kind: "CHAPTER", parent_id: 7 }), "Chapter #7")
|
||||
})
|
||||
|
||||
test("admin quiz questions consume the data array from the question-set API", async () => {
|
||||
const rows = [{ id: 31, question_text: "Review question" }]
|
||||
const api = await loadModule("src/api/learningHierarchy.api.ts", { get: async (path) => {
|
||||
assert.equal(path, "/question-sets/12/questions")
|
||||
return { data: { data: rows } }
|
||||
} })
|
||||
assert.deepEqual(await api.getQuizQuestions(12), rows)
|
||||
})
|
||||
|
||||
test("user learning activity preserves the course chapter lesson tree", async () => {
|
||||
const users = await loadModule("src/api/users.api.ts")
|
||||
const activity = users.normalizeUserLearningActivity({ user_id: 42, learning: {
|
||||
progress: { courses: [{ id: 3, name: "Course", chapters: [{ id: 7, course_id: 3, name: "Chapter", lessons: [{ id: 11, chapter_id: 7, title: "Lesson" }] }] }] },
|
||||
completions: { user_id: 42, courses: [{ id: 3 }] },
|
||||
} })
|
||||
const chapter = activity.learning.progress.courses[0].chapters[0]
|
||||
assert.equal(chapter.course_id, 3)
|
||||
assert.equal(chapter.lessons[0].chapter_id, 7)
|
||||
assert.equal(chapter.lessons[0].title, "Lesson")
|
||||
assert.equal(activity.learning.completions.courses.length, 1)
|
||||
assert.equal("modules" in chapter, false)
|
||||
})
|
||||
|
||||
|
||||
test("public catalog base strips the admin suffix", async () => {
|
||||
const { publicApiBase } = await loadModule("src/lib/publicApiBase.ts")
|
||||
assert.equal(publicApiBase("https://api.example.test/api/v1/admin/"), "https://api.example.test/api/v1")
|
||||
assert.equal(publicApiBase("/api/v1"), "/api/v1")
|
||||
})
|
||||
|
||||
test("catalog browsing does not send a staff token or cookies", async () => {
|
||||
const original = globalThis.fetch
|
||||
const calls = []
|
||||
globalThis.fetch = async (url, options) => {
|
||||
calls.push([url, options])
|
||||
return { ok: true, json: async () => ({ data: { courses: [], total_count: 0 } }) }
|
||||
}
|
||||
try {
|
||||
const api = await loadModule("src/api/publicCatalog.api.ts")
|
||||
await api.getPublicCourses("hello world", 12)
|
||||
await api.getPublicCourse(3)
|
||||
assert.equal(calls[0][0], "/api/v1/catalog/courses?q=hello+world&limit=12&offset=12")
|
||||
assert.equal(calls[1][0], "/api/v1/catalog/courses/3")
|
||||
assert.ok(calls.every(([,options]) => options.credentials === "omit" && options.headers === undefined))
|
||||
} finally { globalThis.fetch = original }
|
||||
})
|
||||
|
|
@ -512,160 +512,160 @@ export const reorderModuleLessons = (
|
|||
data: ReorderOrderedIdsRequest,
|
||||
) => http.put(`/modules/${moduleId}/lessons/reorder`, data)
|
||||
|
||||
/** PUT /exam-prep/catalog-courses/reorder */
|
||||
/** PUT /courses/reorder */
|
||||
export const reorderExamPrepCatalogCourses = (data: ReorderOrderedIdsRequest) =>
|
||||
http.put("/exam-prep/catalog-courses/reorder", data)
|
||||
http.put("/courses/reorder", data)
|
||||
|
||||
/** PUT /exam-prep/catalog-courses/:catalogCourseId/units/reorder */
|
||||
/** PUT /courses/:catalogCourseId/chapters/reorder */
|
||||
export const reorderExamPrepUnitsInCatalogCourse = (
|
||||
catalogCourseId: number,
|
||||
data: ReorderOrderedIdsRequest,
|
||||
) =>
|
||||
http.put(
|
||||
`/exam-prep/catalog-courses/${catalogCourseId}/units/reorder`,
|
||||
`/courses/${catalogCourseId}/chapters/reorder`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** PUT /exam-prep/units/:unitId/modules/reorder */
|
||||
/** PUT /chapters/:unitId/modules/reorder */
|
||||
export const reorderExamPrepModulesInUnit = (
|
||||
unitId: number,
|
||||
data: ReorderOrderedIdsRequest,
|
||||
) => http.put(`/exam-prep/units/${unitId}/modules/reorder`, data)
|
||||
) => http.put(`/chapters/${unitId}/modules/reorder`, data)
|
||||
|
||||
/** PUT /exam-prep/modules/:moduleId/lessons/reorder */
|
||||
/** PUT /modules/:moduleId/lessons/reorder */
|
||||
export const reorderExamPrepLessonsInModule = (
|
||||
moduleId: number,
|
||||
data: ReorderOrderedIdsRequest,
|
||||
) => http.put(`/exam-prep/modules/${moduleId}/lessons/reorder`, data)
|
||||
) => http.put(`/modules/${moduleId}/lessons/reorder`, data)
|
||||
|
||||
export const createProgramCourse = (
|
||||
programId: number,
|
||||
data: CreateProgramCourseRequest,
|
||||
) => http.post<CreateProgramCourseResponse>(`/programs/${programId}/courses`, data)
|
||||
|
||||
/** English proficiency catalog course — POST /exam-prep/catalog-courses */
|
||||
/** English proficiency catalog course — POST /courses */
|
||||
export const createExamPrepCatalogCourse = (
|
||||
data: CreateExamPrepCatalogCourseRequest,
|
||||
) => http.post<CreateExamPrepCatalogCourseResponse>("/exam-prep/catalog-courses", data)
|
||||
) => http.post<CreateExamPrepCatalogCourseResponse>("/courses", data)
|
||||
|
||||
/** English proficiency catalog courses — GET /exam-prep/catalog-courses */
|
||||
/** English proficiency catalog courses — GET /courses */
|
||||
export const getExamPrepCatalogCourses = (params?: { limit?: number; offset?: number }) =>
|
||||
http.get<GetExamPrepCatalogCoursesResponse>("/exam-prep/catalog-courses", { params })
|
||||
http.get<GetExamPrepCatalogCoursesResponse>("/courses", { params })
|
||||
|
||||
/** English proficiency catalog course — PUT /exam-prep/catalog-courses/:catalogCourseId */
|
||||
/** English proficiency catalog course — PUT /courses/:catalogCourseId */
|
||||
export const updateExamPrepCatalogCourse = (
|
||||
catalogCourseId: number,
|
||||
data: UpdateExamPrepCatalogCourseRequest,
|
||||
) =>
|
||||
http.put<UpdateExamPrepCatalogCourseResponse>(
|
||||
`/exam-prep/catalog-courses/${catalogCourseId}`,
|
||||
`/courses/${catalogCourseId}`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** English proficiency catalog course — DELETE /exam-prep/catalog-courses/:catalogCourseId */
|
||||
/** English proficiency catalog course — DELETE /courses/:catalogCourseId */
|
||||
export const deleteExamPrepCatalogCourse = (catalogCourseId: number) =>
|
||||
http.delete(`/exam-prep/catalog-courses/${catalogCourseId}`)
|
||||
http.delete(`/courses/${catalogCourseId}`)
|
||||
|
||||
/** English proficiency catalog unit — POST /exam-prep/catalog-courses/:catalogCourseId/units */
|
||||
/** English proficiency catalog unit — POST /courses/:catalogCourseId/chapters */
|
||||
export const createExamPrepCatalogUnit = (
|
||||
catalogCourseId: number,
|
||||
data: CreateExamPrepCatalogUnitRequest,
|
||||
) =>
|
||||
http.post<CreateExamPrepCatalogUnitResponse>(
|
||||
`/exam-prep/catalog-courses/${catalogCourseId}/units`,
|
||||
`/courses/${catalogCourseId}/chapters`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** English proficiency catalog units — GET /exam-prep/catalog-courses/:catalogCourseId/units */
|
||||
/** English proficiency catalog units — GET /courses/:catalogCourseId/chapters */
|
||||
export const getExamPrepCatalogUnits = (
|
||||
catalogCourseId: number,
|
||||
params?: { limit?: number; offset?: number },
|
||||
) =>
|
||||
http.get<GetExamPrepCatalogUnitsResponse>(
|
||||
`/exam-prep/catalog-courses/${catalogCourseId}/units`,
|
||||
`/courses/${catalogCourseId}/chapters`,
|
||||
{ params },
|
||||
)
|
||||
|
||||
/** English proficiency unit — PUT /exam-prep/units/:unitId */
|
||||
/** English proficiency unit — PUT /chapters/:unitId */
|
||||
export const updateExamPrepCatalogUnit = (
|
||||
unitId: number,
|
||||
data: UpdateExamPrepCatalogUnitRequest,
|
||||
) => http.put<UpdateExamPrepCatalogUnitResponse>(`/exam-prep/units/${unitId}`, data)
|
||||
) => http.put<UpdateExamPrepCatalogUnitResponse>(`/chapters/${unitId}`, data)
|
||||
|
||||
/** English proficiency unit — DELETE /exam-prep/units/:unitId */
|
||||
/** English proficiency unit — DELETE /chapters/:unitId */
|
||||
export const deleteExamPrepCatalogUnit = (unitId: number) =>
|
||||
http.delete(`/exam-prep/units/${unitId}`)
|
||||
http.delete(`/chapters/${unitId}`)
|
||||
|
||||
/** English proficiency unit modules — POST /exam-prep/units/:unitId/modules */
|
||||
/** English proficiency unit modules — POST /chapters/:unitId/modules */
|
||||
export const createExamPrepUnitModule = (
|
||||
unitId: number,
|
||||
data: CreateExamPrepUnitModuleRequest,
|
||||
) =>
|
||||
http.post<CreateExamPrepUnitModuleResponse>(
|
||||
`/exam-prep/units/${unitId}/modules`,
|
||||
`/chapters/${unitId}/modules`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** English proficiency unit modules — GET /exam-prep/units/:unitId/modules */
|
||||
/** English proficiency unit modules — GET /chapters/:unitId/modules */
|
||||
export const getExamPrepUnitModules = (
|
||||
unitId: number,
|
||||
params?: { limit?: number; offset?: number },
|
||||
) =>
|
||||
http.get<GetExamPrepUnitModulesResponse>(`/exam-prep/units/${unitId}/modules`, {
|
||||
http.get<GetExamPrepUnitModulesResponse>(`/chapters/${unitId}/modules`, {
|
||||
params,
|
||||
})
|
||||
|
||||
/** English proficiency module — PUT /exam-prep/modules/:moduleId */
|
||||
/** English proficiency module — PUT /modules/:moduleId */
|
||||
export const updateExamPrepUnitModule = (
|
||||
moduleId: number,
|
||||
data: UpdateExamPrepUnitModuleRequest,
|
||||
) =>
|
||||
http.put<UpdateExamPrepUnitModuleResponse>(
|
||||
`/exam-prep/modules/${moduleId}`,
|
||||
`/modules/${moduleId}`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** English proficiency module — DELETE /exam-prep/modules/:moduleId */
|
||||
/** English proficiency module — DELETE /modules/:moduleId */
|
||||
export const deleteExamPrepUnitModule = (moduleId: number) =>
|
||||
http.delete(`/exam-prep/modules/${moduleId}`)
|
||||
http.delete(`/modules/${moduleId}`)
|
||||
|
||||
/** English proficiency module lessons — GET /exam-prep/modules/:moduleId/lessons */
|
||||
/** English proficiency module lessons — GET /modules/:moduleId/lessons */
|
||||
export const getExamPrepModuleLessons = (
|
||||
moduleId: number,
|
||||
params?: { limit?: number; offset?: number },
|
||||
) =>
|
||||
http.get<GetExamPrepModuleLessonsResponse>(
|
||||
`/exam-prep/modules/${moduleId}/lessons`,
|
||||
`/modules/${moduleId}/lessons`,
|
||||
{
|
||||
params,
|
||||
},
|
||||
)
|
||||
|
||||
/** English proficiency module lesson — POST /exam-prep/modules/:moduleId/lessons */
|
||||
/** English proficiency module lesson — POST /modules/:moduleId/lessons */
|
||||
export const createExamPrepModuleLesson = (
|
||||
moduleId: number,
|
||||
data: CreateExamPrepModuleLessonRequest,
|
||||
) =>
|
||||
http.post<CreateExamPrepModuleLessonResponse>(
|
||||
`/exam-prep/modules/${moduleId}/lessons`,
|
||||
`/modules/${moduleId}/lessons`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** English proficiency lesson — PUT /exam-prep/lessons/:lessonId */
|
||||
/** English proficiency lesson — PUT /lessons/:lessonId */
|
||||
export const updateExamPrepModuleLesson = (
|
||||
lessonId: number,
|
||||
data: UpdateExamPrepModuleLessonRequest,
|
||||
) =>
|
||||
http.put<UpdateExamPrepModuleLessonResponse>(
|
||||
`/exam-prep/lessons/${lessonId}`,
|
||||
`/lessons/${lessonId}`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** PUT /exam-prep/lessons/:lessonId — set publish_status only. */
|
||||
/** PUT /lessons/:lessonId — set publish_status only. */
|
||||
export const setExamPrepModuleLessonPublishStatus = (
|
||||
lessonId: number,
|
||||
data: PublishStatusOnlyRequest,
|
||||
) => http.put(`/exam-prep/lessons/${lessonId}`, data)
|
||||
) => http.put(`/lessons/${lessonId}`, data)
|
||||
|
||||
/** @deprecated Use setExamPrepModuleLessonPublishStatus */
|
||||
export const publishExamPrepModuleLesson = (
|
||||
|
|
@ -673,115 +673,115 @@ export const publishExamPrepModuleLesson = (
|
|||
data: PublishExamPrepModuleLessonRequest,
|
||||
) => setExamPrepModuleLessonPublishStatus(lessonId, data)
|
||||
|
||||
/** PUT /exam-prep/lessons/:lessonId — set access_tier only. */
|
||||
/** PUT /lessons/:lessonId — set access_tier only. */
|
||||
export const setExamPrepModuleLessonAccessTier = (
|
||||
lessonId: number,
|
||||
data: AccessTierOnlyRequest,
|
||||
) => http.put(`/exam-prep/lessons/${lessonId}`, data)
|
||||
) => http.put(`/lessons/${lessonId}`, data)
|
||||
|
||||
/** English proficiency lesson — DELETE /exam-prep/lessons/:lessonId */
|
||||
/** English proficiency lesson — DELETE /lessons/:lessonId */
|
||||
export const deleteExamPrepModuleLesson = (lessonId: number) =>
|
||||
http.delete(`/exam-prep/lessons/${lessonId}`)
|
||||
http.delete(`/lessons/${lessonId}`)
|
||||
|
||||
/** POST /exam-prep/catalog-courses/:catalogCourseId/practices */
|
||||
/** POST /courses/:catalogCourseId/practices */
|
||||
export const createExamPrepCatalogCoursePractice = (
|
||||
catalogCourseId: number,
|
||||
data: CreateExamPrepCatalogCoursePracticeRequest,
|
||||
) =>
|
||||
http.post<CreateExamPrepCatalogCoursePracticeResponse>(
|
||||
`/exam-prep/catalog-courses/${catalogCourseId}/practices`,
|
||||
`/courses/${catalogCourseId}/practices`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** GET /exam-prep/catalog-courses/:catalogCourseId/practices */
|
||||
/** GET /courses/:catalogCourseId/practices */
|
||||
export const getExamPrepCatalogCoursePractices = (
|
||||
catalogCourseId: number,
|
||||
params?: { limit?: number; offset?: number },
|
||||
) =>
|
||||
http.get<GetExamPrepCatalogCoursePracticesResponse>(
|
||||
`/exam-prep/catalog-courses/${catalogCourseId}/practices`,
|
||||
`/courses/${catalogCourseId}/practices`,
|
||||
{ params },
|
||||
)
|
||||
|
||||
/** POST /exam-prep/units/:unitId/practices */
|
||||
/** POST /chapters/:unitId/practices */
|
||||
export const createExamPrepUnitPractice = (
|
||||
unitId: number,
|
||||
data: CreateExamPrepUnitPracticeRequest,
|
||||
) =>
|
||||
http.post<CreateExamPrepUnitPracticeResponse>(
|
||||
`/exam-prep/units/${unitId}/practices`,
|
||||
`/chapters/${unitId}/practices`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** GET /exam-prep/units/:unitId/practices */
|
||||
/** GET /chapters/:unitId/practices */
|
||||
export const getExamPrepUnitPractices = (
|
||||
unitId: number,
|
||||
params?: { limit?: number; offset?: number },
|
||||
) =>
|
||||
http.get<GetExamPrepUnitPracticesResponse>(
|
||||
`/exam-prep/units/${unitId}/practices`,
|
||||
`/chapters/${unitId}/practices`,
|
||||
{ params },
|
||||
)
|
||||
|
||||
/** POST /exam-prep/lessons/:lessonId/practices */
|
||||
/** POST /lessons/:lessonId/practices */
|
||||
export const createExamPrepLessonPractice = (
|
||||
lessonId: number,
|
||||
data: CreateExamPrepLessonPracticeRequest,
|
||||
) =>
|
||||
http.post<CreateExamPrepLessonPracticeResponse>(
|
||||
`/exam-prep/lessons/${lessonId}/practices`,
|
||||
`/lessons/${lessonId}/practices`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** GET /exam-prep/lessons/:lessonId/practices */
|
||||
/** GET /lessons/:lessonId/practices */
|
||||
export const getExamPrepLessonPractices = (
|
||||
lessonId: number,
|
||||
params?: { limit?: number; offset?: number },
|
||||
) =>
|
||||
http.get<GetExamPrepLessonPracticesResponse>(
|
||||
`/exam-prep/lessons/${lessonId}/practices`,
|
||||
`/lessons/${lessonId}/practices`,
|
||||
{ params },
|
||||
)
|
||||
|
||||
/** POST /exam-prep/practices — create practice with optional parents. */
|
||||
/** POST /practices — create practice with optional parents. */
|
||||
export const createExamPrepPractice = (data: CreateExamPrepPracticeRequest) =>
|
||||
http.post<CreateExamPrepPracticeResponse>("/exam-prep/practices", data)
|
||||
http.post<CreateExamPrepPracticeResponse>("/practices", data)
|
||||
|
||||
/** GET /exam-prep/practices — list practices (supports unlinked_only). */
|
||||
/** GET /practices — list practices (supports unlinked_only). */
|
||||
export const getExamPrepPractices = (params?: GetPracticesListParams) =>
|
||||
http.get<GetExamPrepPracticesListResponse>("/exam-prep/practices", { params })
|
||||
http.get<GetExamPrepPracticesListResponse>("/practices", { params })
|
||||
|
||||
/** PUT /exam-prep/practices/:id/parents — replace all parent links. */
|
||||
/** PUT /practices/:id/parents — replace all parent links. */
|
||||
export const updateExamPrepPracticeParents = (
|
||||
practiceId: number,
|
||||
data: UpdatePracticeParentsRequest,
|
||||
) =>
|
||||
http.put<UpdatePracticeParentsResponse>(
|
||||
`/exam-prep/practices/${practiceId}/parents`,
|
||||
`/practices/${practiceId}/parents`,
|
||||
data,
|
||||
)
|
||||
|
||||
/** DELETE /exam-prep/practices/:id/parents/:parentKind/:parentId — unlink one parent. */
|
||||
/** DELETE /practices/:id/parents/:parentKind/:parentId — unlink one parent. */
|
||||
export const unlinkExamPrepPracticeParent = (
|
||||
practiceId: number,
|
||||
parent: PracticeParent,
|
||||
) =>
|
||||
http.delete<UpdatePracticeParentsResponse>(
|
||||
`/exam-prep/practices/${practiceId}/parents/${parent.parent_kind.toUpperCase()}/${parent.parent_id}`,
|
||||
`/practices/${practiceId}/parents/${parent.parent_kind.toUpperCase()}/${parent.parent_id}`,
|
||||
{ skipErrorToast: true },
|
||||
)
|
||||
|
||||
/** DELETE /exam-prep/practices/:practiceId */
|
||||
/** DELETE /practices/:practiceId */
|
||||
export const deleteExamPrepPractice = (practiceId: number) =>
|
||||
http.delete<{ message: string; success: boolean; status_code: number; metadata: unknown }>(
|
||||
`/exam-prep/practices/${practiceId}`,
|
||||
`/practices/${practiceId}`,
|
||||
)
|
||||
|
||||
/** PUT /exam-prep/practices/:practiceId — set publish_status only. */
|
||||
/** PUT /practices/:practiceId — set publish_status only. */
|
||||
export const setExamPrepPracticePublishStatus = (
|
||||
practiceId: number,
|
||||
data: PublishStatusOnlyRequest,
|
||||
) => http.put(`/exam-prep/practices/${practiceId}`, data)
|
||||
) => http.put(`/practices/${practiceId}`, data)
|
||||
|
||||
/** PUT /programs/:programId — set publish_status only. */
|
||||
export const setLearningProgramPublishStatus = (
|
||||
|
|
@ -807,41 +807,41 @@ export const setProgramCourseAccessTier = (
|
|||
data: AccessTierOnlyRequest,
|
||||
) => http.put(`/courses/${courseId}`, data)
|
||||
|
||||
/** PUT /exam-prep/catalog-courses/:catalogCourseId — set publish_status only. */
|
||||
/** PUT /courses/:catalogCourseId — set publish_status only. */
|
||||
export const setExamPrepCatalogCoursePublishStatus = (
|
||||
catalogCourseId: number,
|
||||
data: PublishStatusOnlyRequest,
|
||||
) => http.put(`/exam-prep/catalog-courses/${catalogCourseId}`, data)
|
||||
) => http.put(`/courses/${catalogCourseId}`, data)
|
||||
|
||||
/** PUT /exam-prep/catalog-courses/:catalogCourseId — set access_tier only. */
|
||||
/** PUT /courses/:catalogCourseId — set access_tier only. */
|
||||
export const setExamPrepCatalogCourseAccessTier = (
|
||||
catalogCourseId: number,
|
||||
data: AccessTierOnlyRequest,
|
||||
) => http.put(`/exam-prep/catalog-courses/${catalogCourseId}`, data)
|
||||
) => http.put(`/courses/${catalogCourseId}`, data)
|
||||
|
||||
/** PUT /exam-prep/units/:unitId — set publish_status only. */
|
||||
/** PUT /chapters/:unitId — set publish_status only. */
|
||||
export const setExamPrepCatalogUnitPublishStatus = (
|
||||
unitId: number,
|
||||
data: PublishStatusOnlyRequest,
|
||||
) => http.put(`/exam-prep/units/${unitId}`, data)
|
||||
) => http.put(`/chapters/${unitId}`, data)
|
||||
|
||||
/** PUT /exam-prep/units/:unitId — set access_tier only. */
|
||||
/** PUT /chapters/:unitId — set access_tier only. */
|
||||
export const setExamPrepCatalogUnitAccessTier = (
|
||||
unitId: number,
|
||||
data: AccessTierOnlyRequest,
|
||||
) => http.put(`/exam-prep/units/${unitId}`, data)
|
||||
) => http.put(`/chapters/${unitId}`, data)
|
||||
|
||||
/** PUT /exam-prep/modules/:moduleId — set publish_status only. */
|
||||
/** PUT /modules/:moduleId — set publish_status only. */
|
||||
export const setExamPrepUnitModulePublishStatus = (
|
||||
moduleId: number,
|
||||
data: PublishStatusOnlyRequest,
|
||||
) => http.put(`/exam-prep/modules/${moduleId}`, data)
|
||||
) => http.put(`/modules/${moduleId}`, data)
|
||||
|
||||
/** PUT /exam-prep/modules/:moduleId — set access_tier only. */
|
||||
/** PUT /modules/:moduleId — set access_tier only. */
|
||||
export const setExamPrepUnitModuleAccessTier = (
|
||||
moduleId: number,
|
||||
data: AccessTierOnlyRequest,
|
||||
) => http.put(`/exam-prep/modules/${moduleId}`, data)
|
||||
) => http.put(`/modules/${moduleId}`, data)
|
||||
|
||||
/** PUT /modules/:moduleId — set publish_status only (Learn English module). */
|
||||
export const setTopLevelCourseModulePublishStatus = (
|
||||
|
|
@ -992,19 +992,19 @@ export const updateLearnEnglishPracticeFull = (
|
|||
) =>
|
||||
http.put<UpdatePracticeFullResponse>(`/practices/${practiceId}/full`, data)
|
||||
|
||||
/** GET /exam-prep/practices/:id/full */
|
||||
/** GET /practices/:id/full */
|
||||
export const getExamPrepPracticeFull = (practiceId: number) =>
|
||||
http.get<GetPracticeFullResponse>(`/exam-prep/practices/${practiceId}/full`, {
|
||||
http.get<GetPracticeFullResponse>(`/practices/${practiceId}/full`, {
|
||||
skipErrorToast: true,
|
||||
})
|
||||
|
||||
/** PUT /exam-prep/practices/:id/full */
|
||||
/** PUT /practices/:id/full */
|
||||
export const updateExamPrepPracticeFull = (
|
||||
practiceId: number,
|
||||
data: UpdatePracticeFullRequest,
|
||||
) =>
|
||||
http.put<UpdatePracticeFullResponse>(
|
||||
`/exam-prep/practices/${practiceId}/full`,
|
||||
`/practices/${practiceId}/full`,
|
||||
data,
|
||||
)
|
||||
|
||||
|
|
@ -1167,15 +1167,15 @@ export const getQuestionSets = (params?: GetQuestionSetsParams) =>
|
|||
http.get<GetQuestionSetsResponse>("/question-sets", { params })
|
||||
|
||||
export const getExamPrepAssessments = (parent: ExamPrepAssessmentParent) =>
|
||||
http.get<GetQuestionSetsResponse>("/exam-prep/assessments", {
|
||||
http.get<GetQuestionSetsResponse>("/assessments", {
|
||||
params: { parent_kind: parent.kind, parent_id: parent.id },
|
||||
})
|
||||
|
||||
export const linkExamPrepAssessment = (data: ExamPrepAssessmentLinkRequest) =>
|
||||
http.post("/exam-prep/assessments", data)
|
||||
http.post("/assessments", data)
|
||||
|
||||
export const unlinkExamPrepAssessment = (questionSetId: number, parent: ExamPrepAssessmentParent) =>
|
||||
http.delete(`/exam-prep/assessments/${questionSetId}/parents/${parent.kind}/${parent.id}`)
|
||||
http.delete(`/assessments/${questionSetId}/parents/${parent.kind}/${parent.id}`)
|
||||
|
||||
export const getQuestionSetsByOwner = (ownerType: string, ownerId: number) =>
|
||||
http.get<GetQuestionSetsResponse>("/question-sets/by-owner", {
|
||||
|
|
|
|||
69
src/api/learningHierarchy.api.ts
Normal file
69
src/api/learningHierarchy.api.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import http from "./http"
|
||||
import type { QuestionSetQuestion } from "../types/course.types"
|
||||
|
||||
export type LearningKind = "course" | "chapter" | "lesson" | "quiz"
|
||||
export type LearningItem = {
|
||||
id: number
|
||||
course_id?: number
|
||||
chapter_id?: number
|
||||
name?: string
|
||||
title?: string
|
||||
description?: string
|
||||
thumbnail?: string
|
||||
video_url?: string
|
||||
publish_status: "DRAFT" | "PUBLISHED"
|
||||
access_tier?: "FREE" | "PREMIUM"
|
||||
question_set_id?: number
|
||||
}
|
||||
|
||||
export const learningCollections = { course: "courses", chapter: "chapters", lesson: "lessons", quiz: "quizzes" } as const
|
||||
|
||||
type Envelope<T> = { data: T; message: string; success: boolean; status_code: number }
|
||||
type Page = { total_count: number; limit: number; offset: number } & Partial<Record<"courses" | "chapters" | "lessons" | "quizzes", LearningItem[]>>
|
||||
|
||||
export async function listLearningItems(path: string, key: typeof learningCollections[LearningKind]): Promise<LearningItem[]> {
|
||||
const result: LearningItem[] = []
|
||||
for (let offset = 0; ; offset += 200) {
|
||||
const { data } = await http.get<Envelope<Page>>(path, { params: { limit: 200, offset } })
|
||||
const page = data.data?.[key]
|
||||
if (!Array.isArray(page)) throw new Error(`Invalid ${key} response`)
|
||||
result.push(...page)
|
||||
if (page.length < 200 || result.length >= data.data.total_count) return result
|
||||
}
|
||||
}
|
||||
|
||||
export async function getLearningItem(kind: LearningKind, id: number): Promise<LearningItem> {
|
||||
const { data } = await http.get<Envelope<LearningItem>>(`/${learningCollections[kind]}/${id}`)
|
||||
if (!data.data || data.data.id !== id) throw new Error(`Invalid ${kind} response`)
|
||||
return data.data
|
||||
}
|
||||
|
||||
/** Admin question-set reads return a data array, unlike paginated learner quiz reads. */
|
||||
export async function getQuizQuestions(questionSetId: number): Promise<QuestionSetQuestion[]> {
|
||||
const { data } = await http.get<Envelope<QuestionSetQuestion[]>>(`/question-sets/${questionSetId}/questions`)
|
||||
if (!Array.isArray(data.data)) throw new Error("Invalid quiz questions response")
|
||||
return data.data
|
||||
}
|
||||
|
||||
/** Update quiz and question-set publication/title through one request. */
|
||||
export function updateChapterQuiz(id: number, changes: { title?: string; publish_status?: "DRAFT" | "PUBLISHED" }) {
|
||||
return http.put(`/quizzes/${id}/full`, {
|
||||
practice: changes,
|
||||
question_set: {
|
||||
...(changes.title !== undefined ? { title: changes.title } : {}),
|
||||
...(changes.publish_status !== undefined ? { status: changes.publish_status } : {}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export async function createChapterQuiz(chapterId: number, title: string) {
|
||||
const { data } = await http.post<Envelope<{ id: number }>>("/question-sets", { title, set_type: "QUIZ", status: "DRAFT" })
|
||||
const setId = data.data?.id
|
||||
if (!Number.isSafeInteger(setId) || setId <= 0) throw new Error("Invalid question set response")
|
||||
try {
|
||||
return await http.post(`/chapters/${chapterId}/quizzes`, { title, question_set_id: setId, publish_status: "DRAFT" })
|
||||
} catch (error) {
|
||||
await http.delete(`/question-sets/${setId}`, { skipErrorToast: true }).catch(() => undefined)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
38
src/api/publicCatalog.api.ts
Normal file
38
src/api/publicCatalog.api.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { publicApiBase } from "../lib/publicApiBase"
|
||||
|
||||
export type PublicCourse = {
|
||||
id: number; name: string; description: string; thumbnail: string; access_tier: "FREE" | "PREMIUM"
|
||||
chapter_count: number; lesson_count: number; quiz_count: number
|
||||
}
|
||||
export type PublicCourseOutline = PublicCourse & { chapters: {
|
||||
id: number; name: string; description: string
|
||||
lessons: { id: number; title: string; description: string; thumbnail: string; access_tier: "FREE" | "PREMIUM" }[]
|
||||
quizzes: { id: number; title: string; question_count: number }[]
|
||||
}[] }
|
||||
export type PublicCatalogPage = { courses: PublicCourse[]; total_count: number; limit: number; offset: number }
|
||||
|
||||
const base = publicApiBase(import.meta.env.VITE_API_BASE_URL ?? "/api/v1")
|
||||
|
||||
// Use a separate anonymous client: staff tokens, refresh and login redirects do
|
||||
// not belong in public discovery, even when a staff session exists in this tab.
|
||||
async function read<T>(path: string, signal?: AbortSignal): Promise<T> {
|
||||
const response = await fetch(`${base}${path}`, { signal, credentials: "omit" })
|
||||
if (!response.ok) throw new Error(response.status === 404 ? "This course is not available." : "Unable to load the course catalog. Please try again.")
|
||||
const result = await response.json()
|
||||
return result.data as T
|
||||
}
|
||||
|
||||
export function getPublicCourses(search: string, offset: number, signal?: AbortSignal) {
|
||||
const params = new URLSearchParams({ q: search, limit: "12", offset: String(offset) })
|
||||
return read<PublicCatalogPage>(`/catalog/courses?${params}`, signal)
|
||||
}
|
||||
export function getPublicCourse(id: number, signal?: AbortSignal) {
|
||||
return read<PublicCourseOutline>(`/catalog/courses/${id}`, signal)
|
||||
}
|
||||
|
||||
export function catalogThumbnail(value: string): string {
|
||||
if (!value.startsWith("/static/")) return value
|
||||
// Static uploads live on the API origin when the UI and API use different hosts.
|
||||
if (/^https?:\/\//.test(base)) return `${new URL(base).origin}${value}`
|
||||
return value
|
||||
}
|
||||
|
|
@ -16,8 +16,7 @@ import type {
|
|||
LearningActivityAccess,
|
||||
LearningActivityCourse,
|
||||
LearningActivityLesson,
|
||||
LearningActivityModule,
|
||||
LearningActivityUnit,
|
||||
LearningActivityChapter,
|
||||
UserLearningActivityData,
|
||||
UserLearningActivityResponse,
|
||||
UserSubscriptionPayment,
|
||||
|
|
@ -127,119 +126,46 @@ function normalizeLearningActivityAccess(raw: unknown): LearningActivityAccess {
|
|||
function normalizeLearningActivityLesson(raw: unknown): LearningActivityLesson | null {
|
||||
if (!isRecord(raw)) return null;
|
||||
const id = Number(raw.id);
|
||||
const moduleId = Number(raw.module_id);
|
||||
if (!Number.isFinite(id) || !Number.isFinite(moduleId)) return null;
|
||||
|
||||
return {
|
||||
id,
|
||||
module_id: moduleId,
|
||||
title: String(raw.title ?? ""),
|
||||
access: normalizeLearningActivityAccess(raw.access),
|
||||
};
|
||||
const chapterId = Number(raw.chapter_id);
|
||||
if (!Number.isSafeInteger(id) || id <= 0 || !Number.isSafeInteger(chapterId) || chapterId <= 0) return null;
|
||||
return { id, chapter_id: chapterId, title: String(raw.title ?? ""), access: normalizeLearningActivityAccess(raw.access) };
|
||||
}
|
||||
|
||||
function normalizeLearningActivityModule(raw: unknown): LearningActivityModule | null {
|
||||
function normalizeLearningActivityChapter(raw: unknown): LearningActivityChapter | null {
|
||||
if (!isRecord(raw)) return null;
|
||||
const id = Number(raw.id);
|
||||
if (!Number.isFinite(id)) return null;
|
||||
|
||||
const lessonsRaw = raw.lessons;
|
||||
const lessons = Array.isArray(lessonsRaw)
|
||||
? lessonsRaw
|
||||
.map((entry) => normalizeLearningActivityLesson(entry))
|
||||
.filter((entry): entry is LearningActivityLesson => entry !== null)
|
||||
const courseId = Number(raw.course_id);
|
||||
if (!Number.isSafeInteger(id) || id <= 0 || !Number.isSafeInteger(courseId) || courseId <= 0) return null;
|
||||
const lessons = Array.isArray(raw.lessons)
|
||||
? raw.lessons.map(normalizeLearningActivityLesson).filter((entry): entry is LearningActivityLesson => entry !== null)
|
||||
: [];
|
||||
|
||||
const unitId = Number(raw.unit_id);
|
||||
|
||||
return {
|
||||
id,
|
||||
unit_id: Number.isFinite(unitId) ? unitId : undefined,
|
||||
name: String(raw.name ?? ""),
|
||||
access: normalizeLearningActivityAccess(raw.access),
|
||||
lessons,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeLearningActivityUnit(raw: unknown): LearningActivityUnit | null {
|
||||
if (!isRecord(raw)) return null;
|
||||
const id = Number(raw.id);
|
||||
const catalogCourseId = Number(raw.catalog_course_id);
|
||||
if (!Number.isFinite(id) || !Number.isFinite(catalogCourseId)) return null;
|
||||
|
||||
const modulesRaw = raw.modules;
|
||||
const modules = Array.isArray(modulesRaw)
|
||||
? modulesRaw
|
||||
.map((entry) => normalizeLearningActivityModule(entry))
|
||||
.filter((entry): entry is LearningActivityModule => entry !== null)
|
||||
: [];
|
||||
|
||||
return {
|
||||
id,
|
||||
catalog_course_id: catalogCourseId,
|
||||
name: String(raw.name ?? ""),
|
||||
access: normalizeLearningActivityAccess(raw.access),
|
||||
modules,
|
||||
};
|
||||
return { id, course_id: courseId, name: String(raw.name ?? ""), access: normalizeLearningActivityAccess(raw.access), lessons };
|
||||
}
|
||||
|
||||
function normalizeLearningActivityCourse(raw: unknown): LearningActivityCourse | null {
|
||||
if (!isRecord(raw)) return null;
|
||||
const id = Number(raw.id);
|
||||
if (!Number.isFinite(id)) return null;
|
||||
|
||||
const modulesRaw = raw.modules;
|
||||
const modules = Array.isArray(modulesRaw)
|
||||
? modulesRaw
|
||||
.map((entry) => normalizeLearningActivityModule(entry))
|
||||
.filter((entry): entry is LearningActivityModule => entry !== null)
|
||||
: undefined;
|
||||
|
||||
const unitsRaw = raw.units;
|
||||
const units = Array.isArray(unitsRaw)
|
||||
? unitsRaw
|
||||
.map((entry) => normalizeLearningActivityUnit(entry))
|
||||
.filter((entry): entry is LearningActivityUnit => entry !== null)
|
||||
: undefined;
|
||||
|
||||
const catalogCourseId = Number(raw.catalog_course_id);
|
||||
|
||||
return {
|
||||
id,
|
||||
catalog_course_id: Number.isFinite(catalogCourseId) ? catalogCourseId : undefined,
|
||||
name: String(raw.name ?? ""),
|
||||
access: normalizeLearningActivityAccess(raw.access),
|
||||
modules,
|
||||
units,
|
||||
};
|
||||
if (!Number.isSafeInteger(id) || id <= 0) return null;
|
||||
const chapters = Array.isArray(raw.chapters)
|
||||
? raw.chapters.map(normalizeLearningActivityChapter).filter((entry): entry is LearningActivityChapter => entry !== null)
|
||||
: [];
|
||||
return { id, name: String(raw.name ?? ""), access: normalizeLearningActivityAccess(raw.access), chapters };
|
||||
}
|
||||
|
||||
export function normalizeUserLearningActivity(raw: unknown): UserLearningActivityData | null {
|
||||
if (!isRecord(raw)) return null;
|
||||
const userId = Number(raw.user_id);
|
||||
if (!Number.isFinite(userId)) return null;
|
||||
|
||||
const examPrepRaw = isRecord(raw.exam_prep) ? raw.exam_prep : {};
|
||||
const examProgressRaw = isRecord(examPrepRaw.progress) ? examPrepRaw.progress : {};
|
||||
const catalogCoursesRaw = examProgressRaw.catalog_courses;
|
||||
const catalogCourses = Array.isArray(catalogCoursesRaw)
|
||||
? catalogCoursesRaw
|
||||
.map((entry) => normalizeLearningActivityCourse(entry))
|
||||
.filter((entry): entry is LearningActivityCourse => entry !== null)
|
||||
if (!Number.isSafeInteger(userId) || userId <= 0 || !isRecord(raw.learning)) return null;
|
||||
const progress = isRecord(raw.learning.progress) ? raw.learning.progress : {};
|
||||
const completions = isRecord(raw.learning.completions) ? raw.learning.completions : {};
|
||||
const courses = Array.isArray(progress.courses)
|
||||
? progress.courses.map(normalizeLearningActivityCourse).filter((entry): entry is LearningActivityCourse => entry !== null)
|
||||
: [];
|
||||
|
||||
const examCompletionsRaw = isRecord(examPrepRaw.completions) ? examPrepRaw.completions : {};
|
||||
|
||||
return {
|
||||
user_id: userId,
|
||||
exam_prep: {
|
||||
progress: { catalog_courses: catalogCourses },
|
||||
completions: {
|
||||
user_id: Number(examCompletionsRaw.user_id) || userId,
|
||||
catalog_courses: Array.isArray(examCompletionsRaw.catalog_courses)
|
||||
? examCompletionsRaw.catalog_courses
|
||||
: [],
|
||||
},
|
||||
learning: {
|
||||
progress: { courses },
|
||||
completions: { user_id: Number(completions.user_id) || userId, courses: Array.isArray(completions.courses) ? completions.courses : [] },
|
||||
},
|
||||
recent_activity: normalizeUserRecentActivity(raw.recent_activity) ?? undefined,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import { PublicCatalogPage } from "../pages/catalog/PublicCatalogPage";
|
||||
import { getAccessToken } from "../lib/teamAuthStorage";
|
||||
import { Navigate, Route, Routes } from "react-router-dom";
|
||||
import { LearningHierarchyPage } from "../pages/content-management/LearningHierarchyPage";
|
||||
import { getDefaultAppHome } from "../lib/adminAccess";
|
||||
import { getNormalizedSessionTeamRole } from "../lib/teamRole";
|
||||
import { FullPanelGuard } from "../components/access/AdminAccessGates";
|
||||
|
|
@ -6,29 +9,9 @@ import { AppLayout } from "../layouts/AppLayout";
|
|||
import { DashboardPage } from "../pages/DashboardPage";
|
||||
import { AnalyticsPage } from "../pages/analytics/AnalyticsPage";
|
||||
import { ContentManagementLayout } from "../pages/content-management/ContentManagementLayout";
|
||||
import { AllCoursesPage } from "../pages/content-management/AllCoursesPage";
|
||||
import { CourseFlowBuilderPage } from "../pages/content-management/CourseFlowBuilderPage";
|
||||
import { ContentOverviewPage } from "../pages/content-management/ContentOverviewPage";
|
||||
import { CoursesPage } from "../pages/content-management/CoursesPage";
|
||||
import { PracticeQuestionsPage } from "../pages/content-management/PracticeQuestionsPage";
|
||||
import { AddNewPracticePage } from "../pages/content-management/AddNewPracticePage";
|
||||
import { SubModulesPage } from "../pages/content-management/SubCoursesPage";
|
||||
import { SubModuleContentPage } from "../pages/content-management/SubCourseContentPage";
|
||||
import { SpeakingPage } from "../pages/content-management/SpeakingPage";
|
||||
import { AddVideoPage } from "../pages/content-management/AddVideoPage";
|
||||
import { AddPracticePage } from "../pages/content-management/AddPracticePage";
|
||||
import { NewContentPage } from "../pages/content-management/NewContentPage";
|
||||
import { ReorderContentPage } from "../pages/content-management/ReorderContentPage";
|
||||
import { LessonPracticesPage } from "../pages/content-management/LessonPracticesPage";
|
||||
import { LessonAssessmentsPage } from "../pages/content-management/LessonAssessmentsPage";
|
||||
import { AddPracticeFlow } from "../pages/content-management/AddPracticeFlow";
|
||||
import { LinkExistingPracticeFlow } from "../pages/content-management/LinkExistingPracticeFlow";
|
||||
import { EditPracticeFlow } from "../pages/content-management/EditPracticeFlow";
|
||||
import { CourseModuleDetailPage } from "../pages/content-management/CourseModuleDetailPage";
|
||||
import { ProgramTypeSelectionPage } from "../pages/content-management/ProgramTypeSelectionPage";
|
||||
import { ProgramDetailPage } from "../pages/content-management/ProgramDetailPage";
|
||||
import { CourseManagementPage } from "../pages/content-management/CourseManagementPage";
|
||||
import { UnitManagementPage } from "../pages/content-management/UnitManagementPage";
|
||||
import { QuestionTypeLibraryPage } from "../pages/content-management/QuestionTypeLibraryPage";
|
||||
import { CreateQuestionTypeFlow } from "../pages/content-management/CreateQuestionTypeFlow";
|
||||
import { NotFoundPage } from "../pages/NotFoundPage";
|
||||
|
|
@ -44,12 +27,8 @@ import { UserManagementLayout } from "../pages/user-management/UserManagementLay
|
|||
import { UsersListPage } from "../pages/user-management/UsersListPage";
|
||||
import { UserGroupsPage } from "../pages/user-management/UserGroupsPage";
|
||||
import { DeletionRequestsPage } from "../pages/user-management/DeletionRequestsPage";
|
||||
import { PracticeDetailsPage } from "../pages/content-management/PracticeDetailsPage";
|
||||
import { PracticeMembersPage } from "../pages/content-management/PracticeMembersPage";
|
||||
import { QuestionsPage } from "../pages/content-management/QuestionsPage";
|
||||
import { AddQuestionPage } from "../pages/content-management/AddQuestionPage";
|
||||
import { HumanLanguageHierarchyPage } from "../pages/content-management/HumanLanguageHierarchyPage";
|
||||
import { HumanLanguageSubModulePage } from "../pages/content-management/HumanLanguageSubModulePage";
|
||||
import { UserLogPage } from "../pages/user-log/UserLogPage";
|
||||
import { PaymentsPage } from "../pages/payments/PaymentsPage";
|
||||
import { SubscriptionsExportPage } from "../pages/subscriptions/SubscriptionsExportPage";
|
||||
|
|
@ -73,6 +52,9 @@ import { PersonasPage } from "../pages/personas/PersonasPage";
|
|||
export function AppRoutes() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/" element={getAccessToken() ? <Navigate to={getDefaultAppHome(getNormalizedSessionTeamRole())} replace /> : <PublicCatalogPage />} />
|
||||
<Route path="/catalog" element={<PublicCatalogPage />} />
|
||||
<Route path="/catalog/courses/:courseId" element={<PublicCatalogPage />} />
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/forgot-password" element={<ForgotPasswordPage />} />
|
||||
<Route path="/reset-password" element={<ResetPasswordPage />} />
|
||||
|
|
@ -83,7 +65,6 @@ export function AppRoutes() {
|
|||
<Route path="/privacy" element={<PrivacyPage />} />
|
||||
<Route path="/account-deletion" element={<AccountDeletionPage />} />
|
||||
<Route element={<AppLayout />}>
|
||||
<Route path="/" element={<Navigate to={getDefaultAppHome(getNormalizedSessionTeamRole())} replace />} />
|
||||
|
||||
<Route element={<FullPanelGuard />}>
|
||||
<Route path="/dashboard" element={<DashboardPage />} />
|
||||
|
|
@ -100,188 +81,24 @@ export function AppRoutes() {
|
|||
</Route>
|
||||
|
||||
<Route path="/content" element={<ContentManagementLayout />}>
|
||||
<Route index element={<Navigate to="practices" replace />} />
|
||||
<Route path="courses" element={<AllCoursesPage />} />
|
||||
<Route path="flows" element={<CourseFlowBuilderPage />} />
|
||||
<Route path="human-language" element={<HumanLanguageHierarchyPage />} />
|
||||
<Route
|
||||
path="human-language/:categoryId/:courseId/sub-module/:subModuleId/add-practice"
|
||||
element={<AddNewPracticePage />}
|
||||
/>
|
||||
<Route
|
||||
path="human-language/:categoryId/:courseId/sub-module/:subModuleId/practices/:practiceId/questions"
|
||||
element={<PracticeQuestionsPage />}
|
||||
/>
|
||||
<Route
|
||||
path="human-language/:categoryId/:courseId/sub-module/:subModuleId"
|
||||
element={<HumanLanguageSubModulePage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId"
|
||||
element={<ContentOverviewPage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses"
|
||||
element={<CoursesPage />}
|
||||
/>
|
||||
{/* Course → Sub-module → Lesson/Practice */}
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-modules"
|
||||
element={<SubModulesPage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-modules/:subModuleId"
|
||||
element={<SubModuleContentPage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-modules/:subModuleId/add-practice"
|
||||
element={<AddNewPracticePage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-modules/:subModuleId/practices/:practiceId/questions"
|
||||
element={<PracticeQuestionsPage />}
|
||||
/>
|
||||
{/* Legacy aliases */}
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-courses"
|
||||
element={<SubModulesPage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-courses/:subModuleId"
|
||||
element={<SubModuleContentPage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-courses/:subModuleId/add-practice"
|
||||
element={<AddNewPracticePage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses/:courseId/sub-courses/:subModuleId/practices/:practiceId/questions"
|
||||
element={<PracticeQuestionsPage />}
|
||||
/>
|
||||
<Route
|
||||
path="category/:categoryId/courses/add-video"
|
||||
element={<AddVideoPage />}
|
||||
/>
|
||||
<Route path="speaking" element={<SpeakingPage />} />
|
||||
<Route path="speaking/add-practice" element={<AddPracticePage />} />
|
||||
<Route path="practices" element={<PracticeDetailsPage />} />
|
||||
<Route path="practices/members" element={<PracticeMembersPage />} />
|
||||
<Route index element={<Navigate to="/new-content/courses" replace />} />
|
||||
<Route path="courses" element={<Navigate to="/new-content/courses" replace />} />
|
||||
<Route path="questions" element={<QuestionsPage />} />
|
||||
<Route path="question-sets/:practiceId/questions" element={<PracticeQuestionsPage />} />
|
||||
<Route path="questions/add" element={<AddQuestionPage />} />
|
||||
<Route path="questions/edit/:id" element={<AddQuestionPage />} />
|
||||
<Route path="question-sets/:practiceId/questions" element={<PracticeQuestionsPage />} />
|
||||
<Route path="*" element={<Navigate to="/new-content/courses" replace />} />
|
||||
</Route>
|
||||
|
||||
<Route path="/new-content" element={<NewContentPage />} />
|
||||
<Route path="/new-content/reorder" element={<ReorderContentPage />} />
|
||||
<Route
|
||||
path="/new-content/courses"
|
||||
element={<ProgramTypeSelectionPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/proficiency"
|
||||
element={<Navigate to="/new-content/courses/ielts" replace />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/skill-based"
|
||||
element={<Navigate to="/new-content/courses/education" replace />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/question-types"
|
||||
element={<QuestionTypeLibraryPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/initial-assessment"
|
||||
element={<Navigate to="/new-content/courses/education" replace />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/question-types/:definitionId/create-practice"
|
||||
element={<AddPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/practices/:practiceId/edit"
|
||||
element={<EditPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/question-types/:definitionId/edit"
|
||||
element={<CreateQuestionTypeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/question-types/create"
|
||||
element={<CreateQuestionTypeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType"
|
||||
element={<ProgramDetailPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/add-practice"
|
||||
element={<AddPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/attach-practice"
|
||||
element={<LinkExistingPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/add-practice"
|
||||
element={<AddPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/attach-practice"
|
||||
element={<LinkExistingPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/add-practice"
|
||||
element={<AddPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/attach-practice"
|
||||
element={<LinkExistingPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/:moduleId/add-practice"
|
||||
element={<AddPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/:moduleId/attach-practice"
|
||||
element={<LinkExistingPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId"
|
||||
element={<CourseManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId"
|
||||
element={<UnitManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/:moduleId"
|
||||
element={<CourseModuleDetailPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/edit-practice/:practiceId"
|
||||
element={<EditPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/edit-practice/:practiceId"
|
||||
element={<EditPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/:moduleId/lessons/:lessonId/practices"
|
||||
element={<LessonPracticesPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/:moduleId/lessons/:lessonId/assessments"
|
||||
element={<LessonAssessmentsPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/courses/:programType/:courseId/:unitId/:moduleId/lessons/:lessonId/edit-practice/:practiceId"
|
||||
element={<EditPracticeFlow />}
|
||||
/>
|
||||
<Route
|
||||
path="/new-content/learn-english/*"
|
||||
element={<Navigate to="/new-content/courses/education" replace />}
|
||||
/>
|
||||
<Route path="/new-content" element={<Navigate to="/new-content/courses" replace />} />
|
||||
<Route path="/new-content/courses" element={<LearningHierarchyPage />} />
|
||||
<Route path="/new-content/courses/:courseId" element={<LearningHierarchyPage />} />
|
||||
<Route path="/new-content/courses/:courseId/chapters/:chapterId" element={<LearningHierarchyPage />} />
|
||||
<Route path="/new-content/question-types" element={<QuestionTypeLibraryPage />} />
|
||||
<Route path="/new-content/question-types/create" element={<CreateQuestionTypeFlow />} />
|
||||
<Route path="/new-content/question-types/:definitionId/edit" element={<CreateQuestionTypeFlow />} />
|
||||
<Route path="/new-content/question-types/:definitionId/create-practice" element={<AddPracticeFlow />} />
|
||||
<Route path="/new-content/practices/:practiceId/edit" element={<EditPracticeFlow />} />
|
||||
<Route path="/new-content/*" element={<Navigate to="/new-content/courses" replace />} />
|
||||
|
||||
<Route path="/personas" element={<PersonasPage />} />
|
||||
<Route path="/admin/personas" element={<PersonasPage />} />
|
||||
|
|
|
|||
|
|
@ -75,13 +75,12 @@ const navEntries: NavEntry[] = [
|
|||
kind: "group",
|
||||
label: "Content",
|
||||
basePath: "/new-content",
|
||||
activePaths: ["/new-content"],
|
||||
activePaths: ["/new-content", "/content"],
|
||||
icon: BookOpen,
|
||||
children: [
|
||||
{ label: "Learning content", to: "/new-content", end: true },
|
||||
{ label: "Reorder structure", to: "/new-content/reorder" },
|
||||
{ label: "Courses", to: "/new-content/courses" },
|
||||
{ label: "Question types", to: "/new-content/question-types" },
|
||||
{ label: "Initial assessment", to: "/new-content/initial-assessment" },
|
||||
{ label: "Question bank", to: "/content/questions" },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,13 +1,4 @@
|
|||
import {
|
||||
getExamPrepCatalogCourses,
|
||||
getExamPrepCatalogUnits,
|
||||
getExamPrepModuleLessons,
|
||||
getExamPrepUnitModules,
|
||||
getLearningPrograms,
|
||||
getModuleLessons,
|
||||
getProgramCourses,
|
||||
getTopLevelCourseModules,
|
||||
} from "../api/courses.api"
|
||||
import http from "../api/http"
|
||||
import type { PracticeParent, PracticeParentKind } from "../types/course.types"
|
||||
import {
|
||||
dedupeParents,
|
||||
|
|
@ -15,8 +6,6 @@ import {
|
|||
formatPracticeParentsSummary,
|
||||
} from "./practiceParents"
|
||||
|
||||
const LIST_LIMIT = 200
|
||||
|
||||
export type PracticeParentTitleMap = Map<string, string>
|
||||
|
||||
export type PracticeParentTitleHints = {
|
||||
|
|
@ -30,8 +19,8 @@ export function practiceParentKey(parent: PracticeParent): string {
|
|||
}
|
||||
|
||||
function kindLabel(kind: PracticeParentKind): string {
|
||||
if (kind === "CATALOG_COURSE") return "Catalog course"
|
||||
if (kind === "UNIT") return "Unit"
|
||||
if (kind === "CATALOG_COURSE") return "Course"
|
||||
if (kind === "UNIT" || kind === "CHAPTER") return "Chapter"
|
||||
if (kind === "COURSE") return "Course"
|
||||
if (kind === "MODULE") return "Module"
|
||||
return "Lesson"
|
||||
|
|
@ -73,206 +62,29 @@ function applyHints(
|
|||
}
|
||||
}
|
||||
|
||||
async function resolveLearnEnglishCourseTitles(
|
||||
ids: Set<number>,
|
||||
map: PracticeParentTitleMap,
|
||||
): Promise<void> {
|
||||
if (ids.size === 0) return
|
||||
const progRes = await getLearningPrograms({ limit: LIST_LIMIT, offset: 0 })
|
||||
const programs = progRes.data?.data?.programs ?? []
|
||||
for (const program of programs) {
|
||||
if (ids.size === 0) break
|
||||
const cRes = await getProgramCourses(program.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
for (const course of cRes.data?.data?.courses ?? []) {
|
||||
if (ids.has(course.id)) {
|
||||
map.set(`COURSE:${course.id}`, course.name?.trim() || `Course #${course.id}`)
|
||||
ids.delete(course.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveExamPrepCourseTitles(
|
||||
ids: Set<number>,
|
||||
map: PracticeParentTitleMap,
|
||||
): Promise<void> {
|
||||
if (ids.size === 0) return
|
||||
const res = await getExamPrepCatalogCourses({ limit: LIST_LIMIT, offset: 0 })
|
||||
for (const course of res.data?.data?.catalog_courses ?? []) {
|
||||
if (ids.has(course.id)) {
|
||||
const title = course.name?.trim() || `Course #${course.id}`
|
||||
map.set(`CATALOG_COURSE:${course.id}`, title)
|
||||
map.set(`COURSE:${course.id}`, title)
|
||||
ids.delete(course.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveExamPrepUnitTitles(
|
||||
ids: Set<number>,
|
||||
map: PracticeParentTitleMap,
|
||||
): Promise<void> {
|
||||
if (ids.size === 0) return
|
||||
const coursesRes = await getExamPrepCatalogCourses({ limit: LIST_LIMIT, offset: 0 })
|
||||
for (const course of coursesRes.data?.data?.catalog_courses ?? []) {
|
||||
if (ids.size === 0) break
|
||||
const unitsRes = await getExamPrepCatalogUnits(course.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
for (const unit of unitsRes.data?.data?.units ?? []) {
|
||||
if (ids.has(unit.id)) {
|
||||
map.set(`UNIT:${unit.id}`, unit.name?.trim() || `Unit #${unit.id}`)
|
||||
ids.delete(unit.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveLearnEnglishModuleTitles(
|
||||
ids: Set<number>,
|
||||
map: PracticeParentTitleMap,
|
||||
): Promise<void> {
|
||||
if (ids.size === 0) return
|
||||
const progRes = await getLearningPrograms({ limit: LIST_LIMIT, offset: 0 })
|
||||
const programs = progRes.data?.data?.programs ?? []
|
||||
for (const program of programs) {
|
||||
if (ids.size === 0) break
|
||||
const cRes = await getProgramCourses(program.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
const courses = cRes.data?.data?.courses ?? []
|
||||
const moduleBatches = await Promise.all(
|
||||
courses.map((course) =>
|
||||
getTopLevelCourseModules(course.id, { limit: LIST_LIMIT, offset: 0 }),
|
||||
),
|
||||
)
|
||||
for (let i = 0; i < courses.length; i++) {
|
||||
for (const module of moduleBatches[i].data?.data?.modules ?? []) {
|
||||
if (ids.has(module.id)) {
|
||||
map.set(`MODULE:${module.id}`, module.name?.trim() || `Module #${module.id}`)
|
||||
ids.delete(module.id)
|
||||
}
|
||||
}
|
||||
if (ids.size === 0) break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveExamPrepModuleTitles(
|
||||
ids: Set<number>,
|
||||
map: PracticeParentTitleMap,
|
||||
): Promise<void> {
|
||||
if (ids.size === 0) return
|
||||
const coursesRes = await getExamPrepCatalogCourses({ limit: LIST_LIMIT, offset: 0 })
|
||||
const catalogCourses = coursesRes.data?.data?.catalog_courses ?? []
|
||||
for (const course of catalogCourses) {
|
||||
if (ids.size === 0) break
|
||||
const unitsRes = await getExamPrepCatalogUnits(course.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
const units = unitsRes.data?.data?.units ?? []
|
||||
for (const unit of units) {
|
||||
const modulesRes = await getExamPrepUnitModules(unit.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
for (const module of modulesRes.data?.data?.modules ?? []) {
|
||||
if (ids.has(module.id)) {
|
||||
map.set(`MODULE:${module.id}`, module.name?.trim() || `Module #${module.id}`)
|
||||
ids.delete(module.id)
|
||||
}
|
||||
}
|
||||
if (ids.size === 0) break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveLearnEnglishLessonTitles(
|
||||
ids: Set<number>,
|
||||
map: PracticeParentTitleMap,
|
||||
): Promise<void> {
|
||||
if (ids.size === 0) return
|
||||
const progRes = await getLearningPrograms({ limit: LIST_LIMIT, offset: 0 })
|
||||
const programs = progRes.data?.data?.programs ?? []
|
||||
for (const program of programs) {
|
||||
if (ids.size === 0) break
|
||||
const cRes = await getProgramCourses(program.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
const courses = cRes.data?.data?.courses ?? []
|
||||
for (const course of courses) {
|
||||
if (ids.size === 0) break
|
||||
const mRes = await getTopLevelCourseModules(course.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
const modules = mRes.data?.data?.modules ?? []
|
||||
const lessonBatches = await Promise.all(
|
||||
modules.map((module) =>
|
||||
getModuleLessons(module.id, { limit: LIST_LIMIT, offset: 0 }),
|
||||
),
|
||||
)
|
||||
for (let i = 0; i < modules.length; i++) {
|
||||
for (const lesson of lessonBatches[i].data?.data?.lessons ?? []) {
|
||||
if (ids.has(lesson.id)) {
|
||||
map.set(`LESSON:${lesson.id}`, lesson.title?.trim() || `Lesson #${lesson.id}`)
|
||||
ids.delete(lesson.id)
|
||||
}
|
||||
}
|
||||
if (ids.size === 0) break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveExamPrepLessonTitles(
|
||||
ids: Set<number>,
|
||||
map: PracticeParentTitleMap,
|
||||
): Promise<void> {
|
||||
if (ids.size === 0) return
|
||||
const coursesRes = await getExamPrepCatalogCourses({ limit: LIST_LIMIT, offset: 0 })
|
||||
const catalogCourses = coursesRes.data?.data?.catalog_courses ?? []
|
||||
for (const course of catalogCourses) {
|
||||
if (ids.size === 0) break
|
||||
const unitsRes = await getExamPrepCatalogUnits(course.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
const units = unitsRes.data?.data?.units ?? []
|
||||
for (const unit of units) {
|
||||
if (ids.size === 0) break
|
||||
const modulesRes = await getExamPrepUnitModules(unit.id, { limit: LIST_LIMIT, offset: 0 })
|
||||
const modules = modulesRes.data?.data?.modules ?? []
|
||||
for (const module of modules) {
|
||||
if (ids.size === 0) break
|
||||
const lessonsRes = await getExamPrepModuleLessons(module.id, {
|
||||
limit: LIST_LIMIT,
|
||||
offset: 0,
|
||||
})
|
||||
for (const lesson of lessonsRes.data?.data?.lessons ?? []) {
|
||||
if (ids.has(lesson.id)) {
|
||||
map.set(`LESSON:${lesson.id}`, lesson.title?.trim() || `Lesson #${lesson.id}`)
|
||||
ids.delete(lesson.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolve only the requested IDs against the canonical hierarchy. */
|
||||
export async function resolvePracticeParentTitles(
|
||||
parents: PracticeParent[],
|
||||
hints?: PracticeParentTitleHints,
|
||||
): Promise<PracticeParentTitleMap> {
|
||||
const map: PracticeParentTitleMap = new Map()
|
||||
applyHints(map, hints)
|
||||
|
||||
const normalized = dedupeParents(parents)
|
||||
const unresolvedCourses = new Set<number>()
|
||||
const unresolvedCatalogCourses = new Set<number>()
|
||||
const unresolvedUnits = new Set<number>()
|
||||
const unresolvedModules = new Set<number>()
|
||||
const unresolvedLessons = new Set<number>()
|
||||
|
||||
for (const parent of normalized) {
|
||||
if (map.has(practiceParentKey(parent))) continue
|
||||
if (parent.parent_kind === "COURSE") unresolvedCourses.add(parent.parent_id)
|
||||
if (parent.parent_kind === "CATALOG_COURSE") unresolvedCatalogCourses.add(parent.parent_id)
|
||||
if (parent.parent_kind === "UNIT") unresolvedUnits.add(parent.parent_id)
|
||||
if (parent.parent_kind === "MODULE") unresolvedModules.add(parent.parent_id)
|
||||
if (parent.parent_kind === "LESSON") unresolvedLessons.add(parent.parent_id)
|
||||
}
|
||||
|
||||
await resolveLearnEnglishCourseTitles(unresolvedCourses, map)
|
||||
await resolveExamPrepCourseTitles(unresolvedCatalogCourses, map)
|
||||
await resolveExamPrepUnitTitles(unresolvedUnits, map)
|
||||
await resolveLearnEnglishModuleTitles(unresolvedModules, map)
|
||||
await resolveExamPrepModuleTitles(unresolvedModules, map)
|
||||
await resolveLearnEnglishLessonTitles(unresolvedLessons, map)
|
||||
await resolveExamPrepLessonTitles(unresolvedLessons, map)
|
||||
|
||||
await Promise.all(dedupeParents(parents).map(async parent => {
|
||||
const key = practiceParentKey(parent)
|
||||
if (map.has(key)) return
|
||||
const collection = parent.parent_kind === "COURSE" || parent.parent_kind === "CATALOG_COURSE"
|
||||
? "courses"
|
||||
: parent.parent_kind === "CHAPTER" || parent.parent_kind === "UNIT"
|
||||
? "chapters"
|
||||
: parent.parent_kind === "LESSON" ? "lessons" : null
|
||||
if (!collection) return
|
||||
try {
|
||||
const { data } = await http.get(`/${collection}/${parent.parent_id}`, { skipErrorToast: true })
|
||||
const title = data.data?.name ?? data.data?.title
|
||||
if (typeof title === "string" && title.trim()) map.set(key, title.trim())
|
||||
} catch {
|
||||
// A deleted or inaccessible parent retains its ID label.
|
||||
}
|
||||
}))
|
||||
return map
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { PracticeParent, PracticeParentKind } from "../types/course.types"
|
||||
|
||||
const PARENT_KINDS: PracticeParentKind[] = [
|
||||
"CHAPTER",
|
||||
"COURSE",
|
||||
"MODULE",
|
||||
"LESSON",
|
||||
|
|
@ -74,7 +75,7 @@ export function validatePracticeParents(
|
|||
const required = options?.required !== false
|
||||
const normalized = dedupeParents(parents)
|
||||
if (normalized.length === 0) {
|
||||
return required ? "Select at least one course, module, or lesson." : null
|
||||
return required ? "Select at least one course, chapter, or lesson." : null
|
||||
}
|
||||
for (let i = 0; i < parents.length; i++) {
|
||||
const row = parents[i]
|
||||
|
|
@ -97,9 +98,10 @@ export function validatePracticeParents(
|
|||
export function formatPracticeParentLabel(parent: PracticeParent): string {
|
||||
switch (parent.parent_kind) {
|
||||
case "CATALOG_COURSE":
|
||||
return `Catalog course #${parent.parent_id}`
|
||||
return `Course #${parent.parent_id}`
|
||||
case "UNIT":
|
||||
return `Unit #${parent.parent_id}`
|
||||
case "CHAPTER":
|
||||
return `Chapter #${parent.parent_id}`
|
||||
case "COURSE":
|
||||
return `Course #${parent.parent_id}`
|
||||
case "MODULE":
|
||||
|
|
@ -118,8 +120,8 @@ export function formatPracticeParentsSummary(
|
|||
const list = dedupeParents(parents)
|
||||
if (list.length === 0) {
|
||||
return options?.isExamPrep
|
||||
? "Not attached to any catalog course, unit, or lesson"
|
||||
: "Not attached to any course, module, or lesson"
|
||||
? "Not attached to any course, chapter, or lesson"
|
||||
: "Not attached to any course, chapter, or lesson"
|
||||
}
|
||||
return list.map(formatPracticeParentLabel).join(" · ")
|
||||
}
|
||||
|
|
|
|||
4
src/lib/publicApiBase.ts
Normal file
4
src/lib/publicApiBase.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/** Public discovery must never inherit the staff /admin scope. */
|
||||
export function publicApiBase(value: string): string {
|
||||
return value.replace(/\/+$/, "").replace(/\/admin$/, "")
|
||||
}
|
||||
|
|
@ -234,6 +234,7 @@ export function LoginPage() {
|
|||
|
||||
return (
|
||||
<div className="relative flex min-h-dvh overflow-y-auto bg-[#f4f2ec]">
|
||||
<Link to="/catalog" className="absolute right-5 top-5 z-10 text-sm font-medium text-[#163d35] underline">Explore courses without signing in</Link>
|
||||
{/* Decorative left panel */}
|
||||
<div className="hidden lg:flex lg:w-1/2 xl:w-[55%] items-center justify-center bg-[#163d35] relative">
|
||||
{/* Abstract decorative shapes */}
|
||||
|
|
|
|||
85
src/pages/catalog/PublicCatalogPage.tsx
Normal file
85
src/pages/catalog/PublicCatalogPage.tsx
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
import { useEffect, useState } from "react"
|
||||
import { Link, useParams, useSearchParams } from "react-router-dom"
|
||||
import { ArrowLeft, ArrowRight, BookOpen, CheckCircle2, LockKeyhole, Search } from "lucide-react"
|
||||
import { BrandLogo } from "../../components/brand/BrandLogo"
|
||||
import { catalogThumbnail, getPublicCourse, getPublicCourses, type PublicCatalogPage as Catalog, type PublicCourseOutline } from "../../api/publicCatalog.api"
|
||||
|
||||
const learnerApp = import.meta.env.VITE_LEARNER_APP_URL as string | undefined
|
||||
|
||||
export function PublicCatalogPage() {
|
||||
const { courseId } = useParams<{ courseId: string }>()
|
||||
const [params, setParams] = useSearchParams()
|
||||
const search = params.get("q") ?? ""
|
||||
const offset = Math.max(0, Number(params.get("offset")) || 0)
|
||||
const [draftSearch, setDraftSearch] = useState(search)
|
||||
const [catalog, setCatalog] = useState<Catalog | null>(null)
|
||||
const [course, setCourse] = useState<PublicCourseOutline | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState("")
|
||||
const [retry, setRetry] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
async function load() {
|
||||
setLoading(true); setError(""); setCourse(null)
|
||||
try {
|
||||
if (courseId) {
|
||||
const id = Number(courseId)
|
||||
if (!Number.isSafeInteger(id) || id < 1) throw new Error("This course is not available.")
|
||||
const outline = await getPublicCourse(id, controller.signal)
|
||||
if (!controller.signal.aborted) setCourse(outline)
|
||||
} else {
|
||||
const page = await getPublicCourses(search, offset, controller.signal)
|
||||
if (!controller.signal.aborted) setCatalog(page)
|
||||
}
|
||||
} catch (problem) {
|
||||
if (!controller.signal.aborted) setError(problem instanceof Error ? problem.message : "Unable to load courses.")
|
||||
} finally { if (!controller.signal.aborted) setLoading(false) }
|
||||
}
|
||||
void load()
|
||||
return () => controller.abort()
|
||||
}, [courseId, search, offset, retry])
|
||||
|
||||
return <div className="min-h-screen bg-[#f7f6f2] text-[#163d35]">
|
||||
<header className="border-b border-[#163d35]/10 bg-white"><div className="mx-auto flex max-w-6xl items-center justify-between gap-4 px-5 py-5">
|
||||
<Link to="/catalog" aria-label="Rezina course catalog"><BrandLogo className="h-10" /></Link>
|
||||
<nav className="flex items-center gap-5 text-sm"><Link to="/catalog" className="font-semibold">Explore courses</Link><Link to="/login" className="rounded-full border border-[#163d35]/20 px-4 py-2">Staff sign in</Link></nav>
|
||||
</div></header>
|
||||
<main className="mx-auto max-w-6xl px-5 py-10 sm:py-16">
|
||||
{courseId ? <Link to={`/catalog${params.size ? `?${params}` : ""}`} className="mb-8 inline-flex items-center gap-2 text-sm"><ArrowLeft size={16} />All courses</Link> : <section className="mb-10 max-w-3xl">
|
||||
<p className="mb-4 text-xs font-semibold uppercase tracking-[.24em] text-[#987343]">Your next chapter starts here</p>
|
||||
<h1 className="text-4xl font-semibold leading-tight tracking-tight sm:text-6xl">Build skills.<br />Open new possibilities.</h1>
|
||||
<p className="mt-5 max-w-xl text-lg leading-relaxed text-[#163d35]/70">Explore our courses, discover what you will learn, and find the right place to begin. Browse every published course without an account.</p>
|
||||
<form onSubmit={event => { event.preventDefault(); setParams(draftSearch.trim() ? { q: draftSearch.trim() } : {}) }} className="mt-7 flex max-w-xl gap-2 rounded-xl border border-[#163d35]/15 bg-white p-2">
|
||||
<label className="flex flex-1 items-center gap-3 px-2"><Search size={20} /><input aria-label="Search courses" className="min-w-0 flex-1 bg-transparent py-2 outline-none" placeholder="What would you like to learn?" maxLength={200} value={draftSearch} onChange={event => setDraftSearch(event.target.value)} /></label>
|
||||
<button className="rounded-lg bg-[#163d35] px-5 text-sm font-semibold text-white">Search</button>
|
||||
</form>
|
||||
</section>}
|
||||
{loading ? <p role="status" className="py-16 text-center">Loading courses...</p> : error ? <div role="alert" className="rounded-2xl border bg-white p-8"><p>{error}</p><button className="mt-4 underline" onClick={() => setRetry(value => value + 1)}>Try again</button></div> : course ? <>
|
||||
<section className="grid gap-8 rounded-3xl bg-[#163d35] p-7 text-white sm:p-10 md:grid-cols-[1fr_280px]">
|
||||
<div><p className="mb-3 text-sm text-[#e4c28f]">{course.access_tier === "PREMIUM" ? "Premium course" : "Free course"}</p><h1 className="text-3xl font-semibold sm:text-5xl">{course.name}</h1><p className="mt-5 leading-relaxed text-white/75">{course.description}</p>
|
||||
<p className="mt-5 text-sm text-white/70">{course.chapter_count} chapters · {course.lesson_count} lessons · {course.quiz_count} quizzes</p>
|
||||
{learnerApp ? <a href={learnerApp} className="mt-7 inline-flex rounded-full bg-[#e4c28f] px-6 py-3 font-semibold text-[#163d35]">Sign in to learn<ArrowRight className="ml-2" size={18} /></a> : <p className="mt-7 flex items-center gap-2 text-sm"><LockKeyhole size={17} />Sign in through your learning app to watch lessons and take quizzes.</p>}
|
||||
</div><div className="flex items-center justify-center overflow-hidden rounded-xl bg-white/5">{course.thumbnail ? <img className="h-full max-h-64 w-full object-cover" src={catalogThumbnail(course.thumbnail)} alt="" /> : <BookOpen size={80} className="text-[#e4c28f]" />}</div>
|
||||
</section>
|
||||
<section className="mt-12 max-w-4xl"><h2 className="mb-6 text-2xl font-semibold">What you will learn</h2><div className="space-y-4">
|
||||
{course.chapters.map((chapter, index) => <details key={chapter.id} className="rounded-2xl border border-[#163d35]/10 bg-white p-5" open={index === 0}>
|
||||
<summary className="cursor-pointer text-lg font-semibold">{index + 1}. {chapter.name}<span className="ml-3 text-sm font-normal text-[#163d35]/60">{chapter.lessons.length} lessons</span></summary>
|
||||
<p className="mt-3 text-sm text-[#163d35]/70">{chapter.description}</p>
|
||||
<ul className="mt-4 divide-y divide-[#163d35]/10">{chapter.lessons.map(lesson => <li key={lesson.id} className="flex gap-3 py-4"><BookOpen size={18} className="mt-1 shrink-0" /><div><h3 className="font-medium">{lesson.title}</h3><p className="mt-1 text-sm leading-relaxed text-[#163d35]/65">{lesson.description}</p><span className="mt-2 inline-block text-xs text-[#163d35]/60">{lesson.access_tier === "PREMIUM" ? "Premium lesson" : "Free lesson"}</span></div></li>)}
|
||||
{chapter.quizzes.map(quiz => <li key={`quiz-${quiz.id}`} className="flex gap-3 py-4"><CheckCircle2 size={18} className="mt-1 shrink-0" /><div><h3 className="font-medium">{quiz.title}</h3><p className="mt-1 text-sm text-[#163d35]/65">Chapter quiz · {quiz.question_count} questions</p></div></li>)}</ul>
|
||||
</details>)}
|
||||
{!course.chapters.length && <p>The course outline will be available soon.</p>}
|
||||
</div></section>
|
||||
</> : <section aria-label="Course highlights">
|
||||
<div className="mb-6 flex items-center justify-between"><h2 className="text-2xl font-semibold">{search ? `Results for “${search}”` : "Explore our courses"}</h2><span className="text-sm text-[#163d35]/65">{catalog?.total_count ?? 0} courses</span></div>
|
||||
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">{catalog?.courses.map(item => <Link key={item.id} to={`/catalog/courses/${item.id}${params.size ? `?${params}` : ""}`} className="group overflow-hidden rounded-2xl border border-[#163d35]/10 bg-white transition hover:-translate-y-1 hover:shadow-lg">
|
||||
<div className="flex h-44 items-center justify-center overflow-hidden bg-[#163d35]">{item.thumbnail ? <img src={catalogThumbnail(item.thumbnail)} alt="" className="h-full w-full object-cover" loading="lazy" /> : <BookOpen size={55} className="text-[#e4c28f]" />}</div>
|
||||
<div className="p-6"><span className="text-xs font-semibold uppercase tracking-wide text-[#987343]">{item.access_tier === "PREMIUM" ? "Premium" : "Free"}</span><h3 className="mt-2 text-xl font-semibold">{item.name}</h3><p className="mt-3 line-clamp-3 text-sm leading-relaxed text-[#163d35]/65">{item.description}</p><p className="mt-5 text-xs text-[#163d35]/65">{item.chapter_count} chapters · {item.lesson_count} lessons · {item.quiz_count} quizzes</p><span className="mt-5 inline-flex items-center gap-2 text-sm font-semibold">View course<ArrowRight size={16} /></span></div>
|
||||
</Link>)}</div>
|
||||
{!catalog?.courses.length && <p className="rounded-2xl border border-dashed p-12 text-center">{search ? "No courses match your search. Try another topic." : "New courses are on their way. Check back soon."}</p>}
|
||||
{!!catalog?.total_count && <nav aria-label="Catalog pages" className="mt-8 flex justify-center gap-5"><button className="rounded-full border px-5 py-2 disabled:opacity-40" disabled={offset === 0} onClick={() => setParams({ q: search, offset: String(Math.max(0, offset - 12)) })}>Previous</button><button className="rounded-full border px-5 py-2 disabled:opacity-40" disabled={offset + 12 >= catalog.total_count} onClick={() => setParams({ q: search, offset: String(offset + 12) })}>Next</button></nav>}
|
||||
</section>}
|
||||
</main><footer className="mx-auto max-w-6xl px-5 pb-10 text-sm text-[#163d35]/60">Rezina · Learn at your own pace.</footer>
|
||||
</div>
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ export function ContentManagementLayout() {
|
|||
Content Management
|
||||
</h1>
|
||||
<p className="mt-1 max-w-2xl text-sm leading-relaxed text-grayScale-500">
|
||||
View and manage practice content for courses, modules, and lessons
|
||||
Manage courses, chapters, lessons, and chapter quizzes
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
149
src/pages/content-management/LearningHierarchyPage.tsx
Normal file
149
src/pages/content-management/LearningHierarchyPage.tsx
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
import { Link, useParams } from "react-router-dom"
|
||||
import { ArrowDown, ArrowLeft, ArrowUp, BookOpen, Pencil, Plus, Trash2 } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
import http from "../../api/http"
|
||||
import { Button } from "../../components/ui/button"
|
||||
import { Input } from "../../components/ui/input"
|
||||
import { Textarea } from "../../components/ui/textarea"
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../../components/ui/dialog"
|
||||
import { notifyApiError } from "../../lib/apiErrors"
|
||||
|
||||
import {
|
||||
createChapterQuiz, getLearningItem, listLearningItems as allItems,
|
||||
learningCollections as collection, updateChapterQuiz,
|
||||
type LearningItem as Item, type LearningKind as Kind,
|
||||
} from "../../api/learningHierarchy.api"
|
||||
|
||||
type Editor = { kind: Kind; item?: Item }
|
||||
|
||||
export function LearningHierarchyPage() {
|
||||
const { courseId, chapterId } = useParams<{ courseId: string; chapterId: string }>()
|
||||
const kind: Kind = chapterId ? "lesson" : courseId ? "chapter" : "course"
|
||||
const path = chapterId ? `/chapters/${chapterId}/lessons` : courseId ? `/courses/${courseId}/chapters` : "/courses"
|
||||
const activePath = useRef(path)
|
||||
const requestVersion = useRef(0)
|
||||
useEffect(() => { activePath.current = path; return () => { requestVersion.current += 1 } }, [path])
|
||||
const [items, setItems] = useState<Item[]>([])
|
||||
const [quizzes, setQuizzes] = useState<Item[]>([])
|
||||
const [course, setCourse] = useState<Item | null>(null)
|
||||
const [chapter, setChapter] = useState<Item | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [failed, setFailed] = useState(false)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [search, setSearch] = useState("")
|
||||
const [editor, setEditor] = useState<Editor | null>(null)
|
||||
const [deleting, setDeleting] = useState<{ item: Item; kind: Kind } | null>(null)
|
||||
const [form, setForm] = useState({ name: "", description: "", thumbnail: "", video_url: "", access_tier: "FREE" })
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (activePath.current !== path) return
|
||||
const version = ++requestVersion.current
|
||||
setLoading(true); setFailed(false)
|
||||
try {
|
||||
const [rows, quizRows, courseRes, chapterRes] = await Promise.all([
|
||||
allItems(path, collection[kind]),
|
||||
chapterId ? allItems(`/chapters/${chapterId}/quizzes`, "quizzes") : Promise.resolve([]),
|
||||
courseId ? getLearningItem("course", Number(courseId)) : Promise.resolve(null),
|
||||
chapterId ? getLearningItem("chapter", Number(chapterId)) : Promise.resolve(null),
|
||||
])
|
||||
if (version !== requestVersion.current || activePath.current !== path) return
|
||||
if (chapterRes && chapterRes.course_id !== Number(courseId)) {
|
||||
throw new Error("This chapter does not belong to the selected course")
|
||||
}
|
||||
setItems(rows); setQuizzes(quizRows); setCourse(courseRes); setChapter(chapterRes)
|
||||
} catch (error) { if (version === requestVersion.current && activePath.current === path) { setFailed(true); notifyApiError(error, "Unable to load learning content") } }
|
||||
finally { if (version === requestVersion.current && activePath.current === path) setLoading(false) }
|
||||
}, [path, kind, courseId, chapterId])
|
||||
useEffect(() => { setSearch(""); void load() }, [load])
|
||||
|
||||
function openEditor(next: Editor) {
|
||||
setEditor(next)
|
||||
const item = next.item
|
||||
setForm({ name: item?.name ?? item?.title ?? "", description: item?.description ?? "", thumbnail: item?.thumbnail ?? "", video_url: item?.video_url ?? "", access_tier: item?.access_tier ?? "FREE" })
|
||||
}
|
||||
async function save(event: React.FormEvent) {
|
||||
event.preventDefault()
|
||||
if (!editor || busy || !form.name.trim()) return
|
||||
setBusy(true)
|
||||
try {
|
||||
const payload = { ...form, name: form.name.trim() }
|
||||
if (editor.kind === "quiz") {
|
||||
if (editor.item) {
|
||||
await updateChapterQuiz(editor.item.id, { title: form.name.trim() })
|
||||
} else {
|
||||
await createChapterQuiz(Number(chapterId), form.name.trim())
|
||||
}
|
||||
} else {
|
||||
const body = editor.kind === "lesson" ? { title: payload.name, description: payload.description, thumbnail: payload.thumbnail, video_url: payload.video_url, access_tier: payload.access_tier } : payload
|
||||
if (editor.item) await http.put(`/${collection[editor.kind]}/${editor.item.id}`, body)
|
||||
else await http.post(path, { ...body, publish_status: "DRAFT" })
|
||||
}
|
||||
setEditor(null); toast.success(`${editor.kind} saved`); await load()
|
||||
} catch (error) { notifyApiError(error, "Unable to save content") }
|
||||
finally { setBusy(false) }
|
||||
}
|
||||
async function publish(item: Item, itemKind: Kind) {
|
||||
setBusy(true)
|
||||
try {
|
||||
const status = item.publish_status === "PUBLISHED" ? "DRAFT" : "PUBLISHED"
|
||||
if (itemKind === "quiz") await updateChapterQuiz(item.id, { publish_status: status })
|
||||
else await http.put(`/${collection[itemKind]}/${item.id}`, { publish_status: status })
|
||||
await load()
|
||||
} catch (error) { notifyApiError(error, "Unable to change publication status") }
|
||||
finally { setBusy(false) }
|
||||
}
|
||||
async function remove() {
|
||||
if (!deleting) return
|
||||
setBusy(true)
|
||||
try { await http.delete(`/${collection[deleting.kind]}/${deleting.item.id}`); setDeleting(null); await load() }
|
||||
catch (error) { notifyApiError(error, "Unable to delete content") }
|
||||
finally { setBusy(false) }
|
||||
}
|
||||
async function move(index: number, direction: number) {
|
||||
const ordered = [...items]; const target = index + direction
|
||||
if (target < 0 || target >= ordered.length) return
|
||||
;[ordered[index], ordered[target]] = [ordered[target], ordered[index]]
|
||||
setBusy(true)
|
||||
try { await http.put(`${path}/reorder`, { ordered_ids: ordered.map(item => item.id) }); setItems(ordered) }
|
||||
catch (error) { notifyApiError(error, "Unable to reorder content") }
|
||||
finally { setBusy(false) }
|
||||
}
|
||||
const title = chapter?.name ?? course?.name ?? "Courses"
|
||||
const matches = (item: Item) => (item.name ?? item.title ?? "").toLowerCase().includes(search.toLowerCase())
|
||||
function card(item: Item, itemKind: Kind, index?: number) {
|
||||
return <article key={item.id} className="rounded-xl border border-grayScale-200 bg-white p-5 dark:bg-grayScale-50">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div className="min-w-0"><h3 className="text-lg font-semibold">{item.name ?? item.title}</h3><p className="mt-1 text-sm text-grayScale-500">{item.publish_status === "PUBLISHED" ? "Published" : "Draft"}{item.access_tier ? ` · ${item.access_tier.toLowerCase()}` : ""}</p></div>
|
||||
<div className="flex gap-1">
|
||||
{index !== undefined && !search && <><Button size="icon" variant="ghost" disabled={busy || index === 0} onClick={() => void move(index, -1)} aria-label="Move up"><ArrowUp size={16} /></Button><Button size="icon" variant="ghost" disabled={busy || index === items.length - 1} onClick={() => void move(index, 1)} aria-label="Move down"><ArrowDown size={16} /></Button></>}
|
||||
<Button size="icon" variant="ghost" disabled={busy} onClick={() => openEditor({ kind: itemKind, item })} aria-label="Edit"><Pencil size={16} /></Button>
|
||||
<Button size="icon" variant="ghost" disabled={busy} onClick={() => setDeleting({ item, kind: itemKind })} aria-label="Delete"><Trash2 size={16} /></Button>
|
||||
</div>
|
||||
</div>
|
||||
{item.description && <p className="mt-3 line-clamp-3 text-sm text-grayScale-600">{item.description}</p>}
|
||||
{item.video_url && <a className="mt-3 block text-sm text-brand-600 underline" href={item.video_url} target="_blank" rel="noreferrer">View lesson video</a>}
|
||||
<div className="mt-5 flex flex-wrap gap-2">
|
||||
{itemKind === "course" && <Button asChild variant="outline"><Link to={`/new-content/courses/${item.id}`}>Chapters</Link></Button>}
|
||||
{itemKind === "chapter" && <Button asChild variant="outline"><Link to={`/new-content/courses/${courseId}/chapters/${item.id}`}>Lessons & quizzes</Link></Button>}
|
||||
{itemKind === "quiz" && <Button asChild variant="outline"><Link to={`/content/question-sets/${item.question_set_id}/questions`} state={{ from: `/new-content/courses/${courseId}/chapters/${chapterId}` }}>Edit questions</Link></Button>}
|
||||
<Button variant="outline" disabled={busy} onClick={() => void publish(item, itemKind)}>{item.publish_status === "PUBLISHED" ? "Unpublish" : "Publish"}</Button>
|
||||
</div>
|
||||
</article>
|
||||
}
|
||||
return <div className="mx-auto max-w-6xl space-y-6 p-4 sm:p-6">
|
||||
<nav className="flex flex-wrap items-center gap-2 text-sm text-grayScale-500"><Link to="/new-content/courses">Courses</Link>{courseId && <><span>/</span><Link to={`/new-content/courses/${courseId}`}>{course?.name ?? "Course"}</Link></>}{chapterId && <><span>/</span><span>{chapter?.name ?? "Chapter"}</span></>}</nav>
|
||||
<header className="flex flex-wrap items-center justify-between gap-4"><div><h1 className="flex items-center gap-3 text-2xl font-bold"><BookOpen />{title}</h1><p className="mt-2 text-grayScale-500">{chapterId ? "Manage the lessons and quizzes in this chapter." : courseId ? "Organize this course into chapters." : "Create courses, organize chapters, and add lessons and chapter quizzes."}</p></div><Button disabled={busy || loading || failed} onClick={() => openEditor({ kind })}><Plus size={16} className="mr-2" />Add {kind}</Button></header>
|
||||
{courseId && <Button asChild variant="ghost"><Link to={chapterId ? `/new-content/courses/${courseId}` : "/new-content/courses"}><ArrowLeft size={16} className="mr-2" />Back to {chapterId ? "chapters" : "courses"}</Link></Button>}
|
||||
<Input aria-label="Search content" placeholder="Search by title…" value={search} onChange={event => setSearch(event.target.value)} />
|
||||
{loading ? <p role="status">Loading content…</p> : failed ? <div role="alert"><p>Content could not be loaded.</p><Button onClick={() => void load()}>Try again</Button></div> : <>
|
||||
<section className="space-y-4"><h2 className="text-xl font-semibold capitalize">{collection[kind]}</h2><div className="grid gap-4 md:grid-cols-2">{items.map((item, index) => matches(item) ? card(item, kind, index) : null)}</div>{!items.some(matches) && <p className="rounded-xl border border-dashed p-8 text-center text-grayScale-500">{search ? "No matching content." : `No ${collection[kind]} yet. Add your first ${kind} to get started.`}</p>}</section>
|
||||
{chapterId && <section className="space-y-4 border-t pt-6"><div className="flex items-center justify-between"><h2 className="text-xl font-semibold">Chapter quizzes</h2><Button disabled={busy} onClick={() => openEditor({ kind: "quiz" })}><Plus size={16} className="mr-2" />Add quiz</Button></div><div className="grid gap-4 md:grid-cols-2">{quizzes.filter(matches).map(item => card(item, "quiz"))}</div>{!quizzes.some(matches) && <p className="text-grayScale-500">{search ? "No matching quizzes." : "No quizzes yet. Create a quiz, add its questions, then publish it."}</p>}</section>}
|
||||
</>}
|
||||
<Dialog open={!!editor} onOpenChange={open => { if (!open && !busy) setEditor(null) }}><DialogContent><DialogHeader><DialogTitle>{editor?.item ? "Edit" : "Add"} {editor?.kind}</DialogTitle></DialogHeader><form onSubmit={save} className="space-y-4"><label className="block space-y-2"><span>Title</span><Input autoFocus required value={form.name} onChange={event => setForm({ ...form, name: event.target.value })} /></label>
|
||||
{editor?.kind !== "quiz" && <><label className="block space-y-2"><span>Description</span><Textarea value={form.description} onChange={event => setForm({ ...form, description: event.target.value })} /></label><label className="block space-y-2"><span>Thumbnail URL</span><Input type="url" value={form.thumbnail} onChange={event => setForm({ ...form, thumbnail: event.target.value })} /></label><label className="block space-y-2"><span>Access</span><select className="w-full rounded-md border p-2" value={form.access_tier} onChange={event => setForm({ ...form, access_tier: event.target.value })}><option value="FREE">Free</option><option value="PREMIUM">Premium</option></select></label></>}
|
||||
{editor?.kind === "lesson" && <label className="block space-y-2"><span>Video URL</span><Input type="url" value={form.video_url} onChange={event => setForm({ ...form, video_url: event.target.value })} /></label>}
|
||||
<div className="flex justify-end gap-2"><Button type="button" variant="outline" disabled={busy} onClick={() => setEditor(null)}>Cancel</Button><Button type="submit" disabled={busy || !form.name.trim()}>{busy ? "Saving…" : "Save"}</Button></div></form></DialogContent></Dialog>
|
||||
<Dialog open={!!deleting} onOpenChange={open => { if (!open && !busy) setDeleting(null) }}><DialogContent><DialogHeader><DialogTitle>Delete {deleting?.kind}?</DialogTitle></DialogHeader><p>This removes “{deleting?.item.name ?? deleting?.item.title}” and its child content.</p><div className="flex justify-end gap-2"><Button variant="outline" disabled={busy} onClick={() => setDeleting(null)}>Cancel</Button><Button variant="destructive" disabled={busy} onClick={() => void remove()}>{busy ? "Deleting…" : "Delete"}</Button></div></DialogContent></Dialog>
|
||||
</div>
|
||||
}
|
||||
|
|
@ -9,13 +9,13 @@ import { Badge } from "../../components/ui/badge"
|
|||
import { Button } from "../../components/ui/button"
|
||||
import {
|
||||
getQuestionSetById,
|
||||
getPracticeQuestionsByPractice,
|
||||
getQuestionById,
|
||||
deleteQuestion,
|
||||
removeQuestionFromSet,
|
||||
updateQuestion,
|
||||
createQuestion,
|
||||
addQuestionToSet,
|
||||
} from "../../api/courses.api"
|
||||
import { getQuizQuestions } from "../../api/learningHierarchy.api"
|
||||
import { Input } from "../../components/ui/input"
|
||||
import { Select } from "../../components/ui/select"
|
||||
import { Textarea } from "../../components/ui/textarea"
|
||||
|
|
@ -60,13 +60,7 @@ const typeColors: Record<QuestionType, string> = {
|
|||
}
|
||||
|
||||
export function PracticeQuestionsPage() {
|
||||
const { categoryId, courseId, subModuleId, levelId, practiceId } = useParams<{
|
||||
categoryId: string
|
||||
courseId: string
|
||||
subModuleId?: string
|
||||
levelId?: string
|
||||
practiceId?: string
|
||||
}>()
|
||||
const { practiceId } = useParams<{ practiceId: string }>()
|
||||
const location = useLocation()
|
||||
|
||||
const [questions, setQuestions] = useState<PracticeQuestion[]>([])
|
||||
|
|
@ -86,7 +80,7 @@ export function PracticeQuestionsPage() {
|
|||
const [loadingDetailIds, setLoadingDetailIds] = useState<Record<number, boolean>>({})
|
||||
const [groupBy, setGroupBy] = useState<GroupByOption>("none")
|
||||
const [pointsSort, setPointsSort] = useState<PointsSortOption>("desc")
|
||||
const [pageSize, setPageSize] = useState(DEFAULT_TABLE_PAGE_SIZE)
|
||||
const [pageSize, setPageSize] = useState<number>(DEFAULT_TABLE_PAGE_SIZE)
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
const [totalQuestions, setTotalQuestions] = useState(0)
|
||||
|
||||
|
|
@ -111,16 +105,9 @@ export function PracticeQuestionsPage() {
|
|||
|
||||
const backLink = useMemo(() => {
|
||||
const returnPath = (location.state as { from?: unknown } | null)?.from
|
||||
if (typeof returnPath === "string" && returnPath.startsWith("/new-content/")) return returnPath
|
||||
if (location.pathname.includes("/content/question-sets/")) return "/new-content"
|
||||
if (location.pathname.includes("/content/human-language/") && location.pathname.includes("/level/") && levelId) {
|
||||
return "/content/human-language"
|
||||
}
|
||||
if (location.pathname.includes("/content/human-language/") && location.pathname.includes("/sub-module/") && subModuleId) {
|
||||
return `/content/human-language/${categoryId}/${courseId}/sub-module/${subModuleId}`
|
||||
}
|
||||
return `/content/category/${categoryId}/courses/${courseId}/sub-modules/${subModuleId}`
|
||||
}, [location.pathname, categoryId, courseId, subModuleId, levelId])
|
||||
return typeof returnPath === "string" && returnPath.startsWith("/new-content/")
|
||||
? returnPath : "/new-content/courses"
|
||||
}, [location.state])
|
||||
|
||||
const buildDefaultOptions = (type: QuestionType, sampleAnswerText?: string): DraftOption[] => {
|
||||
if (type === "TRUE_FALSE") {
|
||||
|
|
@ -224,17 +211,15 @@ export function PracticeQuestionsPage() {
|
|||
|
||||
try {
|
||||
const safePage = page < 1 ? 1 : page
|
||||
const offset = (safePage - 1) * pageSize
|
||||
const [detailRes, questionsRes] = await Promise.all([
|
||||
const [detailRes, questionRows] = await Promise.all([
|
||||
getQuestionSetById(Number(practiceId)),
|
||||
getPracticeQuestionsByPractice(Number(practiceId), { limit: pageSize, offset }),
|
||||
getQuizQuestions(Number(practiceId)),
|
||||
])
|
||||
const detail = detailRes.data?.data
|
||||
setPracticeTitle(detail?.title || "Practice Questions")
|
||||
setPracticeDescription(detail?.description || "")
|
||||
|
||||
const payload = questionsRes.data?.data
|
||||
const mappedQuestions: PracticeQuestion[] = (payload?.questions ?? []).map(
|
||||
const mappedQuestions: PracticeQuestion[] = questionRows.map(
|
||||
(question: QuestionSetQuestion) => ({
|
||||
id: question.question_id || question.id,
|
||||
practice_id: question.set_id,
|
||||
|
|
@ -256,9 +241,11 @@ export function PracticeQuestionsPage() {
|
|||
: "MCQ",
|
||||
}),
|
||||
)
|
||||
setQuestions(mappedQuestions)
|
||||
setTotalQuestions(payload?.total_count ?? mappedQuestions.length)
|
||||
setCurrentPage(safePage)
|
||||
const effectivePage = Math.min(safePage, Math.max(1, Math.ceil(mappedQuestions.length / pageSize)))
|
||||
const offset = (effectivePage - 1) * pageSize
|
||||
setQuestions(mappedQuestions.slice(offset, offset + pageSize))
|
||||
setTotalQuestions(mappedQuestions.length)
|
||||
setCurrentPage(effectivePage)
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch questions:", err)
|
||||
setError("Failed to load questions")
|
||||
|
|
@ -512,7 +499,7 @@ export function PracticeQuestionsPage() {
|
|||
if (!questionToDelete) return
|
||||
setDeleting(true)
|
||||
try {
|
||||
await deleteQuestion(questionToDelete.id)
|
||||
await removeQuestionFromSet(Number(practiceId), questionToDelete.id)
|
||||
setShowDeleteModal(false)
|
||||
setQuestionToDelete(null)
|
||||
await fetchQuestions()
|
||||
|
|
@ -801,7 +788,7 @@ export function PracticeQuestionsPage() {
|
|||
<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 rounded-xl bg-white shadow-2xl">
|
||||
<div className="flex items-center justify-between border-b border-grayScale-100 px-4 py-4 sm:px-6">
|
||||
<h2 className="text-lg font-semibold text-grayScale-900">Delete Question</h2>
|
||||
<h2 className="text-lg font-semibold text-grayScale-900">Remove Question</h2>
|
||||
<button
|
||||
onClick={() => setShowDeleteModal(false)}
|
||||
className="grid h-8 w-8 place-items-center rounded-[6px] text-grayScale-400 transition-colors hover:bg-grayScale-100 hover:text-grayScale-600"
|
||||
|
|
@ -811,7 +798,7 @@ export function PracticeQuestionsPage() {
|
|||
</div>
|
||||
<div className="px-6 py-6">
|
||||
<p className="text-sm leading-relaxed text-grayScale-600">
|
||||
Are you sure you want to delete this question? This action cannot be undone.
|
||||
Remove this question from this quiz? The question remains in the question bank and other quizzes.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col-reverse gap-3 border-t border-grayScale-100 px-6 py-4 sm:flex-row sm:justify-end">
|
||||
|
|
@ -819,7 +806,7 @@ export function PracticeQuestionsPage() {
|
|||
Cancel
|
||||
</Button>
|
||||
<Button className="bg-red-500 hover:bg-red-600" onClick={handleConfirmDelete} disabled={deleting}>
|
||||
{deleting ? "Deleting..." : "Delete"}
|
||||
{deleting ? "Removing..." : "Remove"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -16,20 +16,13 @@ import {
|
|||
import { formatPracticeParentDisplayLabel } from "../../../../lib/practiceParentTitles"
|
||||
import {
|
||||
isPracticeParentUnlinkNotLinkedError,
|
||||
mapPracticeParentUnlinkError,
|
||||
unlinkParentConfirmMessage,
|
||||
unlinkPracticeFromParent,
|
||||
} from "../../../../lib/practiceParentUnlink"
|
||||
|
||||
const LMS_KIND_OPTIONS: { value: PracticeParentKind; label: string }[] = [
|
||||
const PARENT_KIND_OPTIONS: { value: PracticeParentKind; label: string }[] = [
|
||||
{ value: "COURSE", label: "Course" },
|
||||
{ value: "MODULE", label: "Module" },
|
||||
{ value: "LESSON", label: "Lesson" },
|
||||
]
|
||||
|
||||
const EXAM_PREP_KIND_OPTIONS: { value: PracticeParentKind; label: string }[] = [
|
||||
{ value: "CATALOG_COURSE", label: "Catalog course" },
|
||||
{ value: "UNIT", label: "Unit" },
|
||||
{ value: "CHAPTER", label: "Chapter" },
|
||||
{ value: "LESSON", label: "Lesson" },
|
||||
]
|
||||
|
||||
|
|
@ -63,8 +56,8 @@ export function PracticeParentsField({
|
|||
practiceId,
|
||||
onUnlinked,
|
||||
}: PracticeParentsFieldProps) {
|
||||
const kindOptions = isExamPrep ? EXAM_PREP_KIND_OPTIONS : LMS_KIND_OPTIONS
|
||||
const rows = parents.length > 0 ? parents : [newParentRow(isExamPrep ? "CATALOG_COURSE" : "LESSON")]
|
||||
const kindOptions = PARENT_KIND_OPTIONS
|
||||
const rows = parents.length > 0 ? parents : [newParentRow("LESSON")]
|
||||
const savedParents = useMemo(
|
||||
() => dedupeParents(parents.filter((parent) => parent.parent_id > 0)),
|
||||
[parents],
|
||||
|
|
@ -156,11 +149,11 @@ export function PracticeParentsField({
|
|||
? "Remove a location with × to detach immediately. Add new locations here, then save the practice."
|
||||
: optional
|
||||
? isExamPrep
|
||||
? "Attach now or leave empty and link this practice to catalog courses, units, or lessons later."
|
||||
? "Attach now or leave empty and link this practice to courses, chapters, or lessons later."
|
||||
: "Attach now or leave empty and link this practice later."
|
||||
: isExamPrep
|
||||
? "Link this practice to one or more catalog courses, units, or lessons."
|
||||
: "Link this practice to one or more courses, modules, or lessons."}
|
||||
? "Link this practice to one or more courses, chapters, or lessons."
|
||||
: "Link this practice to one or more courses, chapters, or lessons."}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { BarChart3, CheckCircle2, ChevronDown, ChevronRight, Lock } from "lucide-react";
|
||||
import { Badge } from "../../../components/ui/badge";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "../../../components/ui/card";
|
||||
|
|
@ -9,8 +9,7 @@ import type {
|
|||
LearningActivityAccess,
|
||||
LearningActivityCourse,
|
||||
LearningActivityLesson,
|
||||
LearningActivityModule,
|
||||
LearningActivityUnit,
|
||||
LearningActivityChapter,
|
||||
UserLearningActivityData,
|
||||
} from "../../../types/userAdmin.types";
|
||||
|
||||
|
|
@ -78,45 +77,7 @@ function LessonRow({ lesson }: { lesson: LearningActivityLesson }) {
|
|||
);
|
||||
}
|
||||
|
||||
function ModuleBlock({ module }: { module: LearningActivityModule }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="rounded-xl border border-grayScale-100 bg-grayScale-50/60">
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-start justify-between gap-3 px-3 py-3 text-left"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium text-grayScale-800">{module.name || `Module #${module.id}`}</p>
|
||||
<div className="mt-2">
|
||||
<AccessMeta access={module.access} />
|
||||
</div>
|
||||
{!module.access.is_accessible && module.access.reason ? (
|
||||
<p className="mt-1.5 text-xs text-grayScale-400">{module.access.reason}</p>
|
||||
) : null}
|
||||
</div>
|
||||
{open ? (
|
||||
<ChevronDown className="mt-1 h-4 w-4 shrink-0 text-grayScale-400" />
|
||||
) : (
|
||||
<ChevronRight className="mt-1 h-4 w-4 shrink-0 text-grayScale-400" />
|
||||
)}
|
||||
</button>
|
||||
{open ? (
|
||||
<div className="space-y-2 border-t border-grayScale-100 px-3 py-3">
|
||||
{module.lessons.length === 0 ? (
|
||||
<p className="text-xs text-grayScale-400">No lessons in this module.</p>
|
||||
) : (
|
||||
module.lessons.map((lesson) => <LessonRow key={lesson.id} lesson={lesson} />)
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UnitBlock({ unit }: { unit: LearningActivityUnit }) {
|
||||
function ChapterBlock({ chapter }: { chapter: LearningActivityChapter }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
|
|
@ -127,9 +88,9 @@ function UnitBlock({ unit }: { unit: LearningActivityUnit }) {
|
|||
onClick={() => setOpen((prev) => !prev)}
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium text-grayScale-800">{unit.name || `Unit #${unit.id}`}</p>
|
||||
<p className="text-sm font-medium text-grayScale-800">{chapter.name || `Chapter #${chapter.id}`}</p>
|
||||
<div className="mt-2">
|
||||
<AccessMeta access={unit.access} />
|
||||
<AccessMeta access={chapter.access} />
|
||||
</div>
|
||||
</div>
|
||||
{open ? (
|
||||
|
|
@ -140,10 +101,10 @@ function UnitBlock({ unit }: { unit: LearningActivityUnit }) {
|
|||
</button>
|
||||
{open ? (
|
||||
<div className="space-y-3 border-t border-grayScale-100 px-3 py-3">
|
||||
{unit.modules.length === 0 ? (
|
||||
<p className="text-xs text-grayScale-400">No modules in this unit.</p>
|
||||
{chapter.lessons.length === 0 ? (
|
||||
<p className="text-xs text-grayScale-400">No lessons in this chapter.</p>
|
||||
) : (
|
||||
unit.modules.map((module) => <ModuleBlock key={module.id} module={module} />)
|
||||
chapter.lessons.map((lesson) => <LessonRow key={lesson.id} lesson={lesson} />)
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
|
@ -153,7 +114,7 @@ function UnitBlock({ unit }: { unit: LearningActivityUnit }) {
|
|||
|
||||
function CourseBlock({ course }: { course: LearningActivityCourse }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const children = course.units ?? [];
|
||||
const children = course.chapters ?? [];
|
||||
|
||||
return (
|
||||
<div className="rounded-xl border border-grayScale-200 bg-white">
|
||||
|
|
@ -182,7 +143,7 @@ function CourseBlock({ course }: { course: LearningActivityCourse }) {
|
|||
{children.length === 0 ? (
|
||||
<p className="text-xs text-grayScale-400">No content available.</p>
|
||||
) : (
|
||||
(course.units ?? []).map((unit) => <UnitBlock key={unit.id} unit={unit} />)
|
||||
(course.chapters ?? []).map((unit) => <ChapterBlock key={unit.id} chapter={unit} />)
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
|
@ -209,25 +170,12 @@ export function UserLearningActivitySection({
|
|||
error: string | null;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const catalogCourses = activity?.exam_prep.progress.catalog_courses ?? [];
|
||||
const catalogCourses = useMemo(() => activity?.learning.progress.courses ?? [], [activity]);
|
||||
|
||||
const [selectedCatalogCourseId, setSelectedCatalogCourseId] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (catalogCourses.length === 0) {
|
||||
setSelectedCatalogCourseId(null);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!selectedCatalogCourseId ||
|
||||
!catalogCourses.some((course) => course.id === selectedCatalogCourseId)
|
||||
) {
|
||||
setSelectedCatalogCourseId(catalogCourses[0].id);
|
||||
}
|
||||
}, [catalogCourses, selectedCatalogCourseId]);
|
||||
|
||||
const selectedCatalogCourse = useMemo(
|
||||
() => catalogCourses.find((course) => course.id === selectedCatalogCourseId) ?? null,
|
||||
() => catalogCourses.find((course) => course.id === selectedCatalogCourseId) ?? catalogCourses[0] ?? null,
|
||||
[catalogCourses, selectedCatalogCourseId],
|
||||
);
|
||||
|
||||
|
|
@ -247,7 +195,7 @@ export function UserLearningActivitySection({
|
|||
<div>
|
||||
<CardTitle className="text-base">Learning activity</CardTitle>
|
||||
<p className="mt-0.5 text-xs text-grayScale-500">
|
||||
Progress through catalog course → unit → module → lesson.
|
||||
Progress through course → unit → module → lesson.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -276,7 +224,7 @@ export function UserLearningActivitySection({
|
|||
{!loading && !error && activity ? (
|
||||
<>
|
||||
<div className="grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<Metric label="Catalog courses" value={catalogCourses.length} />
|
||||
<Metric label="Courses" value={catalogCourses.length} />
|
||||
<Metric
|
||||
label="Accessible courses"
|
||||
value={catalogCourses.filter((course) => course.access.is_accessible).length}
|
||||
|
|
@ -289,14 +237,14 @@ export function UserLearningActivitySection({
|
|||
|
||||
<div className="w-full sm:max-w-sm">
|
||||
<Select
|
||||
value={selectedCatalogCourseId ? String(selectedCatalogCourseId) : ""}
|
||||
value={selectedCatalogCourse ? String(selectedCatalogCourse.id) : ""}
|
||||
onChange={(e) =>
|
||||
setSelectedCatalogCourseId(e.target.value ? Number(e.target.value) : null)
|
||||
}
|
||||
disabled={catalogCourses.length === 0}
|
||||
>
|
||||
<option value="">
|
||||
{catalogCourses.length === 0 ? "No catalog courses" : "Select catalog course..."}
|
||||
{catalogCourses.length === 0 ? "No courses" : "Select course..."}
|
||||
</option>
|
||||
{catalogCourses.map((course) => (
|
||||
<option key={course.id} value={course.id}>
|
||||
|
|
@ -309,7 +257,7 @@ export function UserLearningActivitySection({
|
|||
{selectedCatalogCourse ? (
|
||||
<CourseBlock course={selectedCatalogCourse} />
|
||||
) : (
|
||||
<p className="py-6 text-center text-sm text-grayScale-400">No catalog course activity yet.</p>
|
||||
<p className="py-6 text-center text-sm text-grayScale-400">No course activity yet.</p>
|
||||
)}
|
||||
</>
|
||||
) : null}
|
||||
|
|
|
|||
|
|
@ -685,6 +685,7 @@ export interface GetPracticesListParams {
|
|||
}
|
||||
|
||||
export type PracticeParentKind =
|
||||
| "CHAPTER"
|
||||
| "COURSE"
|
||||
| "MODULE"
|
||||
| "LESSON"
|
||||
|
|
|
|||
|
|
@ -13,46 +13,31 @@ export interface LearningActivityAccess {
|
|||
|
||||
export interface LearningActivityLesson {
|
||||
id: number
|
||||
module_id: number
|
||||
chapter_id: number
|
||||
title: string
|
||||
access: LearningActivityAccess
|
||||
}
|
||||
|
||||
export interface LearningActivityModule {
|
||||
export interface LearningActivityChapter {
|
||||
id: number
|
||||
unit_id?: number
|
||||
course_id: number
|
||||
name: string
|
||||
access: LearningActivityAccess
|
||||
lessons: LearningActivityLesson[]
|
||||
}
|
||||
|
||||
export interface LearningActivityUnit {
|
||||
id: number
|
||||
catalog_course_id: number
|
||||
name: string
|
||||
access: LearningActivityAccess
|
||||
modules: LearningActivityModule[]
|
||||
}
|
||||
|
||||
export interface LearningActivityCourse {
|
||||
id: number
|
||||
catalog_course_id?: number
|
||||
name: string
|
||||
access: LearningActivityAccess
|
||||
modules?: LearningActivityModule[]
|
||||
units?: LearningActivityUnit[]
|
||||
chapters: LearningActivityChapter[]
|
||||
}
|
||||
|
||||
export interface UserLearningActivityData {
|
||||
user_id: number
|
||||
exam_prep: {
|
||||
progress: {
|
||||
catalog_courses: LearningActivityCourse[]
|
||||
}
|
||||
completions: {
|
||||
user_id: number
|
||||
catalog_courses: unknown[]
|
||||
}
|
||||
learning: {
|
||||
progress: { courses: LearningActivityCourse[] }
|
||||
completions: { user_id: number; courses: unknown[] }
|
||||
}
|
||||
recent_activity?: UserRecentActivityData
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user