Add loading personalization to store
[MAILPOET-6354]
This commit is contained in:
@ -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,
|
||||||
|
@ -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: {
|
personalizationTags: {
|
||||||
isModalOpened: false,
|
isModalOpened: false,
|
||||||
|
list: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -195,6 +195,12 @@ export type State = {
|
|||||||
};
|
};
|
||||||
personalizationTags: {
|
personalizationTags: {
|
||||||
isModalOpened: boolean;
|
isModalOpened: boolean;
|
||||||
|
list: {
|
||||||
|
name: string;
|
||||||
|
token: string;
|
||||||
|
category: string;
|
||||||
|
attributes: string[];
|
||||||
|
}[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user