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