Support nullable-parent practice shells for LMS and exam prep.

Add exam-prep create/list/parents APIs, unlinked attach flow, optional placement on create, and exam-prep location editing with catalog course, unit, and lesson parent kinds.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Yared Yemane 2026-06-29 08:14:43 -07:00
parent 63fb170a8f
commit a8243e3ae4
14 changed files with 184 additions and 47 deletions

View File

@ -105,7 +105,10 @@ import type {
CreateExamPrepCatalogCoursePracticeResponse, CreateExamPrepCatalogCoursePracticeResponse,
CreateExamPrepUnitPracticeRequest, CreateExamPrepUnitPracticeRequest,
CreateExamPrepUnitPracticeResponse, CreateExamPrepUnitPracticeResponse,
CreateExamPrepPracticeRequest,
CreateExamPrepPracticeResponse,
GetExamPrepUnitPracticesResponse, GetExamPrepUnitPracticesResponse,
GetExamPrepPracticesListResponse,
GetExamPrepCatalogCoursePracticesResponse, GetExamPrepCatalogCoursePracticesResponse,
GetExamPrepLessonPracticesResponse, GetExamPrepLessonPracticesResponse,
GetExamPrepModuleLessonsResponse, GetExamPrepModuleLessonsResponse,
@ -711,6 +714,24 @@ export const getExamPrepLessonPractices = (
{ params }, { params },
) )
/** POST /exam-prep/practices — create practice with optional parents. */
export const createExamPrepPractice = (data: CreateExamPrepPracticeRequest) =>
http.post<CreateExamPrepPracticeResponse>("/exam-prep/practices", data)
/** GET /exam-prep/practices — list practices (supports unlinked_only). */
export const getExamPrepPractices = (params?: GetPracticesListParams) =>
http.get<GetExamPrepPracticesListResponse>("/exam-prep/practices", { params })
/** PUT /exam-prep/practices/:id/parents — replace all parent links. */
export const updateExamPrepPracticeParents = (
practiceId: number,
data: UpdatePracticeParentsRequest,
) =>
http.put<UpdatePracticeParentsResponse>(
`/exam-prep/practices/${practiceId}/parents`,
data,
)
/** DELETE /exam-prep/practices/:practiceId */ /** DELETE /exam-prep/practices/:practiceId */
export const deleteExamPrepPractice = (practiceId: number) => export const deleteExamPrepPractice = (practiceId: number) =>
http.delete<{ message: string; success: boolean; status_code: number; metadata: unknown }>( http.delete<{ message: string; success: boolean; status_code: number; metadata: unknown }>(

View File

@ -1,4 +1,7 @@
import { updatePracticeParents } from "../api/courses.api" import {
updateExamPrepPracticeParents,
updatePracticeParents,
} from "../api/courses.api"
import type { ParentContextPractice, PracticeParent } from "../types/course.types" import type { ParentContextPractice, PracticeParent } from "../types/course.types"
import { dedupeParents, parentsFromPractice } from "./practiceParents" import { dedupeParents, parentsFromPractice } from "./practiceParents"
@ -22,11 +25,15 @@ export function mergedParentsForAttach(
export async function attachPracticeToParent( export async function attachPracticeToParent(
practice: ParentContextPractice, practice: ParentContextPractice,
newParent: PracticeParent, newParent: PracticeParent,
options?: { isExamPrep?: boolean },
): Promise<void> { ): Promise<void> {
if (practiceAlreadyLinkedToParent(practice, newParent)) { if (practiceAlreadyLinkedToParent(practice, newParent)) {
throw new Error("This practice is already linked to the selected location.") throw new Error("This practice is already linked to the selected location.")
} }
await updatePracticeParents(practice.id, { const parents = mergedParentsForAttach(practice, newParent)
parents: mergedParentsForAttach(practice, newParent), if (options?.isExamPrep) {
}) await updateExamPrepPracticeParents(practice.id, { parents })
return
}
await updatePracticeParents(practice.id, { parents })
} }

View File

@ -1,17 +1,23 @@
import { getPractices } from "../api/courses.api" import { getExamPrepPractices, getPractices } from "../api/courses.api"
import type { ParentContextPractice } from "../types/course.types" import type { ParentContextPractice } from "../types/course.types"
const FETCH_PAGE_SIZE = 100 const FETCH_PAGE_SIZE = 100
export type FetchAllPracticesOptions = {
isExamPrep?: boolean
}
export async function fetchAllPractices( export async function fetchAllPractices(
unlinkedOnly: boolean, unlinkedOnly: boolean,
options?: FetchAllPracticesOptions,
): Promise<ParentContextPractice[]> { ): Promise<ParentContextPractice[]> {
const listPractices = options?.isExamPrep ? getExamPrepPractices : getPractices
const all: ParentContextPractice[] = [] const all: ParentContextPractice[] = []
let offset = 0 let offset = 0
let totalCount = Number.POSITIVE_INFINITY let totalCount = Number.POSITIVE_INFINITY
while (offset < totalCount) { while (offset < totalCount) {
const res = await getPractices({ const res = await listPractices({
limit: FETCH_PAGE_SIZE, limit: FETCH_PAGE_SIZE,
offset, offset,
unlinked_only: unlinkedOnly, unlinked_only: unlinkedOnly,

View File

@ -3,6 +3,7 @@ import {
addQuestionToSet, addQuestionToSet,
createExamPrepCatalogCoursePractice, createExamPrepCatalogCoursePractice,
createExamPrepLessonPractice, createExamPrepLessonPractice,
createExamPrepPractice,
createExamPrepUnitPractice, createExamPrepUnitPractice,
createParentLinkedPractice, createParentLinkedPractice,
createQuestion, createQuestion,
@ -50,6 +51,8 @@ export interface PracticeCreationInput {
examPrepCatalogCourseId?: number examPrepCatalogCourseId?: number
/** English proficiency unit practices use POST /exam-prep/units/:id/practices. */ /** English proficiency unit practices use POST /exam-prep/units/:id/practices. */
examPrepUnitId?: number examPrepUnitId?: number
/** When true, fall back to POST /exam-prep/practices when no nested route applies. */
isExamPrep?: boolean
} }
function extractCreatedResourceId( function extractCreatedResourceId(
@ -216,6 +219,17 @@ export async function executePracticeCreation(
quick_tips: opts.quickTips.trim(), quick_tips: opts.quickTips.trim(),
publish_status: opts.status, publish_status: opts.status,
}) })
: opts.isExamPrep
? await createExamPrepPractice({
parents: createParents,
title: opts.practiceTitle.trim(),
story_description: opts.storyDescription.trim(),
story_image: opts.storyImage.trim(),
persona_id: opts.personaId,
question_set_id: setId,
quick_tips: opts.quickTips.trim(),
publish_status: opts.status,
})
: await createParentLinkedPractice({ : await createParentLinkedPractice({
parents: createParents, parents: createParents,
title: opts.practiceTitle.trim(), title: opts.practiceTitle.trim(),

View File

@ -1,5 +1,6 @@
import { import {
updateExamPrepPracticeFull, updateExamPrepPracticeFull,
updateExamPrepPracticeParents,
updateLearnEnglishPracticeFull, updateLearnEnglishPracticeFull,
updatePracticeParents, updatePracticeParents,
} from "../api/courses.api" } from "../api/courses.api"
@ -44,6 +45,11 @@ export async function executePracticeUpdate(
if (opts.isExamPrep) { if (opts.isExamPrep) {
await updateExamPrepPracticeFull(opts.practiceId, payload) await updateExamPrepPracticeFull(opts.practiceId, payload)
if (opts.parentsChanged && opts.parents) {
await updateExamPrepPracticeParents(opts.practiceId, {
parents: dedupeParents(opts.parents),
})
}
return return
} }

View File

@ -110,9 +110,16 @@ export function formatPracticeParentLabel(parent: PracticeParent): string {
} }
} }
export function formatPracticeParentsSummary(parents: PracticeParent[]): string { export function formatPracticeParentsSummary(
parents: PracticeParent[],
options?: { isExamPrep?: boolean },
): string {
const list = dedupeParents(parents) const list = dedupeParents(parents)
if (list.length === 0) return "Not attached to any course, module, or lesson" if (list.length === 0) {
return options?.isExamPrep
? "Not attached to any catalog course, unit, or lesson"
: "Not attached to any course, module, or lesson"
}
return list.map(formatPracticeParentLabel).join(" · ") return list.map(formatPracticeParentLabel).join(" · ")
} }

View File

@ -344,7 +344,7 @@ export function AddPracticeFlow() {
: formData.parents, : formData.parents,
); );
const parentsErr = validatePracticeParents(parents, { const parentsErr = validatePracticeParents(parents, {
required: !isFromQuestionType, required: !isFromQuestionType && !isExamPrep,
}); });
if (parentsErr) { if (parentsErr) {
toast.error("Check practice locations", { description: parentsErr }); toast.error("Check practice locations", { description: parentsErr });
@ -447,6 +447,7 @@ export function AddPracticeFlow() {
? parentContext!.id ? parentContext!.id
: undefined, : undefined,
examPrepUnitId: useExamPrepUnitApi ? parentContext!.id : undefined, examPrepUnitId: useExamPrepUnitApi ? parentContext!.id : undefined,
isExamPrep,
status, status,
questionSetTitle: isLearnEnglishLessonPractice questionSetTitle: isLearnEnglishLessonPractice
? lessonDefaultTitle ? lessonDefaultTitle
@ -504,6 +505,10 @@ export function AddPracticeFlow() {
? dedupeParents(formData.parents).length > 0 ? dedupeParents(formData.parents).length > 0
? "Your practice is saved with the selected locations. You can edit questions or attach more locations anytime." ? "Your practice is saved with the selected locations. You can edit questions or attach more locations anytime."
: "Your practice is saved as a draft shell. Attach it to courses, modules, or lessons when you are ready." : "Your practice is saved as a draft shell. Attach it to courses, modules, or lessons when you are ready."
: isExamPrep
? parentContext
? "Your speaking practice is saved for the linked catalog course, unit, or lesson."
: "Your practice is saved as a draft shell. Attach it to catalog courses, units, or lessons when you are ready."
: lessonId : lessonId
? "Your speaking practice is saved and linked to this lesson’s question set." ? "Your speaking practice is saved and linked to this lesson’s question set."
: "Your speaking practice is saved for the linked course or module."} : "Your speaking practice is saved for the linked course or module."}
@ -697,9 +702,9 @@ export function AddPracticeFlow() {
prevStep={prevStep} prevStep={prevStep}
onEditContext={() => setCurrentStep(1)} onEditContext={() => setCurrentStep(1)}
onEditQuestions={() => setCurrentStep(3)} onEditQuestions={() => setCurrentStep(3)}
parentSummary={parentSummary} parentSummary={parentSummary ?? (isExamPrep ? formatPracticeParentsSummary([], { isExamPrep: true }) : null)}
typeDefinitions={typeDefinitions} typeDefinitions={typeDefinitions}
canPublish={parentContext !== null} canPublish={isExamPrep || parentContext !== null}
submitting={submitting} submitting={submitting}
onSaveDraft={() => void submitPractice("DRAFT")} onSaveDraft={() => void submitPractice("DRAFT")}
onPublish={() => void submitPractice("PUBLISHED")} onPublish={() => void submitPractice("PUBLISHED")}
@ -751,6 +756,15 @@ export function AddPracticeFlow() {
</p> </p>
</div> </div>
) : null} ) : null}
{isExamPrep && !parentContext && !lessonId ? (
<div className="mt-4 rounded-xl border border-amber-200 bg-amber-50/80 px-4 py-3 text-sm text-amber-950">
<p className="font-semibold text-amber-900">No placement yet</p>
<p className="mt-1 text-amber-900/90">
This practice will be created without catalog course, unit, or lesson links. Attach
locations later from the attach-practice flow or practice editor.
</p>
</div>
) : null}
{lessonId ? ( {lessonId ? (
<div className="mt-4 rounded-xl border border-violet-200 bg-violet-50/80 px-4 py-3 text-sm text-violet-950"> <div className="mt-4 rounded-xl border border-violet-200 bg-violet-50/80 px-4 py-3 text-sm text-violet-950">
<p className="font-semibold text-violet-900">Lesson practice</p> <p className="font-semibold text-violet-900">Lesson practice</p>

View File

@ -404,6 +404,12 @@ export function EditPracticeFlow() {
toast.error("Check practice locations", { description: parentsErr }); toast.error("Check practice locations", { description: parentsErr });
return; return;
} }
} else {
const parentsErr = validatePracticeParents(formData.parents, { required: false });
if (parentsErr) {
toast.error("Check practice locations", { description: parentsErr });
return;
}
} }
setSubmitting(true); setSubmitting(true);
@ -423,16 +429,15 @@ export function EditPracticeFlow() {
isLearnEnglishLessonPractice, isLearnEnglishLessonPractice,
lessonDefaultTitle, lessonDefaultTitle,
parents: dedupeParents(formData.parents), parents: dedupeParents(formData.parents),
parentsChanged: parentsChanged: !practiceParentsEqual(
!isExamPrep && formData.parents,
!practiceParentsEqual(formData.parents, initialParentsRef.current), initialParentsRef.current,
),
}); });
toast.success( toast.success(
status === "PUBLISHED" ? "Practice updated and published" : "Practice saved as draft", status === "PUBLISHED" ? "Practice updated and published" : "Practice saved as draft",
); );
if (!isExamPrep) {
initialParentsRef.current = dedupeParents(formData.parents); initialParentsRef.current = dedupeParents(formData.parents);
}
setIsSaved(true); setIsSaved(true);
} catch (e) { } catch (e) {
toast.error("Could not update practice", { toast.error("Could not update practice", {
@ -511,12 +516,15 @@ export function EditPracticeFlow() {
const reviewParentSummary = const reviewParentSummary =
formData.parents.length > 0 formData.parents.length > 0
? formatPracticeParentsSummary(formData.parents) ? formatPracticeParentsSummary(formData.parents, { isExamPrep })
: parentSummary; : parentSummary;
const renderStep = () => { const renderStep = () => {
const useContextStep = const useContextStep =
isModuleContext || isCourseContext || isLessonContext; isModuleContext ||
isCourseContext ||
isLessonContext ||
isUnitContext;
if (useContextStep) { if (useContextStep) {
switch (currentStep) { switch (currentStep) {
@ -530,7 +538,10 @@ export function EditPracticeFlow() {
isLessonPractice={isLearnEnglishLessonPractice} isLessonPractice={isLearnEnglishLessonPractice}
lessonTitle={lessonTitleDisplay} lessonTitle={lessonTitleDisplay}
parentSummary={reviewParentSummary} parentSummary={reviewParentSummary}
showParentsEditor={!isExamPrep} showParentsEditor={!isLearnEnglishLessonPractice}
isExamPrepParents={isExamPrep}
parentsOptional={isExamPrep}
parentsCollapsedDefault={isExamPrep}
/> />
); );
case 2: case 2:

View File

@ -211,7 +211,7 @@ export function LinkExistingPracticeFlow() {
if (!selectedPractice) return if (!selectedPractice) return
setSubmitting(true) setSubmitting(true)
try { try {
await attachPracticeToParent(selectedPractice, targetParent) await attachPracticeToParent(selectedPractice, targetParent, { isExamPrep })
toast.success("Practice linked successfully") toast.success("Practice linked successfully")
setIsComplete(true) setIsComplete(true)
} catch (e) { } catch (e) {
@ -298,6 +298,7 @@ export function LinkExistingPracticeFlow() {
<div className="mx-auto max-w-4xl"> <div className="mx-auto max-w-4xl">
{currentStep === 1 ? ( {currentStep === 1 ? (
<SelectPracticeToAttachStep <SelectPracticeToAttachStep
isExamPrep={isExamPrep}
targetParent={targetParent} targetParent={targetParent}
targetSummary={targetSummary} targetSummary={targetSummary}
selectedPracticeId={selectedPractice?.id ?? null} selectedPracticeId={selectedPractice?.id ?? null}

View File

@ -67,8 +67,6 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
const [pendingSaveStatus, setPendingSaveStatus] = const [pendingSaveStatus, setPendingSaveStatus] =
useState<PracticePublishStatus | null>(null) useState<PracticePublishStatus | null>(null)
const canUseWizard = parent != null
useEffect(() => { useEffect(() => {
if (step === 4 && setTitle.trim() && !practiceTitle.trim()) { if (step === 4 && setTitle.trim() && !practiceTitle.trim()) {
setPracticeTitle(setTitle.trim()) setPracticeTitle(setTitle.trim())
@ -181,7 +179,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
} }
const handleStep4 = async (status: PracticePublishStatus) => { const handleStep4 = async (status: PracticePublishStatus) => {
if (!parent || questionSetId == null) return if (questionSetId == null) return
if (!practiceTitle.trim() || !storyDescription.trim() || !storyImage.trim()) { if (!practiceTitle.trim() || !storyDescription.trim() || !storyImage.trim()) {
toast.error("Title, story description, and story image are required") toast.error("Title, story description, and story image are required")
return return
@ -190,7 +188,9 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
setSaving(true) setSaving(true)
try { try {
await createParentLinkedPractice({ await createParentLinkedPractice({
parents: [{ parent_kind: parent.kind, parent_id: parent.id }], parents: parent
? [{ parent_kind: parent.kind, parent_id: parent.id }]
: null,
title: practiceTitle.trim(), title: practiceTitle.trim(),
story_description: storyDescription.trim(), story_description: storyDescription.trim(),
story_image: storyImage.trim(), story_image: storyImage.trim(),
@ -218,7 +218,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
<CardTitle className="text-base font-semibold text-grayScale-800">Create a new practice</CardTitle> <CardTitle className="text-base font-semibold text-grayScale-800">Create a new practice</CardTitle>
<p className="text-sm font-normal text-grayScale-500"> <p className="text-sm font-normal text-grayScale-500">
Four steps: create a question set, add audio questions, attach them, then set the practice Four steps: create a question set, add audio questions, attach them, then set the practice
story. Select the course, module, or lesson above first. story. Locations are optional — attach a course, module, or lesson later if needed.
</p> </p>
<ol className="mt-4 flex flex-wrap gap-2"> <ol className="mt-4 flex flex-wrap gap-2">
{STEPS.map((s) => { {STEPS.map((s) => {
@ -242,15 +242,14 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
</ol> </ol>
</CardHeader> </CardHeader>
<CardContent className="pt-5"> <CardContent className="pt-5">
{!canUseWizard && ( {!parent ? (
<p className="rounded-xl border border-amber-200 bg-amber-50/80 px-4 py-3 text-sm text-amber-900"> <p className="mb-4 rounded-xl border border-amber-200 bg-amber-50/80 px-4 py-3 text-sm text-amber-900">
Choose a program, course, and the target (course / module / lesson) in the &quot;Look up No placement selected — the practice shell will be created unlinked. Attach it to a
practice&quot; section, then return here. The practice is created for the same selection course, module, or lesson later.
(course id, module id, or lesson id).
</p> </p>
)} ) : null}
{canUseWizard && step === 1 && ( {step === 1 && (
<div className="space-y-4"> <div className="space-y-4">
<div> <div>
<p className="mb-1.5 text-xs font-semibold uppercase tracking-wider text-grayScale-500"> <p className="mb-1.5 text-xs font-semibold uppercase tracking-wider text-grayScale-500">
@ -273,7 +272,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
</div> </div>
)} )}
{canUseWizard && step === 2 && ( {step === 2 && (
<div className="space-y-4"> <div className="space-y-4">
<p className="text-sm text-grayScale-600"> <p className="text-sm text-grayScale-600">
Add one or more audio questions to question set #{questionSetId}. Add one or more audio questions to question set #{questionSetId}.
@ -382,7 +381,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
</div> </div>
)} )}
{canUseWizard && step === 3 && ( {step === 3 && (
<div className="space-y-4"> <div className="space-y-4">
<p className="text-sm text-grayScale-600"> <p className="text-sm text-grayScale-600">
Confirm the order of questions in the set. Confirm the order of questions in the set.
@ -414,7 +413,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
</div> </div>
)} )}
{canUseWizard && step === 4 && parent && ( {step === 4 && (
<div className="space-y-4"> <div className="space-y-4">
<p className="text-sm text-grayScale-600"> <p className="text-sm text-grayScale-600">
Linked to {parent.kind.toLowerCase()} #{parent.id} · question set #{questionSetId} Linked to {parent.kind.toLowerCase()} #{parent.id} · question set #{questionSetId}

View File

@ -31,6 +31,8 @@ interface ContextStepProps {
lockedParentKey?: string | null; lockedParentKey?: string | null;
/** When true, locations are optional and the picker can stay collapsed. */ /** When true, locations are optional and the picker can stay collapsed. */
parentsOptional?: boolean; parentsOptional?: boolean;
/** Use exam-prep parent kinds in the locations editor. */
isExamPrepParents?: boolean;
parentsCollapsedDefault?: boolean; parentsCollapsedDefault?: boolean;
} }
@ -49,6 +51,7 @@ export function ContextStep({
lockedParentKey = null, lockedParentKey = null,
parentsOptional = false, parentsOptional = false,
parentsCollapsedDefault = false, parentsCollapsedDefault = false,
isExamPrepParents = false,
}: ContextStepProps) { }: ContextStepProps) {
const storyFileRef = useRef<HTMLInputElement>(null); const storyFileRef = useRef<HTMLInputElement>(null);
const [uploadingStory, setUploadingStory] = useState(false); const [uploadingStory, setUploadingStory] = useState(false);
@ -133,7 +136,10 @@ export function ContextStep({
<div className="rounded-xl border border-amber-200 bg-amber-50/80 px-4 py-3 text-sm text-amber-950"> <div className="rounded-xl border border-amber-200 bg-amber-50/80 px-4 py-3 text-sm text-amber-950">
<p className="font-semibold text-amber-900">Locations optional</p> <p className="font-semibold text-amber-900">Locations optional</p>
<p className="mt-1 text-amber-900/90"> <p className="mt-1 text-amber-900/90">
You can create this practice now and attach it to courses, modules, or lessons You can create this practice now and attach it to{" "}
{isExamPrepParents
? "catalog courses, units, or lessons"
: "courses, modules, or lessons"}{" "}
later from the practice editor. later from the practice editor.
</p> </p>
</div> </div>
@ -162,6 +168,7 @@ export function ContextStep({
parents={formData.parents ?? []} parents={formData.parents ?? []}
lockedParentKey={lockedParentKey} lockedParentKey={lockedParentKey}
optional optional
isExamPrep={isExamPrepParents}
onChange={(parents) => setFormData({ ...formData, parents })} onChange={(parents) => setFormData({ ...formData, parents })}
/> />
) : null} ) : null}
@ -170,6 +177,7 @@ export function ContextStep({
<PracticeParentsField <PracticeParentsField
parents={formData.parents ?? []} parents={formData.parents ?? []}
lockedParentKey={lockedParentKey} lockedParentKey={lockedParentKey}
isExamPrep={isExamPrepParents}
onChange={(parents) => setFormData({ ...formData, parents })} onChange={(parents) => setFormData({ ...formData, parents })}
/> />
) )

View File

@ -4,12 +4,18 @@ import { Input } from "../../../../components/ui/input"
import type { PracticeParent, PracticeParentKind } from "../../../../types/course.types" import type { PracticeParent, PracticeParentKind } from "../../../../types/course.types"
import { dedupeParents, newParentRow } from "../../../../lib/practiceParents" import { dedupeParents, newParentRow } from "../../../../lib/practiceParents"
const KIND_OPTIONS: { value: PracticeParentKind; label: string }[] = [ const LMS_KIND_OPTIONS: { value: PracticeParentKind; label: string }[] = [
{ value: "COURSE", label: "Course" }, { value: "COURSE", label: "Course" },
{ value: "MODULE", label: "Module" }, { value: "MODULE", label: "Module" },
{ value: "LESSON", label: "Lesson" }, { value: "LESSON", label: "Lesson" },
] ]
const EXAM_PREP_KIND_OPTIONS: { value: PracticeParentKind; label: string }[] = [
{ value: "CATALOG_COURSE", label: "Catalog course" },
{ value: "UNIT", label: "Unit" },
{ value: "LESSON", label: "Lesson" },
]
interface PracticeParentsFieldProps { interface PracticeParentsFieldProps {
parents: PracticeParent[] parents: PracticeParent[]
onChange: (parents: PracticeParent[]) => void onChange: (parents: PracticeParent[]) => void
@ -18,6 +24,8 @@ interface PracticeParentsFieldProps {
lockedParentKey?: string | null lockedParentKey?: string | null
/** When true, all rows can be cleared (unlinked practice). */ /** When true, all rows can be cleared (unlinked practice). */
optional?: boolean optional?: boolean
/** Use exam-prep parent kinds instead of Learn English. */
isExamPrep?: boolean
} }
function parentKey(parent: PracticeParent): string { function parentKey(parent: PracticeParent): string {
@ -30,8 +38,10 @@ export function PracticeParentsField({
disabled = false, disabled = false,
lockedParentKey = null, lockedParentKey = null,
optional = false, optional = false,
isExamPrep = false,
}: PracticeParentsFieldProps) { }: PracticeParentsFieldProps) {
const rows = parents.length > 0 ? parents : [newParentRow()] const kindOptions = isExamPrep ? EXAM_PREP_KIND_OPTIONS : LMS_KIND_OPTIONS
const rows = parents.length > 0 ? parents : [newParentRow(isExamPrep ? "CATALOG_COURSE" : "LESSON")]
const updateRow = (index: number, patch: Partial<PracticeParent>) => { const updateRow = (index: number, patch: Partial<PracticeParent>) => {
const next = rows.map((row, i) => (i === index ? { ...row, ...patch } : row)) const next = rows.map((row, i) => (i === index ? { ...row, ...patch } : row))
@ -58,7 +68,11 @@ export function PracticeParentsField({
<p className="text-sm font-semibold text-grayScale-800">Attached locations</p> <p className="text-sm font-semibold text-grayScale-800">Attached locations</p>
<p className="text-xs text-grayScale-500"> <p className="text-xs text-grayScale-500">
{optional {optional
? "Attach now or leave empty and link this practice later." ? 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 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. Each location can only have one practice."} : "Link this practice to one or more courses, modules, or lessons. Each location can only have one practice."}
</p> </p>
</div> </div>
@ -80,7 +94,7 @@ export function PracticeParentsField({
} }
className="h-9 rounded-[8px] border border-grayScale-200 bg-white px-2.5 text-sm font-medium text-grayScale-700 focus:outline-none focus:ring-2 focus:ring-brand-200" className="h-9 rounded-[8px] border border-grayScale-200 bg-white px-2.5 text-sm font-medium text-grayScale-700 focus:outline-none focus:ring-2 focus:ring-brand-200"
> >
{KIND_OPTIONS.map((opt) => ( {kindOptions.map((opt) => (
<option key={opt.value} value={opt.value}> <option key={opt.value} value={opt.value}>
{opt.label} {opt.label}
</option> </option>

View File

@ -22,6 +22,7 @@ interface SelectPracticeToAttachStepProps {
nextStep: () => void nextStep: () => void
onCancel: () => void onCancel: () => void
variant?: "page" | "dialog" variant?: "page" | "dialog"
isExamPrep?: boolean
} }
function publishStatusClass(status?: string | null): string { function publishStatusClass(status?: string | null): string {
@ -42,7 +43,7 @@ function matchesPracticeSearch(
practice.story_description ?? "", practice.story_description ?? "",
String(practice.id), String(practice.id),
String(practice.question_set_id), String(practice.question_set_id),
formatPracticeParentsSummary(practice.parents ?? []), formatPracticeParentsSummary(practice.parents ?? [], { isExamPrep }),
] ]
.join(" ") .join(" ")
.toLowerCase() .toLowerCase()
@ -57,6 +58,7 @@ export function SelectPracticeToAttachStep({
nextStep, nextStep,
onCancel, onCancel,
variant = "page", variant = "page",
isExamPrep = false,
}: SelectPracticeToAttachStepProps) { }: SelectPracticeToAttachStepProps) {
const isDialog = variant === "dialog" const isDialog = variant === "dialog"
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
@ -69,7 +71,7 @@ export function SelectPracticeToAttachStep({
const load = useCallback(async () => { const load = useCallback(async () => {
setLoading(true) setLoading(true)
try { try {
const practices = await fetchAllPractices(unlinkedOnly) const practices = await fetchAllPractices(unlinkedOnly, { isExamPrep })
setAllPractices(practices) setAllPractices(practices)
} catch (e) { } catch (e) {
toast.error("Could not load practices", { toast.error("Could not load practices", {
@ -79,7 +81,7 @@ export function SelectPracticeToAttachStep({
} finally { } finally {
setLoading(false) setLoading(false)
} }
}, [unlinkedOnly]) }, [unlinkedOnly, isExamPrep])
useEffect(() => { useEffect(() => {
void load() void load()
@ -187,7 +189,9 @@ export function SelectPracticeToAttachStep({
<p className="text-sm font-semibold text-grayScale-700">No practices found</p> <p className="text-sm font-semibold text-grayScale-700">No practices found</p>
<p className="max-w-sm text-xs text-grayScale-500"> <p className="max-w-sm text-xs text-grayScale-500">
{unlinkedOnly {unlinkedOnly
? "No unlinked practices match your search. Try all practices or create a new shell from Question Types." ? isExamPrep
? "No unlinked exam-prep practices match your search. Try all practices or create a new shell first."
: "No unlinked practices match your search. Try all practices or create a new shell from Question Types."
: "Try a different search, switch to unlinked only, or create a new practice instead."} : "Try a different search, switch to unlinked only, or create a new practice instead."}
</p> </p>
</div> </div>

View File

@ -445,6 +445,28 @@ export interface GetExamPrepUnitPracticesResponse {
metadata: unknown | null metadata: unknown | null
} }
/** POST /exam-prep/practices — create with optional parents (unlinked shell). */
export interface CreateExamPrepPracticeRequest {
question_set_id: number
parents?: PracticeParent[] | null
parent_kind?: PracticeParentKind
parent_id?: number
title?: string
story_description?: string
story_image?: string
persona_id?: number
quick_tips?: string
publish_status?: PracticePublishStatus
}
export interface CreateExamPrepPracticeResponse {
message: string
data: ParentContextPractice
success: boolean
status_code: number
metadata: unknown | null
}
/** POST /exam-prep/lessons/:lessonId/practices */ /** POST /exam-prep/lessons/:lessonId/practices */
export interface CreateExamPrepLessonPracticeRequest { export interface CreateExamPrepLessonPracticeRequest {
title: string title: string
@ -642,6 +664,9 @@ export interface GetPracticesByParentContextResponse {
/** GET /practices — paginated list of all Learn English practices. */ /** GET /practices — paginated list of all Learn English practices. */
export type GetPracticesListResponse = GetPracticesByParentContextResponse export type GetPracticesListResponse = GetPracticesByParentContextResponse
/** GET /exam-prep/practices — paginated list of exam-prep practices. */
export type GetExamPrepPracticesListResponse = GetPracticesByParentContextResponse
export interface GetPracticesListParams { export interface GetPracticesListParams {
limit?: number limit?: number
offset?: number offset?: number