diff --git a/frontend/packages/volto-form-block/locales/de/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/de/LC_MESSAGES/volto.po index dc51ecf..9846f65 100644 --- a/frontend/packages/volto-form-block/locales/de/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/de/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "Statischer Text" msgid "textarea" msgstr "Textfeld" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/en/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/en/LC_MESSAGES/volto.po index 38a9699..1bc1b49 100644 --- a/frontend/packages/volto-form-block/locales/en/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/en/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/es/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/es/LC_MESSAGES/volto.po index aa650dd..7238675 100644 --- a/frontend/packages/volto-form-block/locales/es/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/es/LC_MESSAGES/volto.po @@ -788,6 +788,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/eu/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/eu/LC_MESSAGES/volto.po index 26d1f95..b688fc8 100644 --- a/frontend/packages/volto-form-block/locales/eu/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/eu/LC_MESSAGES/volto.po @@ -784,6 +784,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/fr/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/fr/LC_MESSAGES/volto.po index 3e5075d..72c43f3 100644 --- a/frontend/packages/volto-form-block/locales/fr/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/fr/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/it/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/it/LC_MESSAGES/volto.po index 1f396e3..cceb0a1 100644 --- a/frontend/packages/volto-form-block/locales/it/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/it/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/ja/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/ja/LC_MESSAGES/volto.po index 8a7aa34..dc6c79f 100644 --- a/frontend/packages/volto-form-block/locales/ja/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/ja/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/nl/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/nl/LC_MESSAGES/volto.po index 4e74fbc..adc3173 100644 --- a/frontend/packages/volto-form-block/locales/nl/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/nl/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/pt/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/pt/LC_MESSAGES/volto.po index 8a7aa34..dc6c79f 100644 --- a/frontend/packages/volto-form-block/locales/pt/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/pt/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/pt_BR/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/pt_BR/LC_MESSAGES/volto.po index fcb7846..75d4378 100644 --- a/frontend/packages/volto-form-block/locales/pt_BR/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/pt_BR/LC_MESSAGES/volto.po @@ -788,6 +788,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/ro/LC_MESSAGES/volto.po b/frontend/packages/volto-form-block/locales/ro/LC_MESSAGES/volto.po index 8a7aa34..dc6c79f 100644 --- a/frontend/packages/volto-form-block/locales/ro/LC_MESSAGES/volto.po +++ b/frontend/packages/volto-form-block/locales/ro/LC_MESSAGES/volto.po @@ -782,6 +782,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/locales/volto.pot b/frontend/packages/volto-form-block/locales/volto.pot index 3a0ee9d..863ea22 100644 --- a/frontend/packages/volto-form-block/locales/volto.pot +++ b/frontend/packages/volto-form-block/locales/volto.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: Plone\n" -"POT-Creation-Date: 2024-10-05T13:25:45.385Z\n" +"POT-Creation-Date: 2024-10-05T15:44:18.362Z\n" "Last-Translator: Plone i18n \n" "Language-Team: Plone i18n \n" "Content-Type: text/plain; charset=utf-8\n" @@ -784,6 +784,11 @@ msgstr "" msgid "textarea" msgstr "" +#. Default: "Thank you message" +#: schemaFormBlock/schema +msgid "thankyou" +msgstr "" + #. Default: "Time" #: index msgid "time" diff --git a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx index 3d7299b..9d2f2df 100644 --- a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx +++ b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { useDispatch } from 'react-redux'; import { defineMessages, useIntl } from 'react-intl'; import { Form } from '@plone/volto/components/manage/Form'; @@ -30,6 +30,7 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => { const dispatch = useDispatch(); const intl = useIntl(); const location = useLocation(); + const [submitted, setSubmitted] = useState(false); const propertyNames = keys(data.schema.properties); const initialData = pickBy(qs.parse(location.search), (value, key) => @@ -58,27 +59,31 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => { ), ); - dispatch(submitForm(path, id, submitData, captcha)).catch((err) => { - let message = - err?.response?.body?.error?.message || - err?.response?.body?.message || - err?.response?.text || - ''; - const errorsList = tryParseJSON(message); - let invariantErrors = []; - if (Array.isArray(errorsList)) { - invariantErrors = extractInvariantErrors(errorsList); - } - if (invariantErrors.length > 0) { - toast.error( - , - ); - } - }); + dispatch(submitForm(path, id, submitData, captcha)) + .then((resp) => { + setSubmitted(true); + }) + .catch((err) => { + let message = + err?.response?.body?.error?.message || + err?.response?.body?.message || + err?.response?.text || + ''; + const errorsList = tryParseJSON(message); + let invariantErrors = []; + if (Array.isArray(errorsList)) { + invariantErrors = extractInvariantErrors(errorsList); + } + if (invariantErrors.length > 0) { + toast.error( + , + ); + } + }); }; return ( @@ -87,23 +92,34 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => { {data.description && (

{data.description}

)} -
({ - ...fieldset, - fields: includes(fieldset.fields, 'captchaWidget') - ? [...without(fieldset.fields, 'captchaWidget'), 'captchaWidget'] - : fieldset.fields, - })), - }} - formData={initialData} - onSubmit={onSubmit} - resetOnCancel={true} - onCancel={data.show_cancel ? onCancel : null} - submitLabel={data.submit_label || intl.formatMessage(messages.submit)} - cancelLabel={data.cancel_label || intl.formatMessage(messages.cancel)} - /> + {submitted ? ( +

+ ) : ( + ({ + ...fieldset, + fields: includes(fieldset.fields, 'captchaWidget') + ? [ + ...without(fieldset.fields, 'captchaWidget'), + 'captchaWidget', + ] + : fieldset.fields, + })), + }} + formData={initialData} + onSubmit={onSubmit} + resetOnCancel={true} + onCancel={data.show_cancel ? onCancel : null} + submitLabel={data.submit_label || intl.formatMessage(messages.submit)} + cancelLabel={data.cancel_label || intl.formatMessage(messages.cancel)} + /> + )} ); }; diff --git a/frontend/packages/volto-form-block/src/schemaFormBlock/schema.js b/frontend/packages/volto-form-block/src/schemaFormBlock/schema.js index 243bbb9..4e66723 100644 --- a/frontend/packages/volto-form-block/src/schemaFormBlock/schema.js +++ b/frontend/packages/volto-form-block/src/schemaFormBlock/schema.js @@ -48,6 +48,10 @@ const messages = defineMessages({ id: 'Admin Recipients', defaultMessage: 'Admin Recipients', }, + thankyou: { + id: 'thankyou', + defaultMessage: 'Thank you message', + }, recipients_description: { id: 'The email addresses the submitted form data will be sent to. Multiple email addresses can be entered separated by a semicolon.', defaultMessage: @@ -197,6 +201,7 @@ export const schemaFormBlockSchema = ({ intl, ...props }) => { 'description', 'submit_label', 'show_cancel', + 'thankyou', ...(data?.show_cancel ? ['cancel_label'] : []), 'captcha', ], @@ -256,6 +261,14 @@ export const schemaFormBlockSchema = ({ intl, ...props }) => { cancel_label: { title: intl.formatMessage(messages.cancel_label), }, + thankyou: { + title: intl.formatMessage(messages.thankyou), + widget: 'richtext', + type: 'string', + default: { + data: '

Send!

', + }, + }, captcha: { title: intl.formatMessage(messages.captcha), type: 'string',