@@ -3,6 +3,7 @@ import { useParams, Link, useSearchParams } from 'react-router-dom';
33import {
44 Row , Spinner , Icon , ModalLayer , Button , Chip , Card , Collapsible , Col ,
55 Stack ,
6+ Toast ,
67} from '@openedx/paragon' ;
78import {
89 Person ,
@@ -49,7 +50,7 @@ const LearningPathDetailPage = () => {
4950
5051 const { data : learningPaths , isLoading : loadingLearningPaths } = useLearningPaths ( ) ;
5152
52- const key = learningPaths ?. find ( ( lp ) => lp . slug === catalogId ) . id ;
53+ const key = learningPaths ?. find ( ( lp ) => lp . slug === catalogId ) ? .id ;
5354
5455 const {
5556 data : detail ,
@@ -70,20 +71,23 @@ const LearningPathDetailPage = () => {
7071 setIsModalOpen ( false ) ;
7172 } ;
7273
73- const handleAllowAndContinue = async ( ) => {
74+ const [ errorMessage , setErrorMessage ] = useState ( '' ) ;
75+ const handleAllowAndContinue = ( ) => {
7476 if ( detail && ! detail . enrollmentDate ) {
7577 setEnrolling ( true ) ;
7678 setIsModalOpen ( false ) ;
77- try {
78- await enrollMutation . mutateAsync ( key ) ;
79- setLocalStatus ( 'accepted' ) ;
80- } catch ( error ) {
81- // eslint-disable-next-line no-console
82- console . error ( 'Enrollment failed:' , error ) ;
83- } finally {
84- setActiveTab ( 'courses' ) ;
85- setEnrolling ( false ) ;
86- }
79+ enrollMutation . mutate ( key , {
80+ onSuccess : ( ) => {
81+ setLocalStatus ( 'accepted' ) ;
82+ setEnrolling ( false ) ;
83+ setActiveTab ( 'courses' ) ;
84+ } ,
85+ onError : ( { response } ) => {
86+ setErrorMessage ( response . data . detail ) ;
87+ setEnrolling ( false ) ;
88+ } ,
89+
90+ } ) ;
8791 }
8892 } ;
8993
@@ -172,10 +176,12 @@ const LearningPathDetailPage = () => {
172176 } else if ( detailError || ! detail ) {
173177 content = (
174178 < div className = "p-4" >
175- < p > { formatMessage ( messages . failedToLoadDetail ) } </ p >
179+ < p className = "text-center" > { formatMessage ( messages . failedToLoadDetail ) } </ p >
176180 < Link to = "/" >
177- < Icon src = { ChevronLeft } />
178- < span > { formatMessage ( messages . backToMyCatalogs ) } </ span >
181+ < Stack direction = "horizontal" >
182+ < Icon src = { ChevronLeft } />
183+ < span > { formatMessage ( messages . backToMyCatalogs ) } </ span >
184+ </ Stack >
179185 </ Link >
180186 </ div >
181187 ) ;
@@ -338,6 +344,7 @@ const LearningPathDetailPage = () => {
338344 learningPathSteps = { detail ?. steps }
339345 learningPathId = { key }
340346 onCourseClick = { handleCourseViewButton }
347+ isEnrolledInLearningPath = { isEnrolledInLearningPath }
341348 />
342349 ) }
343350 </ section >
@@ -378,6 +385,13 @@ const LearningPathDetailPage = () => {
378385
379386 return (
380387 < >
388+ < Toast
389+ onClose = { ( ) => setErrorMessage ( '' ) }
390+ show = { ! ! errorMessage }
391+ >
392+ { errorMessage }
393+ </ Toast >
394+
381395 { content }
382396
383397 { selectedCourseKey && (
0 commit comments