Initialize @wordpress/api-fetch in automation editor

[MAILPOET-4454]
This commit is contained in:
Jan Jakes
2022-06-29 15:56:18 +02:00
committed by Jan Jakeš
parent 91de8bd105
commit 3fa2ffb8f8
2 changed files with 12 additions and 0 deletions

View File

@@ -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));
};

View File

@@ -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<StoreDescriptor, 'name'> & {
name: typeof storeName;
};
initializeApi();
export const store = createReduxStore<State>(storeName, {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- the "Action" type is missing thunks with "dispatch"
actions: actions as any,