Require exam category when creating exam prep catalog courses.
Add IELTS/Duolingo selection to the admin form so catalog course creation satisfies backend validation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
687eb964cc
commit
7b22d6d54c
|
|
@ -46,6 +46,7 @@ import { ContentListSearchFilterBar } from "./components/ContentListSearchFilter
|
||||||
import { ContentPageDescription } from "./components/ContentPageDescription";
|
import { ContentPageDescription } from "./components/ContentPageDescription";
|
||||||
import type {
|
import type {
|
||||||
ContentAccessTier,
|
ContentAccessTier,
|
||||||
|
ExamPrepCatalogCategory,
|
||||||
ExamPrepCatalogCourseItem,
|
ExamPrepCatalogCourseItem,
|
||||||
LearningProgramListItem,
|
LearningProgramListItem,
|
||||||
PracticePublishStatus,
|
PracticePublishStatus,
|
||||||
|
|
@ -69,6 +70,7 @@ type CourseListRow = {
|
||||||
id: number;
|
id: number;
|
||||||
programId?: number;
|
programId?: number;
|
||||||
programName?: string;
|
programName?: string;
|
||||||
|
category?: ExamPrepCatalogCategory | string | null;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
thumbnail?: string | null;
|
thumbnail?: string | null;
|
||||||
|
|
@ -88,6 +90,7 @@ export function ProgramDetailPage() {
|
||||||
const [createDescription, setCreateDescription] = useState("");
|
const [createDescription, setCreateDescription] = useState("");
|
||||||
const [createSortOrder, setCreateSortOrder] = useState("");
|
const [createSortOrder, setCreateSortOrder] = useState("");
|
||||||
const [createProgramId, setCreateProgramId] = useState("");
|
const [createProgramId, setCreateProgramId] = useState("");
|
||||||
|
const [createCategory, setCreateCategory] = useState<ExamPrepCatalogCategory | "">("");
|
||||||
const [createThumbnail, setCreateThumbnail] = useState("");
|
const [createThumbnail, setCreateThumbnail] = useState("");
|
||||||
const [createThumbnailFromUpload, setCreateThumbnailFromUpload] = useState(false);
|
const [createThumbnailFromUpload, setCreateThumbnailFromUpload] = useState(false);
|
||||||
const [creating, setCreating] = useState(false);
|
const [creating, setCreating] = useState(false);
|
||||||
|
|
@ -107,6 +110,7 @@ export function ProgramDetailPage() {
|
||||||
const [editingCourseId, setEditingCourseId] = useState<number | null>(null);
|
const [editingCourseId, setEditingCourseId] = useState<number | null>(null);
|
||||||
const [editName, setEditName] = useState("");
|
const [editName, setEditName] = useState("");
|
||||||
const [editDescription, setEditDescription] = useState("");
|
const [editDescription, setEditDescription] = useState("");
|
||||||
|
const [editCategory, setEditCategory] = useState<ExamPrepCatalogCategory | "">("");
|
||||||
const [editThumbnail, setEditThumbnail] = useState("");
|
const [editThumbnail, setEditThumbnail] = useState("");
|
||||||
const [editSortOrder, setEditSortOrder] = useState("1");
|
const [editSortOrder, setEditSortOrder] = useState("1");
|
||||||
const [savingEdit, setSavingEdit] = useState(false);
|
const [savingEdit, setSavingEdit] = useState(false);
|
||||||
|
|
@ -138,6 +142,7 @@ export function ProgramDetailPage() {
|
||||||
|
|
||||||
const mapExamPrepCourse = (row: ExamPrepCatalogCourseItem): CourseListRow => ({
|
const mapExamPrepCourse = (row: ExamPrepCatalogCourseItem): CourseListRow => ({
|
||||||
id: Number(row.id),
|
id: Number(row.id),
|
||||||
|
category: row.category ?? null,
|
||||||
name: row.name?.trim() || `Course ${row.id}`,
|
name: row.name?.trim() || `Course ${row.id}`,
|
||||||
description: row.description?.trim() || "",
|
description: row.description?.trim() || "",
|
||||||
thumbnail: row.thumbnail?.trim() || null,
|
thumbnail: row.thumbnail?.trim() || null,
|
||||||
|
|
@ -237,6 +242,7 @@ export function ProgramDetailPage() {
|
||||||
id: course.id,
|
id: course.id,
|
||||||
programId: course.programId,
|
programId: course.programId,
|
||||||
programName: course.programName,
|
programName: course.programName,
|
||||||
|
category: course.category,
|
||||||
name: course.name,
|
name: course.name,
|
||||||
description: course.description,
|
description: course.description,
|
||||||
units_count: course.unitsCount,
|
units_count: course.unitsCount,
|
||||||
|
|
@ -384,6 +390,7 @@ export function ProgramDetailPage() {
|
||||||
setCreateDescription("");
|
setCreateDescription("");
|
||||||
setCreateSortOrder("");
|
setCreateSortOrder("");
|
||||||
setCreateProgramId("");
|
setCreateProgramId("");
|
||||||
|
setCreateCategory("");
|
||||||
setCreateThumbnail("");
|
setCreateThumbnail("");
|
||||||
setCreateThumbnailFromUpload(false);
|
setCreateThumbnailFromUpload(false);
|
||||||
};
|
};
|
||||||
|
|
@ -412,9 +419,14 @@ export function ProgramDetailPage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isProficiency) {
|
if (isProficiency) {
|
||||||
|
if (createCategory !== "IELTS" && createCategory !== "DUOLINGO") {
|
||||||
|
toast.error("Please select an exam category");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const response = await createExamPrepCatalogCourse({
|
const response = await createExamPrepCatalogCourse({
|
||||||
name,
|
name,
|
||||||
description: null,
|
description: null,
|
||||||
|
category: createCategory,
|
||||||
thumbnail: thumbnailToSend,
|
thumbnail: thumbnailToSend,
|
||||||
});
|
});
|
||||||
const row = response.data?.data;
|
const row = response.data?.data;
|
||||||
|
|
@ -466,6 +478,11 @@ export function ProgramDetailPage() {
|
||||||
setEditingCourseId(idNum);
|
setEditingCourseId(idNum);
|
||||||
setEditName(String(course.name ?? ""));
|
setEditName(String(course.name ?? ""));
|
||||||
setEditDescription(String(course.description ?? ""));
|
setEditDescription(String(course.description ?? ""));
|
||||||
|
setEditCategory(
|
||||||
|
course.category === "IELTS" || course.category === "DUOLINGO"
|
||||||
|
? course.category
|
||||||
|
: "",
|
||||||
|
);
|
||||||
setEditThumbnail(String(course.thumbnail ?? ""));
|
setEditThumbnail(String(course.thumbnail ?? ""));
|
||||||
setEditSortOrder(String(course.sort_order ?? 1));
|
setEditSortOrder(String(course.sort_order ?? 1));
|
||||||
};
|
};
|
||||||
|
|
@ -475,6 +492,7 @@ export function ProgramDetailPage() {
|
||||||
setEditingCourseId(null);
|
setEditingCourseId(null);
|
||||||
setEditName("");
|
setEditName("");
|
||||||
setEditDescription("");
|
setEditDescription("");
|
||||||
|
setEditCategory("");
|
||||||
setEditThumbnail("");
|
setEditThumbnail("");
|
||||||
setEditSortOrder("1");
|
setEditSortOrder("1");
|
||||||
};
|
};
|
||||||
|
|
@ -527,9 +545,14 @@ export function ProgramDetailPage() {
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (isProficiency) {
|
if (isProficiency) {
|
||||||
|
if (editCategory !== "IELTS" && editCategory !== "DUOLINGO") {
|
||||||
|
toast.error("Please select an exam category");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const response = await updateExamPrepCatalogCourse(editingCourseId, {
|
const response = await updateExamPrepCatalogCourse(editingCourseId, {
|
||||||
name,
|
name,
|
||||||
description: preservedDescription,
|
description: preservedDescription,
|
||||||
|
category: editCategory,
|
||||||
thumbnail: minioThumbnail || null,
|
thumbnail: minioThumbnail || null,
|
||||||
sort_order: sortOrderNum,
|
sort_order: sortOrderNum,
|
||||||
});
|
});
|
||||||
|
|
@ -539,6 +562,7 @@ export function ProgramDetailPage() {
|
||||||
course.id === editingCourseId
|
course.id === editingCourseId
|
||||||
? {
|
? {
|
||||||
...course,
|
...course,
|
||||||
|
category: row?.category ?? editCategory,
|
||||||
name: row?.name ?? name,
|
name: row?.name ?? name,
|
||||||
description:
|
description:
|
||||||
row?.description?.trim() || preservedDescription || "",
|
row?.description?.trim() || preservedDescription || "",
|
||||||
|
|
@ -674,6 +698,25 @@ export function ProgramDetailPage() {
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="min-h-0 flex-1 space-y-8 overflow-y-auto p-8">
|
<div className="min-h-0 flex-1 space-y-8 overflow-y-auto p-8">
|
||||||
|
{isProficiency ? (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<label className="text-[15px] text-grayScale-800">
|
||||||
|
Exam Category
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={createCategory}
|
||||||
|
onChange={(e) =>
|
||||||
|
setCreateCategory(e.target.value as ExamPrepCatalogCategory | "")
|
||||||
|
}
|
||||||
|
className="h-12 w-full rounded-[8px] border border-grayScale-400 bg-white px-4 text-[15px] text-grayScale-900 focus:outline-none focus:ring-2 focus:ring-brand-500/20"
|
||||||
|
disabled={creating || uploadingThumbnail}
|
||||||
|
>
|
||||||
|
<option value="">Select IELTS or Duolingo…</option>
|
||||||
|
<option value="IELTS">IELTS</option>
|
||||||
|
<option value="DUOLINGO">Duolingo</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
{isSkillBased ? (
|
{isSkillBased ? (
|
||||||
<>
|
<>
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
|
|
@ -979,6 +1022,11 @@ export function ProgramDetailPage() {
|
||||||
<SearchHighlight text={course.programName} query={listSearch} />
|
<SearchHighlight text={course.programName} query={listSearch} />
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
|
{isProficiency && course.category ? (
|
||||||
|
<p className="text-[12px] font-semibold uppercase tracking-wide text-brand-500">
|
||||||
|
{course.category === "DUOLINGO" ? "Duolingo" : course.category}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
<h3 className="text-[18px] font-medium text-grayScale-900">
|
<h3 className="text-[18px] font-medium text-grayScale-900">
|
||||||
<SearchHighlight text={course.name} query={listSearch} />
|
<SearchHighlight text={course.name} query={listSearch} />
|
||||||
</h3>
|
</h3>
|
||||||
|
|
@ -1073,6 +1121,26 @@ export function ProgramDetailPage() {
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
{isProficiency ? (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<label className="text-[15px] text-grayScale-800">
|
||||||
|
Exam Category
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={editCategory}
|
||||||
|
onChange={(e) =>
|
||||||
|
setEditCategory(e.target.value as ExamPrepCatalogCategory | "")
|
||||||
|
}
|
||||||
|
className="h-12 w-full rounded-[8px] border border-grayScale-400 bg-white px-4 text-[15px] text-grayScale-900 focus:outline-none focus:ring-2 focus:ring-brand-500/20"
|
||||||
|
disabled={savingEdit || uploadingEditThumbnail}
|
||||||
|
>
|
||||||
|
<option value="">Select IELTS or Duolingo…</option>
|
||||||
|
<option value="IELTS">IELTS</option>
|
||||||
|
<option value="DUOLINGO">Duolingo</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<label className="text-[15px] text-grayScale-800">Sort Order</label>
|
<label className="text-[15px] text-grayScale-800">Sort Order</label>
|
||||||
<Input
|
<Input
|
||||||
|
|
|
||||||
|
|
@ -159,10 +159,13 @@ export interface CreateProgramCourseResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Exam prep catalog course row (e.g. IELTS / DET cards) */
|
/** Exam prep catalog course row (e.g. IELTS / DET cards) */
|
||||||
|
export type ExamPrepCatalogCategory = "IELTS" | "DUOLINGO"
|
||||||
|
|
||||||
export interface ExamPrepCatalogCourseItem {
|
export interface ExamPrepCatalogCourseItem {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
description?: string | null
|
description?: string | null
|
||||||
|
category?: ExamPrepCatalogCategory | string | null
|
||||||
thumbnail?: string | null
|
thumbnail?: string | null
|
||||||
sort_order?: number
|
sort_order?: number
|
||||||
units_count?: number
|
units_count?: number
|
||||||
|
|
@ -177,6 +180,7 @@ export interface ExamPrepCatalogCourseItem {
|
||||||
export interface CreateExamPrepCatalogCourseRequest {
|
export interface CreateExamPrepCatalogCourseRequest {
|
||||||
name: string
|
name: string
|
||||||
description?: string | null
|
description?: string | null
|
||||||
|
category: ExamPrepCatalogCategory
|
||||||
thumbnail?: string | null
|
thumbnail?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,6 +208,7 @@ export interface GetExamPrepCatalogCoursesResponse {
|
||||||
export interface UpdateExamPrepCatalogCourseRequest {
|
export interface UpdateExamPrepCatalogCourseRequest {
|
||||||
name: string
|
name: string
|
||||||
description?: string | null
|
description?: string | null
|
||||||
|
category?: ExamPrepCatalogCategory
|
||||||
thumbnail?: string | null
|
thumbnail?: string | null
|
||||||
sort_order: number
|
sort_order: number
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user