Skip to content

Commit f9cd15e

Browse files
Ahtesham QuraishFaraz32123
authored andcommitted
fix: press Cancel it's not properly refreshing the unit and not showing the blank component was added.
1 parent bad66ca commit f9cd15e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/course-unit/add-component/AddComponent.jsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useCallback, useState } from 'react';
22
import PropTypes from 'prop-types';
3-
import { useSelector } from 'react-redux';
3+
import { useDispatch, useSelector } from 'react-redux';
44
import { getConfig } from '@edx/frontend-platform';
55
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
66
import {
77
ActionRow, Button, StandardModal, useToggle,
88
} from '@openedx/paragon';
99

10-
import { getCourseSectionVertical } from '../data/selectors';
10+
import { getCourseSectionVertical, getCourseUnitData } from '../data/selectors';
1111
import { useWaffleFlags } from '../../data/apiHooks';
1212
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
1313
import ComponentModalView from './add-component-modals/ComponentModalView';
@@ -20,6 +20,7 @@ import { useIframe } from '../../generic/hooks/context/hooks';
2020
import { useEventListener } from '../../generic/hooks';
2121
import VideoSelectorPage from '../../editors/VideoSelectorPage';
2222
import EditorPage from '../../editors/EditorPage';
23+
import { fetchCourseSectionVerticalData } from '../data/thunk';
2324

2425
const 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

Comments
 (0)