@@ -3,30 +3,28 @@ import { useDispatch, useSelector } from 'react-redux';
33import { useIntl } from '@edx/frontend-platform/i18n' ;
44
55import { RequestStatus } from '../data/constants' ;
6- import { getLoadingDetailsStatus , getLoadingSettingsStatus , getSavingStatus } from './data/selectors' ;
6+ import { getLoadingSettingsStatus , getSavingStatus } from './data/selectors' ;
77import { validateScheduleAndDetails , updateWithDefaultValues } from './utils' ;
88
99const useLoadValuesPrompt = (
1010 courseId ,
11- fetchCourseDetailsQuery ,
1211 fetchCourseSettingsQuery ,
12+ courseDetailsError ,
1313) => {
1414 const dispatch = useDispatch ( ) ;
15- const loadingDetailsStatus = useSelector ( getLoadingDetailsStatus ) ;
1615 const loadingSettingsStatus = useSelector ( getLoadingSettingsStatus ) ;
1716 const [ showLoadFailedAlert , setShowLoadFailedAlert ] = useState ( false ) ;
1817
1918 useEffect ( ( ) => {
20- dispatch ( fetchCourseDetailsQuery ( courseId ) ) ;
2119 dispatch ( fetchCourseSettingsQuery ( courseId ) ) ;
2220 } , [ courseId ] ) ;
2321
2422 useEffect ( ( ) => {
25- if ( loadingDetailsStatus === RequestStatus . FAILED || loadingSettingsStatus === RequestStatus . FAILED ) {
23+ if ( courseDetailsError || loadingSettingsStatus === RequestStatus . FAILED ) {
2624 setShowLoadFailedAlert ( true ) ;
2725 window . scrollTo ( { top : 0 , behavior : 'smooth' } ) ;
2826 }
29- } , [ loadingDetailsStatus , loadingSettingsStatus ] ) ;
27+ } , [ courseDetailsError , loadingSettingsStatus ] ) ;
3028
3129 return {
3230 showLoadFailedAlert,
@@ -54,7 +52,7 @@ const useSaveValuesPrompt = (
5452 if ( ! isQueryPending && ! isEditableState ) {
5553 setEditedValues ( initialEditedData ) ;
5654 }
57- } , [ initialEditedData ] ) ;
55+ } , [ initialEditedData . isLoading ] ) ;
5856
5957 useEffect ( ( ) => {
6058 const errors = validateScheduleAndDetails ( editedValues , canShowCertificateAvailableDateField , intl ) ;
@@ -115,6 +113,8 @@ const useSaveValuesPrompt = (
115113 if ( ! isEditableState ) {
116114 setShowModifiedAlert ( false ) ;
117115 }
116+ // Refresh course data after successful save
117+ initialEditedData . refetch ( ) ;
118118 } else if ( savingStatus === RequestStatus . FAILED ) {
119119 setIsQueryPending ( false ) ;
120120 setShowSuccessfulAlert ( false ) ;
0 commit comments