@@ -8,14 +8,15 @@ import DisableCohortsModal from './components/DisableCohortsModal';
88import messages from './messages' ;
99import DisabledCohortsView from './components/DisabledCohortsView' ;
1010import EnabledCohortsView from './components/EnabledCohortsView' ;
11- import { CohortProvider } from './components/CohortContext' ;
11+ import { CohortProvider , useCohortContext } from './components/CohortContext' ;
1212
13- const CohortsPage = ( ) => {
13+ const CohortsPageContent = ( ) => {
1414 const intl = useIntl ( ) ;
1515 const { courseId = '' } = useParams ( ) ;
1616 const { data : cohortStatus } = useCohortStatus ( courseId ) ;
1717 const { mutate : toggleCohortsMutate } = useToggleCohorts ( courseId ) ;
1818 const [ isOpenDisableModal , setIsOpenDisableModal ] = useState ( false ) ;
19+ const { clearSelectedCohort } = useCohortContext ( ) ;
1920 const { isCohorted = false } = cohortStatus ?? { } ;
2021
2122 const handleEnableCohorts = ( ) => {
@@ -28,36 +29,44 @@ const CohortsPage = () => {
2829 const handleDisableCohorts = ( ) => {
2930 toggleCohortsMutate ( { isCohorted : false } ,
3031 {
32+ onSuccess : ( ) => clearSelectedCohort ( ) ,
3133 onError : ( error ) => console . log ( error )
3234 } ) ;
3335 setIsOpenDisableModal ( false ) ;
3436 } ;
3537
3638 return (
37- < CohortProvider >
38- < div className = "mt-4.5 mb-4 mx-4" >
39- < div className = "d-inline-flex align-items-center" >
40- < h3 className = "mb-0 text-gray-700" > { intl . formatMessage ( messages . cohortsTitle ) } </ h3 >
41- { isCohorted && (
42- < div className = "small" >
43- < IconButton
44- alt = { intl . formatMessage ( messages . disableCohorts ) }
45- iconAs = { Settings }
46- iconClassNames = "mb-2 text-gray-500"
47- size = "sm"
48- variant = "secondary"
49- onClick = { ( ) => setIsOpenDisableModal ( true ) }
50- />
51- </ div >
52- ) }
53- </ div >
54- { isCohorted ? (
55- < EnabledCohortsView />
56- ) : (
57- < DisabledCohortsView onEnableCohorts = { handleEnableCohorts } />
39+ < div className = "mt-4.5 mb-4 mx-4" >
40+ < div className = "d-inline-flex align-items-center" >
41+ < h3 className = "mb-0 text-gray-700" > { intl . formatMessage ( messages . cohortsTitle ) } </ h3 >
42+ { isCohorted && (
43+ < div className = "small" >
44+ < IconButton
45+ alt = { intl . formatMessage ( messages . disableCohorts ) }
46+ iconAs = { Settings }
47+ iconClassNames = "mb-2 text-gray-500"
48+ size = "sm"
49+ variant = "secondary"
50+ onClick = { ( ) => setIsOpenDisableModal ( true ) }
51+ />
52+ </ div >
5853 ) }
59- < DisableCohortsModal isOpen = { isOpenDisableModal } onClose = { ( ) => setIsOpenDisableModal ( false ) } onConfirmDisable = { handleDisableCohorts } />
6054 </ div >
55+ { isCohorted ? (
56+ < EnabledCohortsView />
57+ ) : (
58+ < DisabledCohortsView onEnableCohorts = { handleEnableCohorts } />
59+ ) }
60+ < DisableCohortsModal isOpen = { isOpenDisableModal } onClose = { ( ) => setIsOpenDisableModal ( false ) } onConfirmDisable = { handleDisableCohorts } />
61+ </ div >
62+ ) ;
63+ } ;
64+
65+ // It was necessary to wrap the entire content with CohortProvider here to avoid errors in the use of cohort hooks within a provider
66+ const CohortsPage = ( ) => {
67+ return (
68+ < CohortProvider >
69+ < CohortsPageContent />
6170 </ CohortProvider >
6271 ) ;
6372} ;
0 commit comments