From d17faaa13ad951c87044f1d5fa43f04e882646d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lys=C3=BD?= Date: Tue, 3 Dec 2024 13:36:41 +0100 Subject: [PATCH] Add rendering Personalization tags to modal [MAILPOET-6354] --- .../personalization-tags/index.scss | 42 +++++++++++++++ .../personalization-tags-modal.tsx | 51 +++++++++++++++++-- packages/js/email-editor/src/store/types.ts | 14 ++--- 3 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 packages/js/email-editor/src/components/personalization-tags/index.scss diff --git a/packages/js/email-editor/src/components/personalization-tags/index.scss b/packages/js/email-editor/src/components/personalization-tags/index.scss new file mode 100644 index 0000000000..e06699d49e --- /dev/null +++ b/packages/js/email-editor/src/components/personalization-tags/index.scss @@ -0,0 +1,42 @@ +.mailpoet-personalization-tags-modal { + p:first-child { + margin-top: 0; + } + .mailpoet-personalization-tags-modal__category { + display: inline-block; + font-size: 11px; + line-height: 16px; + padding-bottom: 8px; + padding-top: 16px; + text-transform: uppercase; + } + .mailpoet-personalization-tags-modal__category-group { + display: flex; + flex-direction: column; + gap: 10px; + + .mailpoet-personalization-tags-modal__category-group-item { + align-items: stretch; + border-bottom: 1px solid #ddd; + display: flex; + padding: 16px 0; + + .mailpoet-personalization-tags-modal__item-text { + display: flex; + flex: 1; + flex-direction: column; + font-size: 12px; + gap: 5px; + justify-content: center; + line-height: 18px; + } + + button.is-link { + flex: 0 0 auto; + font-size: 14px; + height: auto; + line-height: 2; + } + } + } +} diff --git a/packages/js/email-editor/src/components/personalization-tags/personalization-tags-modal.tsx b/packages/js/email-editor/src/components/personalization-tags/personalization-tags-modal.tsx index 7bd6085300..44942ed7e4 100644 --- a/packages/js/email-editor/src/components/personalization-tags/personalization-tags-modal.tsx +++ b/packages/js/email-editor/src/components/personalization-tags/personalization-tags-modal.tsx @@ -1,12 +1,14 @@ -import { Modal } from '@wordpress/components'; +import { Modal, Button } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { storeName } from '../../store'; +import { PersonalizationTag, storeName } from '../../store'; import { useDispatch, useSelect } from '@wordpress/data'; +import { external, Icon } from '@wordpress/icons'; +import './index.scss'; const PersonalizationTagsModal = () => { const { togglePersonalizationTagsModal } = useDispatch( storeName ); - const { isModalOpened } = useSelect( + const { isModalOpened, list } = useSelect( ( select ) => select( storeName ).getPersonalizationTagsState(), [] ); @@ -14,13 +16,54 @@ const PersonalizationTagsModal = () => { if ( ! isModalOpened ) { return null; } + + const groupedTags: Record< string, PersonalizationTag[] > = list.reduce( + ( groups, item ) => { + const { category } = item; + if ( ! groups[ category ] ) { + groups[ category ] = []; + } + groups[ category ].push( item ); + return groups; + }, + {} as Record< string, PersonalizationTag[] > + ); + return ( togglePersonalizationTagsModal( false ) } + className="mailpoet-personalization-tags-modal" > -

There will be a list of personalization tags here.

+

+ Insert shortcodes to dynamically fill in information and + personalize your emails. Learn more{ ' ' } + +

+ { Object.entries( groupedTags ).map( ( [ category, items ] ) => ( +
+
+ { category } +
+
+ { items.map( ( item ) => ( +
+
+ { item.name } + { item.token } +
+ +
+ ) ) } +
+
+ ) ) }
); }; diff --git a/packages/js/email-editor/src/store/types.ts b/packages/js/email-editor/src/store/types.ts index 3c9e164923..86d1c46b9d 100644 --- a/packages/js/email-editor/src/store/types.ts +++ b/packages/js/email-editor/src/store/types.ts @@ -166,6 +166,13 @@ export type EmailEditorUrls = { listings: string; }; +export type PersonalizationTag = { + name: string; + token: string; + category: string; + attributes: string[]; +}; + export type State = { inserterSidebar: { isOpened: boolean; @@ -195,12 +202,7 @@ export type State = { }; personalizationTags: { isModalOpened: boolean; - list: { - name: string; - token: string; - category: string; - attributes: string[]; - }[]; + list: PersonalizationTag[]; }; };