diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js index 250297a5d6..886cd21e23 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js @@ -17,6 +17,7 @@ import retrieveComponentsFromSchema from './utils/retrieveComponentsFromSchema'; import retrieveNestedComponents from './utils/retrieveNestedComponents'; import { retrieveComponentsThatHaveComponents } from './utils/retrieveComponentsThatHaveComponents'; import makeUnique from '../../utils/makeUnique'; +import { getComponentsToPost, formatContentType } from './utils/cleanData'; const DataManagerProvider = ({ allIcons, children }) => { const [reducerState, dispatch] = useReducer(reducer, initialState, init); @@ -238,6 +239,35 @@ const DataManagerProvider = ({ allIcons, children }) => { return makeUnique(composWithCompos); }; + const submitData = async () => { + console.log('will submit', currentUid); + try { + // const mainDataUID = + // Temporary works only for creating ct + const body = { + components: getComponentsToPost( + modifiedData.components, + components, + currentUid, + true + ), + contentType: formatContentType(modifiedData.contentType), + }; + + const response = await request( + `/${pluginId}/content-types`, + { method: 'POST', body }, + true + ); + + console.log({ response }); + + console.log({ body }); + } catch (err) { + console.log(err); + } + }; + const updateSchema = (data, schemaType) => { dispatch({ type: 'UPDATE_SCHEMA', @@ -276,6 +306,7 @@ const DataManagerProvider = ({ allIcons, children }) => { removeComponentFromDynamicZone, setModifiedData, sortedContentTypesList, + submitData, updateSchema, }} > diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/TempListView/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/TempListView/index.js index 419c46c21f..aa6ded30e1 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/TempListView/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/TempListView/index.js @@ -36,6 +36,7 @@ const ListPage = () => { isInContentTypeView, // removeAttribute, // removeComponentFromDynamicZone, + submitData, } = useDataManager(); const { formatMessage } = useGlobalContext(); const { push } = useHistory(); @@ -207,7 +208,7 @@ const ListPage = () => { }, { color: 'success', - onClick: () => {}, + onClick: () => submitData(), title: formatMessage({ id: `${pluginId}.form.button.save`, }),