diff --git a/mailpoet/assets/js/src/automation/editor/store/api.ts b/mailpoet/assets/js/src/automation/editor/store/api.ts new file mode 100644 index 0000000000..30620c04e5 --- /dev/null +++ b/mailpoet/assets/js/src/automation/editor/store/api.ts @@ -0,0 +1,9 @@ +import apiFetch from '@wordpress/api-fetch'; +import { api } from '../../config'; + +const apiUrl = `${api.root}/mailpoet/v1/automation/`; + +export const initializeApi = () => { + apiFetch.use(apiFetch.createRootURLMiddleware(apiUrl)); + apiFetch.use(apiFetch.createNonceMiddleware(api.nonce)); +}; diff --git a/mailpoet/assets/js/src/automation/editor/store/index.ts b/mailpoet/assets/js/src/automation/editor/store/index.ts index d4d19cb4c0..611e34d682 100644 --- a/mailpoet/assets/js/src/automation/editor/store/index.ts +++ b/mailpoet/assets/js/src/automation/editor/store/index.ts @@ -1,5 +1,6 @@ import { createReduxStore, register, StoreDescriptor } from '@wordpress/data'; import * as actions from './actions'; +import { initializeApi } from './api'; import { storeName } from './constants'; import { initialState } from './initial_state'; import { reducer } from './reducer'; @@ -13,6 +14,8 @@ type StoreType = Omit & { name: typeof storeName; }; +initializeApi(); + export const store = createReduxStore(storeName, { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- the "Action" type is missing thunks with "dispatch" actions: actions as any,