Add loading personalization to store

[MAILPOET-6354]
This commit is contained in:
Jan Lysý
2024-12-03 09:36:40 +01:00
committed by Aschepikov
parent bcc07c7503
commit 2c031b01fc
5 changed files with 34 additions and 2 deletions

View File

@ -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,

View File

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

View File

@ -40,6 +40,7 @@ export function getInitialState(): State {
},
personalizationTags: {
isModalOpened: false,
list: [],
},
};
}

View File

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

View File

@ -195,6 +195,12 @@ export type State = {
};
personalizationTags: {
isModalOpened: boolean;
list: {
name: string;
token: string;
category: string;
attributes: string[];
}[];
};
};