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 6 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 @@ -81,7 +81,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
75 changes: 55 additions & 20 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 @@ -47,30 +46,56 @@ const messages = defineMessages({
id: 'form_send_email',
defaultMessage: 'Send email to recipient',
},
attachXml: {
id: 'form_attach_xml',
defaultMessage: 'Attach XML to email',
},
storedDataIds: {
id: 'form_stored_data_ids',
defaultMessage: 'Data ID mapping',
},
});

export default () => {
export default (formData) => {
var intl = useIntl();

const fieldsets = [
{
id: 'default',
title: 'Default',
fields: [
'title',
'description',
'default_to',
'default_from',
'default_subject',
'submit_label',
'captcha',
'store',
'send',
],
},
];

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',
'captcha',
'store',
'send',
],
},
],
fieldsets: fieldsets,
properties: {
title: {
title: intl.formatMessage(messages.title),
Expand Down Expand Up @@ -107,6 +132,16 @@ export default () => {
type: 'boolean',
title: intl.formatMessage(messages.send),
},
attachXml: {
type: 'boolean',
title: intl.formatMessage(messages.attachXml),
},
...Object.assign(
{},
...formData.subblocks.map((subblock) => {
return { [subblock.field_id]: { title: subblock.label } };
}),
),
},
required: ['default_to', 'default_from', 'default_subject'],
};
Expand Down