Add loading personalization to store
[MAILPOET-6354]
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
import {
|
||||
ErrorBoundary,
|
||||
PostLockedModal,
|
||||
@ -24,6 +23,7 @@ import { unlockPatternsRelatedSelectorsFromCoreStore } from '../../private-apis'
|
||||
import { storeName } from '../../store';
|
||||
import { Layout } from './layout';
|
||||
import { useNavigateToEntityRecord } from '../../hooks/use-navigate-to-entity-record';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function InnerEditor( {
|
||||
postId: initialPostId,
|
||||
@ -32,6 +32,12 @@ export function InnerEditor( {
|
||||
initialEdits,
|
||||
...props
|
||||
} ) {
|
||||
const { loadPersonalizationTags } = useDispatch( storeName );
|
||||
|
||||
useEffect( () => {
|
||||
void loadPersonalizationTags();
|
||||
}, [ loadPersonalizationTags ] );
|
||||
|
||||
const {
|
||||
currentPost,
|
||||
onNavigateToEntityRecord,
|
||||
|
@ -266,4 +266,15 @@ export function revertAndSaveTemplate( template ) {
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export function* loadPersonalizationTags() {
|
||||
const data = yield apiFetch( {
|
||||
path: `/mailpoet-email-editor/v1/get_personalization_tags`,
|
||||
method: 'GET',
|
||||
} );
|
||||
|
||||
return {
|
||||
type: 'SET_PERSONALIZATION_TAGS',
|
||||
personalizationTags: data.result,
|
||||
} as const;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ export function getInitialState(): State {
|
||||
},
|
||||
personalizationTags: {
|
||||
isModalOpened: false,
|
||||
list: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -23,6 +23,14 @@ export function reducer( state: State, action ): State {
|
||||
activeTab: action.state.activeTab,
|
||||
},
|
||||
};
|
||||
case 'SET_PERSONALIZATION_TAGS':
|
||||
return {
|
||||
...state,
|
||||
personalizationTags: {
|
||||
...state.personalizationTags,
|
||||
list: action.personalizationTags,
|
||||
},
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -195,6 +195,12 @@ export type State = {
|
||||
};
|
||||
personalizationTags: {
|
||||
isModalOpened: boolean;
|
||||
list: {
|
||||
name: string;
|
||||
token: string;
|
||||
category: string;
|
||||
attributes: string[];
|
||||
}[];
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user