From 2895540ae7bc97a30aba401e1ae7fc94ed51d270 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Tue, 2 Jul 2024 16:37:09 -0300 Subject: [PATCH] fix(canary): add field to persist value CKEditor5 on form --- .../Settings/Autofire/CKEditor5Field.tsx | 56 +++++++++++++++++++ .../WidgetActions/Settings/Autofire/index.tsx | 40 +++++-------- 2 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/CKEditor5Field.tsx diff --git a/clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/CKEditor5Field.tsx b/clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/CKEditor5Field.tsx new file mode 100644 index 000000000..af8faff0a --- /dev/null +++ b/clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/CKEditor5Field.tsx @@ -0,0 +1,56 @@ +import React from "react"; +import { FormControl, FormLabel, Flex, Tooltip, Stack } from "bonde-components/chakra"; +import { Hint } from "bonde-components"; +import { InfoIcon } from "bonde-components/icons"; +import { useField } from "bonde-components/form"; + +import { CKEditor } from "@ckeditor/ckeditor5-react"; +import ClassicEditor from "ckeditor5-custom-build"; + + +const CKEditor5Field = ({ + name, + helpText, + label, + ...config +}: any) => { + const { input, meta } = useField(name, config); + const editorConfig: any = { + s3Upload: { + signingUrl: process.env.REACT_APP_UPLOADS_URL + } + } + + return ( + + + + {label} + {helpText && ( + + + + )} + + {(meta.error || meta.submitError) && meta.touched && ( + {meta.error || meta.submitError} + )} + + { + const data = editor.getData(); + console.log("event, editor, data", { event, editor, data }); + input.onChange(data); + }} + /> + + ) +} + +export default CKEditor5Field; \ No newline at end of file diff --git a/clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/index.tsx b/clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/index.tsx index ff9618bf9..ff103af50 100644 --- a/clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/index.tsx +++ b/clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import { useTranslation } from "react-i18next"; import styled from 'styled-components'; @@ -9,17 +9,17 @@ import { Flex, Grid, GridItem, - Heading, - FormLabel + Heading } from "bonde-components/chakra"; -import ClassicEditor from "ckeditor5-custom-build"; -import { CKEditor } from "@ckeditor/ckeditor5-react"; + import { noSpecialCharacters } from "../../../../services/utils"; import { Widget } from "../../FetchWidgets"; import SettingsForm from '../SettingsForm'; +import CKEditor5Field from "./CKEditor5Field"; + const Styles = styled.div` .emailBody { padding-bottom: 30px; @@ -41,7 +41,7 @@ const { required, composeValidators, isEmail } = Validators; const AutofireForm = ({ widget, updateCache }: Props): React.ReactElement => { const { t } = useTranslation("widgetActions"); - const [editorData, setEditorData] = useState(widget.settings.email_body); + console.log("settings", { settings: widget.settings }); return ( @@ -87,27 +87,13 @@ const AutofireForm = ({ widget, updateCache }: Props): React.ReactElement => { required(t("settings.autofire.validators.required")) )} /> - - - {t("settings.autofire.label.emailBody")} - - { - const data = editor.getData(); - setEditorData(data); - }} - validate={composeValidators( - required(t("settings.autofire.validators.required")) - )} - /> - +