Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sending a custom acknowledgement message to the person submitting this form #57

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
46 changes: 40 additions & 6 deletions src/formSchema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineMessages } from 'react-intl';
import { useIntl } from 'react-intl';
import { defineMessages, useIntl } from 'react-intl';

const messages = defineMessages({
form: {
Expand Down Expand Up @@ -45,12 +44,23 @@ const messages = defineMessages({
},
send: {
id: 'form_send_email',
defaultMessage: 'Send email to recipient',
defaultMessage: 'Send email to',
},
send_acknowledgement_field_description: {
id: 'form_send_acknowledgement_field_description',
defaultMessage:
'Select which fields will contain an email address to send an acknowledgement to.',
},
});

export default () => {
export default (formData) => {
var intl = useIntl();
const emailFields =
formData?.subblocks?.reduce((acc, field) => {
return ['from', 'email'].includes(field.field_type)
? [...acc, [field.id, field.label]]
: acc;
}, []) ?? [];

return {
title: intl.formatMessage(messages.form),
Expand All @@ -68,6 +78,11 @@ export default () => {
'captcha',
'store',
'send',
...(formData?.send &&
Array.isArray(formData.send) &&
formData.send.includes('acknowledgement')
? ['acknowledgementFields', 'acknowledgementMessage']
: []),
],
},
],
Expand Down Expand Up @@ -101,11 +116,30 @@ export default () => {
store: {
type: 'boolean',
title: intl.formatMessage(messages.store),
description: intl.formatMessage(messages.attachmentSendEmail),
},
send: {
type: 'boolean',
title: intl.formatMessage(messages.send),
description: intl.formatMessage(messages.attachmentSendEmail),
isMulti: 'true',
default: 'recipient',
choices: [
['recipient', 'Recipient'],
['acknowledgement', 'Acknowledgement'],
],
},
acknowledgementMessage: {
// TODO: i18n
title: 'Acknowledgement message',
widget: 'richtext',
},
acknowledgementFields: {
// TODO: i18n
title: 'Acknowledgement field',
description: intl.formatMessage(messages.send_acknowledgement_field_description),
isMulti: false,
noValueOption: false,
choices: formData?.subblocks ? emailFields : [],
...(emailFields.length === 1 && { default: emailFields[0][0] }),
},
},
required: ['default_to', 'default_from', 'default_subject'],
Expand Down