Add onInsert callback into PersonalizationTags from store
[MAILPOET-6354]
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { Button } from '@wordpress/components';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { PersonalizationTag } from '../../store';
|
||||
import { PersonalizationTag, storeName } from '../../store';
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
|
||||
const CategorySection = ( {
|
||||
groupedTags,
|
||||
@ -9,6 +10,13 @@ const CategorySection = ( {
|
||||
groupedTags: Record< string, PersonalizationTag[] >;
|
||||
activeCategory: string | null;
|
||||
} ) => {
|
||||
const { togglePersonalizationTagsModal } = useDispatch( storeName );
|
||||
|
||||
const { onInsert } = useSelect(
|
||||
( select ) => select( storeName ).getPersonalizationTagsState(),
|
||||
[]
|
||||
);
|
||||
|
||||
const categoriesToRender: [ string, PersonalizationTag[] ][] =
|
||||
activeCategory === null
|
||||
? Object.entries( groupedTags ) // Render all categories
|
||||
@ -32,7 +40,17 @@ const CategorySection = ( {
|
||||
<strong>{ item.name }</strong>
|
||||
{ item.token }
|
||||
</div>
|
||||
<Button variant="link">
|
||||
<Button
|
||||
variant="link"
|
||||
onClick={ () => {
|
||||
if ( onInsert ) {
|
||||
onInsert( item.token );
|
||||
}
|
||||
togglePersonalizationTagsModal(
|
||||
false
|
||||
);
|
||||
} }
|
||||
>
|
||||
{ __( 'Insert' ) }
|
||||
</Button>
|
||||
</div>
|
||||
|
@ -38,12 +38,16 @@ export function togglePreviewModal( isOpen: boolean ) {
|
||||
} as const;
|
||||
}
|
||||
|
||||
export function togglePersonalizationTagsModal( isOpen: boolean ) {
|
||||
export function togglePersonalizationTagsModal(
|
||||
isOpen: boolean,
|
||||
payload: Partial< State[ 'personalizationTags' ] > = {}
|
||||
) {
|
||||
return {
|
||||
type: 'CHANGE_PERSONALIZATION_TAGS_STATE',
|
||||
state: { isModalOpened: isOpen } as Partial<
|
||||
State[ 'personalizationTags' ]
|
||||
>,
|
||||
state: {
|
||||
isModalOpened: isOpen,
|
||||
...payload,
|
||||
} as Partial< State[ 'personalizationTags' ] >,
|
||||
} as const;
|
||||
}
|
||||
|
||||
@ -266,6 +270,7 @@ export function revertAndSaveTemplate( template ) {
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function* loadPersonalizationTags() {
|
||||
const data = yield apiFetch( {
|
||||
|
@ -41,6 +41,7 @@ export function getInitialState(): State {
|
||||
personalizationTags: {
|
||||
isModalOpened: false,
|
||||
list: [],
|
||||
onInsert: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -203,6 +203,7 @@ export type State = {
|
||||
personalizationTags: {
|
||||
isModalOpened: boolean;
|
||||
list: PersonalizationTag[];
|
||||
onInsert: ( ( value: string ) => void ) | null;
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user