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

XML Sending and custom field mapping #52

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,15 @@ const View = ({ data, id, path }) => {
const captchaToken = useRef();

const onChangeFormData = (field_id, field, value, extras) => {
setFormData({ field, value: { field_id, value, ...extras } });
setFormData({
field,
value: {
field_id,
value,
...(data[field_id] && { custom_field_id: data[field_id] }), // Conditionally add the key. Nicer to work with than having a key with a null value
...extras,
},
});
};

useEffect(() => {
Expand Down
87 changes: 63 additions & 24 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 @@ -75,6 +74,14 @@ const messages = defineMessages({
id: 'form_manage_data',
defaultMessage: 'Manage data',
},
attachXml: {
id: 'form_attach_xml',
defaultMessage: 'Attach XML to email',
},
storedDataIds: {
id: 'form_stored_data_ids',
defaultMessage: 'Data ID mapping',
},
});

const Schema = (data) => {
Expand All @@ -86,30 +93,48 @@ const Schema = (data) => {
conditional_required.push('send');
}

const fieldsets = [
{
id: 'default',
title: 'Default',
fields: [
'title',
'description',
'default_to',
'default_from',
'default_subject',
'submit_label',
'show_cancel',
...(data?.show_cancel ? ['cancel_label'] : []),
'captcha',
],
},
{
id: 'manage_data',
title: intl.formatMessage(messages.manage_data),
fields: ['store', 'remove_data_after_days', 'send', 'send_message'],
},
];

if (formData?.send) {
fieldsets.push({
id: 'sendingOptions',
title: 'Sending options',
fields: ['attachXml'],
});
}

if (formData?.send || formData?.store) {
fieldsets.push({
id: 'storedDataIds',
title: intl.formatMessage(messages.storedDataIds),
fields: formData?.subblocks?.map((subblock) => subblock.field_id),
});
}

return {
title: intl.formatMessage(messages.form),
fieldsets: [
{
id: 'default',
title: 'Default',
fields: [
'title',
'description',
'default_to',
'default_from',
'default_subject',
'submit_label',
'show_cancel',
...(data?.show_cancel ? ['cancel_label'] : []),
'captcha',
],
},
{
id: 'manage_data',
title: intl.formatMessage(messages.manage_data),
fields: ['store', 'remove_data_after_days', 'send', 'send_message'],
},
],
fieldsets: fieldsets,
properties: {
title: {
title: intl.formatMessage(messages.title),
Expand Down Expand Up @@ -167,6 +192,19 @@ const Schema = (data) => {
type: 'textarea',
description: intl.formatMessage(messages.send_message_helptext),
},
attachXml: {
type: 'boolean',
title: intl.formatMessage(messages.attachXml),
},
// Add properties for each of the fields for use in the data mapping
...(formData?.subblocks
? Object.assign(
{},
...formData?.subblocks?.map((subblock) => {
return { [subblock.field_id]: { title: subblock.label } };
}),
)
: {}),
},
required: [
'default_to',
Expand All @@ -177,4 +215,5 @@ const Schema = (data) => {
],
};
};

export default Schema;