Skip to content

Commit 27232b7

Browse files
feat: open the editor when creating a new component
1 parent 6cfd71d commit 27232b7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/library-authoring/add-content/AddContentContainer.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ import {
1616
ContentPaste,
1717
} from '@openedx/paragon/icons';
1818
import { v4 as uuid4 } from 'uuid';
19-
import { useParams } from 'react-router-dom';
19+
import { useNavigate, useParams } from 'react-router-dom';
20+
2021
import { ToastContext } from '../../generic/toast-context';
2122
import { useCopyToClipboard } from '../../generic/clipboard';
2223
import { getCanEdit } from '../../course-unit/data/selectors';
2324
import { useCreateLibraryBlock, useLibraryPasteClipboard } from '../data/apiHooks';
25+
import { getEditUrl } from '../components/utils';
2426

2527
import messages from './messages';
2628

2729
const AddContentContainer = () => {
2830
const intl = useIntl();
31+
const navigate = useNavigate();
2932
const { libraryId } = useParams();
3033
const createBlockMutation = useCreateLibraryBlock();
3134
const pasteClipboardMutation = useLibraryPasteClipboard();
@@ -100,8 +103,14 @@ const AddContentContainer = () => {
100103
libraryId,
101104
blockType,
102105
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+
}
105114
}).catch(() => {
106115
showToast(intl.formatMessage(messages.errorCreateMessage));
107116
});

src/library-authoring/data/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export async function createLibraryBlock({
166166
definition_id: definitionId,
167167
},
168168
);
169-
return data;
169+
return camelCaseObject(data);
170170
}
171171

172172
/**

0 commit comments

Comments
 (0)