@@ -11,6 +11,8 @@ import { useAppContext } from '../../../src/render.jsx';
1111function LessonForm ( { header, initialTitle, initialContent, cancelCallback, successCallback, courseId, lessonId, initialWaitingPeriod, contentId } ) {
1212 const initialWaitingPeriodValue = initialWaitingPeriod ? initialWaitingPeriod . period : 1 ;
1313 const initialWaitingPeriodUnit = initialWaitingPeriod ? initialWaitingPeriod . type : "days" ;
14+ const [ lessonIdentifier , setLessonIdentifier ] = useState ( lessonId ) ;
15+ const [ contentIdentifier , setContentIdentifier ] = useState ( contentId ) ;
1416 const [ title , setTitle ] = useState ( initialTitle || "" ) ;
1517 const [ content , setContent ] = useState ( initialContent || "" ) ;
1618 const [ waitingPeriod , setWaitingPeriod ] = useState ( initialWaitingPeriodValue ) ;
@@ -101,13 +103,16 @@ function LessonForm({ header, initialTitle, initialContent, cancelCallback, succ
101103 . then ( ( data ) => {
102104 console . log ( 'Lesson created successfully:' , data ) ;
103105 setErrorMessage ( "" ) ;
106+ setLessonIdentifier ( data . lesson . id ) ;
107+ setContentIdentifier ( data . id ) ;
104108 setSuccessMessage ( localeMessages [ "lesson_saved_success" ] || "Lesson content saved successfully." ) ;
105109 setSavedSnapshot ( {
106110 title,
107111 content,
108112 waitingPeriod : String ( waitingPeriod ) ,
109113 waitingPeriodUnit,
110114 } ) ;
115+ successCallback ?. ( ) ;
111116 } )
112117 . catch ( ( error ) => {
113118 console . error ( 'Error creating lesson:' , error ) ;
@@ -122,9 +127,9 @@ function LessonForm({ header, initialTitle, initialContent, cancelCallback, succ
122127 return ;
123128 }
124129
125- console . log ( "Updating lesson ID:" , lessonId ) ;
130+ console . log ( "Updating lesson ID:" , lessonIdentifier ) ;
126131
127- fetch ( apiBaseUrl + '/organizations/' + orgId + '/courses/' + courseId + '/contents/' + contentId + '/' , {
132+ fetch ( apiBaseUrl + '/organizations/' + orgId + '/courses/' + courseId + '/contents/' + contentIdentifier + '/' , {
128133 method : 'POST' ,
129134 credentials : 'include' ,
130135 headers : {
@@ -453,7 +458,7 @@ function LessonForm({ header, initialTitle, initialContent, cancelCallback, succ
453458 < Button variant = "outlined" onClick = { cancel } >
454459 { localeMessages [ "back" ] }
455460 </ Button >
456- { userRole !== 'viewer' && < Button type = "submit" variant = "contained" onClick = { ( ) => { if ( ! lessonId ) { addLesson ( ) ; } else { updateLesson ( ) ; } } } >
461+ { userRole !== 'viewer' && < Button type = "submit" variant = "contained" onClick = { ( ) => { if ( ! lessonIdentifier ) { addLesson ( ) ; } else { updateLesson ( ) ; } } } >
457462 { localeMessages [ "save_lesson" ] }
458463 </ Button > }
459464 </ Box >
0 commit comments