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:
parent
63fb170a8f
commit
a8243e3ae4
|
|
@ -105,7 +105,10 @@ import type {
|
|||
CreateExamPrepCatalogCoursePracticeResponse,
|
||||
CreateExamPrepUnitPracticeRequest,
|
||||
CreateExamPrepUnitPracticeResponse,
|
||||
CreateExamPrepPracticeRequest,
|
||||
CreateExamPrepPracticeResponse,
|
||||
GetExamPrepUnitPracticesResponse,
|
||||
GetExamPrepPracticesListResponse,
|
||||
GetExamPrepCatalogCoursePracticesResponse,
|
||||
GetExamPrepLessonPracticesResponse,
|
||||
GetExamPrepModuleLessonsResponse,
|
||||
|
|
@ -711,6 +714,24 @@ export const getExamPrepLessonPractices = (
|
|||
{ 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 */
|
||||
export const deleteExamPrepPractice = (practiceId: number) =>
|
||||
http.delete<{ message: string; success: boolean; status_code: number; metadata: unknown }>(
|
||||
|
|
|
|||
|
|
@ -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 { dedupeParents, parentsFromPractice } from "./practiceParents"
|
||||
|
||||
|
|
@ -22,11 +25,15 @@ export function mergedParentsForAttach(
|
|||
export async function attachPracticeToParent(
|
||||
practice: ParentContextPractice,
|
||||
newParent: PracticeParent,
|
||||
options?: { isExamPrep?: boolean },
|
||||
): Promise<void> {
|
||||
if (practiceAlreadyLinkedToParent(practice, newParent)) {
|
||||
throw new Error("This practice is already linked to the selected location.")
|
||||
}
|
||||
await updatePracticeParents(practice.id, {
|
||||
parents: mergedParentsForAttach(practice, newParent),
|
||||
})
|
||||
const parents = mergedParentsForAttach(practice, newParent)
|
||||
if (options?.isExamPrep) {
|
||||
await updateExamPrepPracticeParents(practice.id, { parents })
|
||||
return
|
||||
}
|
||||
await updatePracticeParents(practice.id, { parents })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
import { getPractices } from "../api/courses.api"
|
||||
import { getExamPrepPractices, getPractices } from "../api/courses.api"
|
||||
import type { ParentContextPractice } from "../types/course.types"
|
||||
|
||||
const FETCH_PAGE_SIZE = 100
|
||||
|
||||
export type FetchAllPracticesOptions = {
|
||||
isExamPrep?: boolean
|
||||
}
|
||||
|
||||
export async function fetchAllPractices(
|
||||
unlinkedOnly: boolean,
|
||||
options?: FetchAllPracticesOptions,
|
||||
): Promise<ParentContextPractice[]> {
|
||||
const listPractices = options?.isExamPrep ? getExamPrepPractices : getPractices
|
||||
const all: ParentContextPractice[] = []
|
||||
let offset = 0
|
||||
let totalCount = Number.POSITIVE_INFINITY
|
||||
|
||||
while (offset < totalCount) {
|
||||
const res = await getPractices({
|
||||
const res = await listPractices({
|
||||
limit: FETCH_PAGE_SIZE,
|
||||
offset,
|
||||
unlinked_only: unlinkedOnly,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
addQuestionToSet,
|
||||
createExamPrepCatalogCoursePractice,
|
||||
createExamPrepLessonPractice,
|
||||
createExamPrepPractice,
|
||||
createExamPrepUnitPractice,
|
||||
createParentLinkedPractice,
|
||||
createQuestion,
|
||||
|
|
@ -50,6 +51,8 @@ export interface PracticeCreationInput {
|
|||
examPrepCatalogCourseId?: number
|
||||
/** English proficiency unit practices use POST /exam-prep/units/:id/practices. */
|
||||
examPrepUnitId?: number
|
||||
/** When true, fall back to POST /exam-prep/practices when no nested route applies. */
|
||||
isExamPrep?: boolean
|
||||
}
|
||||
|
||||
function extractCreatedResourceId(
|
||||
|
|
@ -216,6 +219,17 @@ export async function executePracticeCreation(
|
|||
quick_tips: opts.quickTips.trim(),
|
||||
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({
|
||||
parents: createParents,
|
||||
title: opts.practiceTitle.trim(),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
updateExamPrepPracticeFull,
|
||||
updateExamPrepPracticeParents,
|
||||
updateLearnEnglishPracticeFull,
|
||||
updatePracticeParents,
|
||||
} from "../api/courses.api"
|
||||
|
|
@ -44,6 +45,11 @@ export async function executePracticeUpdate(
|
|||
|
||||
if (opts.isExamPrep) {
|
||||
await updateExamPrepPracticeFull(opts.practiceId, payload)
|
||||
if (opts.parentsChanged && opts.parents) {
|
||||
await updateExamPrepPracticeParents(opts.practiceId, {
|
||||
parents: dedupeParents(opts.parents),
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
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(" · ")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ export function AddPracticeFlow() {
|
|||
: formData.parents,
|
||||
);
|
||||
const parentsErr = validatePracticeParents(parents, {
|
||||
required: !isFromQuestionType,
|
||||
required: !isFromQuestionType && !isExamPrep,
|
||||
});
|
||||
if (parentsErr) {
|
||||
toast.error("Check practice locations", { description: parentsErr });
|
||||
|
|
@ -447,6 +447,7 @@ export function AddPracticeFlow() {
|
|||
? parentContext!.id
|
||||
: undefined,
|
||||
examPrepUnitId: useExamPrepUnitApi ? parentContext!.id : undefined,
|
||||
isExamPrep,
|
||||
status,
|
||||
questionSetTitle: isLearnEnglishLessonPractice
|
||||
? lessonDefaultTitle
|
||||
|
|
@ -504,6 +505,10 @@ export function AddPracticeFlow() {
|
|||
? 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 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
|
||||
? "Your speaking practice is saved and linked to this lesson’s question set."
|
||||
: "Your speaking practice is saved for the linked course or module."}
|
||||
|
|
@ -697,9 +702,9 @@ export function AddPracticeFlow() {
|
|||
prevStep={prevStep}
|
||||
onEditContext={() => setCurrentStep(1)}
|
||||
onEditQuestions={() => setCurrentStep(3)}
|
||||
parentSummary={parentSummary}
|
||||
parentSummary={parentSummary ?? (isExamPrep ? formatPracticeParentsSummary([], { isExamPrep: true }) : null)}
|
||||
typeDefinitions={typeDefinitions}
|
||||
canPublish={parentContext !== null}
|
||||
canPublish={isExamPrep || parentContext !== null}
|
||||
submitting={submitting}
|
||||
onSaveDraft={() => void submitPractice("DRAFT")}
|
||||
onPublish={() => void submitPractice("PUBLISHED")}
|
||||
|
|
@ -751,6 +756,15 @@ export function AddPracticeFlow() {
|
|||
</p>
|
||||
</div>
|
||||
) : 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 ? (
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -404,6 +404,12 @@ export function EditPracticeFlow() {
|
|||
toast.error("Check practice locations", { description: parentsErr });
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
const parentsErr = validatePracticeParents(formData.parents, { required: false });
|
||||
if (parentsErr) {
|
||||
toast.error("Check practice locations", { description: parentsErr });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setSubmitting(true);
|
||||
|
|
@ -423,16 +429,15 @@ export function EditPracticeFlow() {
|
|||
isLearnEnglishLessonPractice,
|
||||
lessonDefaultTitle,
|
||||
parents: dedupeParents(formData.parents),
|
||||
parentsChanged:
|
||||
!isExamPrep &&
|
||||
!practiceParentsEqual(formData.parents, initialParentsRef.current),
|
||||
parentsChanged: !practiceParentsEqual(
|
||||
formData.parents,
|
||||
initialParentsRef.current,
|
||||
),
|
||||
});
|
||||
toast.success(
|
||||
status === "PUBLISHED" ? "Practice updated and published" : "Practice saved as draft",
|
||||
);
|
||||
if (!isExamPrep) {
|
||||
initialParentsRef.current = dedupeParents(formData.parents);
|
||||
}
|
||||
setIsSaved(true);
|
||||
} catch (e) {
|
||||
toast.error("Could not update practice", {
|
||||
|
|
@ -511,12 +516,15 @@ export function EditPracticeFlow() {
|
|||
|
||||
const reviewParentSummary =
|
||||
formData.parents.length > 0
|
||||
? formatPracticeParentsSummary(formData.parents)
|
||||
? formatPracticeParentsSummary(formData.parents, { isExamPrep })
|
||||
: parentSummary;
|
||||
|
||||
const renderStep = () => {
|
||||
const useContextStep =
|
||||
isModuleContext || isCourseContext || isLessonContext;
|
||||
isModuleContext ||
|
||||
isCourseContext ||
|
||||
isLessonContext ||
|
||||
isUnitContext;
|
||||
|
||||
if (useContextStep) {
|
||||
switch (currentStep) {
|
||||
|
|
@ -530,7 +538,10 @@ export function EditPracticeFlow() {
|
|||
isLessonPractice={isLearnEnglishLessonPractice}
|
||||
lessonTitle={lessonTitleDisplay}
|
||||
parentSummary={reviewParentSummary}
|
||||
showParentsEditor={!isExamPrep}
|
||||
showParentsEditor={!isLearnEnglishLessonPractice}
|
||||
isExamPrepParents={isExamPrep}
|
||||
parentsOptional={isExamPrep}
|
||||
parentsCollapsedDefault={isExamPrep}
|
||||
/>
|
||||
);
|
||||
case 2:
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ export function LinkExistingPracticeFlow() {
|
|||
if (!selectedPractice) return
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await attachPracticeToParent(selectedPractice, targetParent)
|
||||
await attachPracticeToParent(selectedPractice, targetParent, { isExamPrep })
|
||||
toast.success("Practice linked successfully")
|
||||
setIsComplete(true)
|
||||
} catch (e) {
|
||||
|
|
@ -298,6 +298,7 @@ export function LinkExistingPracticeFlow() {
|
|||
<div className="mx-auto max-w-4xl">
|
||||
{currentStep === 1 ? (
|
||||
<SelectPracticeToAttachStep
|
||||
isExamPrep={isExamPrep}
|
||||
targetParent={targetParent}
|
||||
targetSummary={targetSummary}
|
||||
selectedPracticeId={selectedPractice?.id ?? null}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,6 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
|||
const [pendingSaveStatus, setPendingSaveStatus] =
|
||||
useState<PracticePublishStatus | null>(null)
|
||||
|
||||
const canUseWizard = parent != null
|
||||
|
||||
useEffect(() => {
|
||||
if (step === 4 && setTitle.trim() && !practiceTitle.trim()) {
|
||||
setPracticeTitle(setTitle.trim())
|
||||
|
|
@ -181,7 +179,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
|||
}
|
||||
|
||||
const handleStep4 = async (status: PracticePublishStatus) => {
|
||||
if (!parent || questionSetId == null) return
|
||||
if (questionSetId == null) return
|
||||
if (!practiceTitle.trim() || !storyDescription.trim() || !storyImage.trim()) {
|
||||
toast.error("Title, story description, and story image are required")
|
||||
return
|
||||
|
|
@ -190,7 +188,9 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
|||
setSaving(true)
|
||||
try {
|
||||
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(),
|
||||
story_description: storyDescription.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>
|
||||
<p className="text-sm font-normal text-grayScale-500">
|
||||
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>
|
||||
<ol className="mt-4 flex flex-wrap gap-2">
|
||||
{STEPS.map((s) => {
|
||||
|
|
@ -242,15 +242,14 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
|||
</ol>
|
||||
</CardHeader>
|
||||
<CardContent className="pt-5">
|
||||
{!canUseWizard && (
|
||||
<p className="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 "Look up
|
||||
practice" section, then return here. The practice is created for the same selection
|
||||
(course id, module id, or lesson id).
|
||||
{!parent ? (
|
||||
<p className="mb-4 rounded-xl border border-amber-200 bg-amber-50/80 px-4 py-3 text-sm text-amber-900">
|
||||
No placement selected — the practice shell will be created unlinked. Attach it to a
|
||||
course, module, or lesson later.
|
||||
</p>
|
||||
)}
|
||||
) : null}
|
||||
|
||||
{canUseWizard && step === 1 && (
|
||||
{step === 1 && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<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>
|
||||
)}
|
||||
|
||||
{canUseWizard && step === 2 && (
|
||||
{step === 2 && (
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-grayScale-600">
|
||||
Add one or more audio questions to question set #{questionSetId}.
|
||||
|
|
@ -382,7 +381,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
|||
</div>
|
||||
)}
|
||||
|
||||
{canUseWizard && step === 3 && (
|
||||
{step === 3 && (
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-grayScale-600">
|
||||
Confirm the order of questions in the set.
|
||||
|
|
@ -414,7 +413,7 @@ export function CreatePracticeWizard({ parent, onCreated }: Props) {
|
|||
</div>
|
||||
)}
|
||||
|
||||
{canUseWizard && step === 4 && parent && (
|
||||
{step === 4 && (
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-grayScale-600">
|
||||
Linked to {parent.kind.toLowerCase()} #{parent.id} · question set #{questionSetId}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ interface ContextStepProps {
|
|||
lockedParentKey?: string | null;
|
||||
/** When true, locations are optional and the picker can stay collapsed. */
|
||||
parentsOptional?: boolean;
|
||||
/** Use exam-prep parent kinds in the locations editor. */
|
||||
isExamPrepParents?: boolean;
|
||||
parentsCollapsedDefault?: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +51,7 @@ export function ContextStep({
|
|||
lockedParentKey = null,
|
||||
parentsOptional = false,
|
||||
parentsCollapsedDefault = false,
|
||||
isExamPrepParents = false,
|
||||
}: ContextStepProps) {
|
||||
const storyFileRef = useRef<HTMLInputElement>(null);
|
||||
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">
|
||||
<p className="font-semibold text-amber-900">Locations optional</p>
|
||||
<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.
|
||||
</p>
|
||||
</div>
|
||||
|
|
@ -162,6 +168,7 @@ export function ContextStep({
|
|||
parents={formData.parents ?? []}
|
||||
lockedParentKey={lockedParentKey}
|
||||
optional
|
||||
isExamPrep={isExamPrepParents}
|
||||
onChange={(parents) => setFormData({ ...formData, parents })}
|
||||
/>
|
||||
) : null}
|
||||
|
|
@ -170,6 +177,7 @@ export function ContextStep({
|
|||
<PracticeParentsField
|
||||
parents={formData.parents ?? []}
|
||||
lockedParentKey={lockedParentKey}
|
||||
isExamPrep={isExamPrepParents}
|
||||
onChange={(parents) => setFormData({ ...formData, parents })}
|
||||
/>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,12 +4,18 @@ import { Input } from "../../../../components/ui/input"
|
|||
import type { PracticeParent, PracticeParentKind } from "../../../../types/course.types"
|
||||
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: "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: "LESSON", label: "Lesson" },
|
||||
]
|
||||
|
||||
interface PracticeParentsFieldProps {
|
||||
parents: PracticeParent[]
|
||||
onChange: (parents: PracticeParent[]) => void
|
||||
|
|
@ -18,6 +24,8 @@ interface PracticeParentsFieldProps {
|
|||
lockedParentKey?: string | null
|
||||
/** When true, all rows can be cleared (unlinked practice). */
|
||||
optional?: boolean
|
||||
/** Use exam-prep parent kinds instead of Learn English. */
|
||||
isExamPrep?: boolean
|
||||
}
|
||||
|
||||
function parentKey(parent: PracticeParent): string {
|
||||
|
|
@ -30,8 +38,10 @@ export function PracticeParentsField({
|
|||
disabled = false,
|
||||
lockedParentKey = null,
|
||||
optional = false,
|
||||
isExamPrep = false,
|
||||
}: 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 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-xs text-grayScale-500">
|
||||
{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."}
|
||||
</p>
|
||||
</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"
|
||||
>
|
||||
{KIND_OPTIONS.map((opt) => (
|
||||
{kindOptions.map((opt) => (
|
||||
<option key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</option>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ interface SelectPracticeToAttachStepProps {
|
|||
nextStep: () => void
|
||||
onCancel: () => void
|
||||
variant?: "page" | "dialog"
|
||||
isExamPrep?: boolean
|
||||
}
|
||||
|
||||
function publishStatusClass(status?: string | null): string {
|
||||
|
|
@ -42,7 +43,7 @@ function matchesPracticeSearch(
|
|||
practice.story_description ?? "",
|
||||
String(practice.id),
|
||||
String(practice.question_set_id),
|
||||
formatPracticeParentsSummary(practice.parents ?? []),
|
||||
formatPracticeParentsSummary(practice.parents ?? [], { isExamPrep }),
|
||||
]
|
||||
.join(" ")
|
||||
.toLowerCase()
|
||||
|
|
@ -57,6 +58,7 @@ export function SelectPracticeToAttachStep({
|
|||
nextStep,
|
||||
onCancel,
|
||||
variant = "page",
|
||||
isExamPrep = false,
|
||||
}: SelectPracticeToAttachStepProps) {
|
||||
const isDialog = variant === "dialog"
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
|
@ -69,7 +71,7 @@ export function SelectPracticeToAttachStep({
|
|||
const load = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const practices = await fetchAllPractices(unlinkedOnly)
|
||||
const practices = await fetchAllPractices(unlinkedOnly, { isExamPrep })
|
||||
setAllPractices(practices)
|
||||
} catch (e) {
|
||||
toast.error("Could not load practices", {
|
||||
|
|
@ -79,7 +81,7 @@ export function SelectPracticeToAttachStep({
|
|||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [unlinkedOnly])
|
||||
}, [unlinkedOnly, isExamPrep])
|
||||
|
||||
useEffect(() => {
|
||||
void load()
|
||||
|
|
@ -187,7 +189,9 @@ export function SelectPracticeToAttachStep({
|
|||
<p className="text-sm font-semibold text-grayScale-700">No practices found</p>
|
||||
<p className="max-w-sm text-xs text-grayScale-500">
|
||||
{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."}
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -445,6 +445,28 @@ export interface GetExamPrepUnitPracticesResponse {
|
|||
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 */
|
||||
export interface CreateExamPrepLessonPracticeRequest {
|
||||
title: string
|
||||
|
|
@ -642,6 +664,9 @@ export interface GetPracticesByParentContextResponse {
|
|||
/** GET /practices — paginated list of all Learn English practices. */
|
||||
export type GetPracticesListResponse = GetPracticesByParentContextResponse
|
||||
|
||||
/** GET /exam-prep/practices — paginated list of exam-prep practices. */
|
||||
export type GetExamPrepPracticesListResponse = GetPracticesByParentContextResponse
|
||||
|
||||
export interface GetPracticesListParams {
|
||||
limit?: number
|
||||
offset?: number
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user