@@ -11,6 +11,7 @@ import { Box, Grid, Button, Dialog } from '@mui/material'
1111import LessonForm from './components/LessonForm.jsx' ;
1212import QuizForm from './components/QuizForm.jsx' ;
1313import ContentTable from './components/ContentTable.jsx' ;
14+ import DeleteContentForm from './components/DeleteContentForm.jsx' ;
1415import { getCookie } from '../../src/utils.js' ;
1516
1617
@@ -20,11 +21,13 @@ function Course() {
2021 const [ dialogContent , setDialogContent ] = useState ( null )
2122 const [ lessonCache , setLessonCache ] = useState ( "" )
2223 const [ contentLoaded , setContentLoaded ] = useState ( false )
24+ const [ dialogMaxWidth , setDialogMaxWidth ] = useState ( 'lg' ) ;
2325
2426 const userRole = localStorage . getItem ( 'userRole' ) ;
2527 const apiBaseUrl = localStorage . getItem ( 'apiBaseUrl' ) ;
2628 const organizationId = localStorage . getItem ( 'activeOrganizationId' ) ;
2729
30+
2831 const resetDialog = ( ) => {
2932 setDialogOpen ( false ) ;
3033 setContentLoaded ( false ) ;
@@ -68,6 +71,25 @@ function Course() {
6871 } ) ) ;
6972 }
7073
74+ const deletContent = ( contentId ) => {
75+ fetch ( `${ apiBaseUrl } /organizations/${ organizationId } /courses/${ course_id } /contents/${ contentId } /` , {
76+ method : 'DELETE' ,
77+ headers : {
78+ 'X-CSRFToken' : getCookie ( 'csrftoken' )
79+ } ,
80+ } )
81+ . then ( response => {
82+ if ( response . ok ) {
83+ setContentLoaded ( false ) ;
84+ } else {
85+ console . error ( 'Error deleting content:' , response . statusText ) ;
86+ }
87+ } )
88+ . catch ( error => console . error ( 'Error deleting content:' , error ) ) ;
89+ setDialogMaxWidth ( 'lg' ) ;
90+ setDialogOpen ( false ) ;
91+ }
92+
7193 const tableEventHandler = async ( event ) => {
7294 console . log ( "Event triggered from ContentTable" , event ) ;
7395 if ( event . type === 'content_loaded' ) {
@@ -127,6 +149,11 @@ function Course() {
127149 } )
128150 . catch ( error => console . error ( 'Error reordering contents:' , error ) ) ;
129151 }
152+ if ( event . type === 'delete_content' ) {
153+ setDialogContent ( < DeleteContentForm content = { event . content } onDelete = { deletContent } onCancel = { ( ) => { setDialogOpen ( false ) ; setDialogMaxWidth ( 'lg' ) ; } } /> ) ;
154+ setDialogMaxWidth ( 'sm' ) ;
155+ setDialogOpen ( true ) ;
156+ }
130157 }
131158
132159 return (
@@ -162,7 +189,7 @@ function Course() {
162189 </ Box >
163190 </ Grid >
164191
165- < Dialog open = { dialogOpen } onClose = { handleClose } fullWidth maxWidth = "lg" sx = { { xs : { width : '100%' } , md : { width : '80%' } , lg : { maxWidth : '70%' } } } >
192+ < Dialog open = { dialogOpen } onClose = { handleClose } fullWidth maxWidth = { dialogMaxWidth } >
166193 { dialogContent }
167194 </ Dialog >
168195 </ Base >
0 commit comments