@@ -16,16 +16,19 @@ import {
16
16
ContentPaste ,
17
17
} from '@openedx/paragon/icons' ;
18
18
import { v4 as uuid4 } from 'uuid' ;
19
- import { useParams } from 'react-router-dom' ;
19
+ import { useNavigate , useParams } from 'react-router-dom' ;
20
+
20
21
import { ToastContext } from '../../generic/toast-context' ;
21
22
import { useCopyToClipboard } from '../../generic/clipboard' ;
22
23
import { getCanEdit } from '../../course-unit/data/selectors' ;
23
24
import { useCreateLibraryBlock , useLibraryPasteClipboard } from '../data/apiHooks' ;
25
+ import { getEditUrl } from '../components/utils' ;
24
26
25
27
import messages from './messages' ;
26
28
27
29
const AddContentContainer = ( ) => {
28
30
const intl = useIntl ( ) ;
31
+ const navigate = useNavigate ( ) ;
29
32
const { libraryId } = useParams ( ) ;
30
33
const createBlockMutation = useCreateLibraryBlock ( ) ;
31
34
const pasteClipboardMutation = useLibraryPasteClipboard ( ) ;
@@ -100,8 +103,14 @@ const AddContentContainer = () => {
100
103
libraryId,
101
104
blockType,
102
105
definitionId : `${ uuid4 ( ) } ` ,
103
- } ) . then ( ( ) => {
104
- showToast ( intl . formatMessage ( messages . successCreateMessage ) ) ;
106
+ } ) . then ( ( data ) => {
107
+ const editUrl = getEditUrl ( data . id ) ;
108
+ if ( editUrl ) {
109
+ navigate ( editUrl ) ;
110
+ } else {
111
+ // We can't start editing this right away so just show a toast message:
112
+ showToast ( intl . formatMessage ( messages . successCreateMessage ) ) ;
113
+ }
105
114
} ) . catch ( ( ) => {
106
115
showToast ( intl . formatMessage ( messages . errorCreateMessage ) ) ;
107
116
} ) ;
0 commit comments