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 * WordPress dependencies
*/ */
import { useSelect } from '@wordpress/data'; import { useDispatch, useSelect } from '@wordpress/data';
import { import {
ErrorBoundary, ErrorBoundary,
PostLockedModal, PostLockedModal,
@ -24,6 +23,7 @@ import { unlockPatternsRelatedSelectorsFromCoreStore } from '../../private-apis'
import { storeName } from '../../store'; import { storeName } from '../../store';
import { Layout } from './layout'; import { Layout } from './layout';
import { useNavigateToEntityRecord } from '../../hooks/use-navigate-to-entity-record'; import { useNavigateToEntityRecord } from '../../hooks/use-navigate-to-entity-record';
import { useEffect } from 'react';
export function InnerEditor( { export function InnerEditor( {
postId: initialPostId, postId: initialPostId,
@ -32,6 +32,12 @@ export function InnerEditor( {
initialEdits, initialEdits,
...props ...props
} ) { } ) {
const { loadPersonalizationTags } = useDispatch( storeName );
useEffect( () => {
void loadPersonalizationTags();
}, [ loadPersonalizationTags ] );
const { const {
currentPost, currentPost,
onNavigateToEntityRecord, 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: { personalizationTags: {
isModalOpened: false, isModalOpened: false,
list: [],
}, },
}; };
} }

View File

@ -23,6 +23,14 @@ export function reducer( state: State, action ): State {
activeTab: action.state.activeTab, activeTab: action.state.activeTab,
}, },
}; };
case 'SET_PERSONALIZATION_TAGS':
return {
...state,
personalizationTags: {
...state.personalizationTags,
list: action.personalizationTags,
},
};
default: default:
return state; return state;
} }

View File

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