From 330e2ecb4efc8181a54c3689ceea68e87b464af2 Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Tue, 1 Mar 2022 10:29:42 +0000
Subject: [PATCH] fix(newsletter): use href for stateToHTML in order to keep
 links properly

---
 src/components/Editing/CustomEditor.tsx | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/components/Editing/CustomEditor.tsx b/src/components/Editing/CustomEditor.tsx
index 5cca8c77..fa27851c 100644
--- a/src/components/Editing/CustomEditor.tsx
+++ b/src/components/Editing/CustomEditor.tsx
@@ -22,8 +22,23 @@ const CustomEditor: React.FC<CustomEditorProps> = ({
   const [editorState, setEditorState] = useState<EditorState>(baseState)
 
   const handleStateChange = (state: EditorState) => {
+    let options = {
+      entityStyleFn: (entity: any) => {
+        const entityType = entity.get('type').toLowerCase()
+        if (entityType === 'link') {
+          const data = entity.getData()
+          return {
+            element: 'a',
+            attributes: {
+              target: data.targetOption,
+              href: data.href,
+            },
+          }
+        }
+      },
+    }
     setEditorState(state)
-    handleChange(stateToHTML(editorState.getCurrentContent()), editorType)
+    handleChange(stateToHTML(state.getCurrentContent(), options), editorType)
   }
 
   return (
-- 
GitLab