diff --git a/packages/js/email-editor/src/components/personalization-tags/category-menu.tsx b/packages/js/email-editor/src/components/personalization-tags/category-menu.tsx
new file mode 100644
index 0000000000..7609d67ba9
--- /dev/null
+++ b/packages/js/email-editor/src/components/personalization-tags/category-menu.tsx
@@ -0,0 +1,51 @@
+import * as React from '@wordpress/element';
+import { MenuGroup, MenuItem } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+const CategoryMenu = ( {
+ groupedTags,
+ activeCategory,
+ onCategorySelect,
+}: {
+ groupedTags: Record< string, any[] >;
+ activeCategory: string | null;
+ onCategorySelect: ( category: string | null ) => void;
+} ) => {
+ const getMenuItemClass = ( category: string | null ) =>
+ category === activeCategory
+ ? 'mailpoet-personalization-tags-modal__menu-item-active'
+ : '';
+
+ return (
+
+
+
+ { Object.keys( groupedTags ).map( ( category, index, array ) => (
+
+
+ { index < array.length - 1 && (
+
+ ) }
+
+ ) ) }
+
+ );
+};
+
+export { CategoryMenu };
diff --git a/packages/js/email-editor/src/components/personalization-tags/category-section.tsx b/packages/js/email-editor/src/components/personalization-tags/category-section.tsx
new file mode 100644
index 0000000000..2e8005757e
--- /dev/null
+++ b/packages/js/email-editor/src/components/personalization-tags/category-section.tsx
@@ -0,0 +1,48 @@
+import { Button } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+import { PersonalizationTag } from '../../store';
+
+const CategorySection = ( {
+ groupedTags,
+ activeCategory,
+}: {
+ groupedTags: Record< string, PersonalizationTag[] >;
+ activeCategory: string | null;
+} ) => {
+ const categoriesToRender: [ string, PersonalizationTag[] ][] =
+ activeCategory === null
+ ? Object.entries( groupedTags ) // Render all categories
+ : [ [ activeCategory, groupedTags[ activeCategory ] || [] ] ]; // Render only one selected category
+
+ return (
+ <>
+ { categoriesToRender.map(
+ ( [ category, items ]: [ string, PersonalizationTag[] ] ) => (
+
+
+ { category }
+
+
+ { items.map( ( item ) => (
+
+
+ { item.name }
+ { item.token }
+
+
+
+ ) ) }
+
+
+ )
+ ) }
+ >
+ );
+};
+
+export { CategorySection };
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 de58ebae9e..61736bdda5 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,17 +1,12 @@
-import * as React from '@wordpress/element';
-import {
- Modal,
- Button,
- MenuGroup,
- MenuItem,
- SearchControl,
-} from '@wordpress/components';
+import { Modal, SearchControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { PersonalizationTag, storeName } from '../../store';
import { useDispatch, useSelect } from '@wordpress/data';
import { external, Icon } from '@wordpress/icons';
import './index.scss';
import { useState } from '@wordpress/element';
+import { CategoryMenu } from './category-menu';
+import { CategorySection } from './category-section';
const PersonalizationTagsModal = () => {
const [ activeCategory, setActiveCategory ] = useState( null );
@@ -47,11 +42,6 @@ const PersonalizationTagsModal = () => {
{} as Record< string, PersonalizationTag[] >
);
- const getMenuItemClass = ( category ) =>
- category === activeCategory
- ? 'mailpoet-personalization-tags-modal__menu-item-active'
- : '';
-
return (
{
-
-
-
- { Object.entries( groupedTags ).map(
- ( [ category ], index, array ) => (
-
-
- { index < array.length - 1 && (
-
- ) }
-
- )
- ) }
-
- { activeCategory === null ? (
- // Render all categories
- Object.entries( groupedTags ).map( ( [ category, items ] ) => (
-
-
- { category }
-
-
- { items.map( ( item ) => (
-
-
- { item.name }
- { item.token }
-
-
-
- ) ) }
-
-
- ) )
- ) : (
- // Render selected category
-
-
- { activeCategory }
-
-
- { groupedTags[ activeCategory ]?.map( ( item ) => (
-
-
- { item.name }
- { item.token }
-
-
-
- ) ) }
-
-
- ) }
+
+
);
};