11import { useCallback , useState } from 'react' ;
22import PropTypes from 'prop-types' ;
3- import { useSelector } from 'react-redux' ;
3+ import { useDispatch , useSelector } from 'react-redux' ;
44import { getConfig } from '@edx/frontend-platform' ;
55import { useIntl , FormattedMessage } from '@edx/frontend-platform/i18n' ;
66import {
77 ActionRow , Button , StandardModal , useToggle ,
88} from '@openedx/paragon' ;
99
10- import { getCourseSectionVertical } from '../data/selectors' ;
10+ import { getCourseSectionVertical , getCourseUnitData } from '../data/selectors' ;
1111import { useWaffleFlags } from '../../data/apiHooks' ;
1212import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants' ;
1313import ComponentModalView from './add-component-modals/ComponentModalView' ;
@@ -20,6 +20,7 @@ import { useIframe } from '../../generic/hooks/context/hooks';
2020import { useEventListener } from '../../generic/hooks' ;
2121import VideoSelectorPage from '../../editors/VideoSelectorPage' ;
2222import EditorPage from '../../editors/EditorPage' ;
23+ import { fetchCourseSectionVerticalData } from '../data/thunk' ;
2324
2425const AddComponent = ( {
2526 parentLocator,
@@ -29,6 +30,8 @@ const AddComponent = ({
2930 handleCreateNewCourseXBlock,
3031} ) => {
3132 const intl = useIntl ( ) ;
33+ const dispatch = useDispatch ( ) ;
34+
3235 const [ isOpenAdvanced , openAdvanced , closeAdvanced ] = useToggle ( false ) ;
3336 const [ isOpenHtml , openHtml , closeHtml ] = useToggle ( false ) ;
3437 const [ isOpenOpenAssessment , openOpenAssessment , closeOpenAssessment ] = useToggle ( false ) ;
@@ -47,6 +50,9 @@ const AddComponent = ({
4750 const { sendMessageToIframe } = useIframe ( ) ;
4851 const { useVideoGalleryFlow } = useWaffleFlags ( courseId ?? undefined ) ;
4952
53+ const courseUnit = useSelector ( getCourseUnitData ) ;
54+ const sequenceId = courseUnit ?. ancestorInfo ?. ancestors ?. [ 0 ] ?. id ;
55+
5056 const receiveMessage = useCallback ( ( { data : { type, payload } } ) => {
5157 if ( type === messageTypes . showMultipleComponentPicker ) {
5258 showSelectLibraryContentModal ( ) ;
@@ -68,8 +74,16 @@ const AddComponent = ({
6874 closeXBlockEditorModal ( ) ;
6975 closeVideoSelectorModal ( ) ;
7076 sendMessageToIframe ( messageTypes . refreshXBlock , null ) ;
77+ dispatch ( fetchCourseSectionVerticalData ( blockId , sequenceId ) ) ;
7178 } , [ closeXBlockEditorModal , closeVideoSelectorModal , sendMessageToIframe ] ) ;
7279
80+ const onXBlockCancel = useCallback ( /* istanbul ignore next */ ( ) => {
81+ // ignoring tests because it triggers when someone closes the editor which has a separate store
82+ closeXBlockEditorModal ( ) ;
83+ closeVideoSelectorModal ( ) ;
84+ dispatch ( fetchCourseSectionVerticalData ( blockId , sequenceId ) ) ;
85+ } , [ closeXBlockEditorModal , closeVideoSelectorModal , sendMessageToIframe , blockId , sequenceId ] ) ;
86+
7387 const handleLibraryV2Selection = useCallback ( ( selection ) => {
7488 handleCreateNewCourseXBlock ( {
7589 type : COMPONENT_TYPES . libraryV2 ,
@@ -262,7 +276,7 @@ const AddComponent = ({
262276 blockId = { newBlockId }
263277 studioEndpointUrl = { getConfig ( ) . STUDIO_BASE_URL }
264278 lmsEndpointUrl = { getConfig ( ) . LMS_BASE_URL }
265- onClose = { closeXBlockEditorModal }
279+ onClose = { onXBlockCancel }
266280 returnFunction = { /* istanbul ignore next */ ( ) => onXBlockSave }
267281 />
268282 </ div >
0 commit comments