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

feature/mautic-extended #1311

Merged
merged 1 commit into from
Jan 23, 2021
Merged
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
72 changes: 72 additions & 0 deletions packages/nodes-base/nodes/Mautic/ContactDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,42 @@ export const contactFields = [
type: 'string',
default: '',
},
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Fields',
description: 'Adds a custom fields to set also values which have not been predefined.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'customFieldValues',
displayName: 'Field',
values: [
{
displayName: 'Field ID',
name: 'fieldId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getContactFields',
},
default: '',
description: 'ID of the field to set.',
},
{
displayName: 'Field Value',
name: 'fieldValue',
type: 'string',
default: '',
description: 'Value of the field to set.',
},
],
},
],
},
{
displayName: 'Fax',
name: 'fax',
Expand Down Expand Up @@ -617,6 +653,42 @@ export const contactFields = [
},
default: '',
},
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Fields',
description: 'Adds a custom fields to set also values which have not been predefined.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'customFieldValues',
displayName: 'Field',
values: [
{
displayName: 'Field ID',
name: 'fieldId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getContactFields',
},
default: '',
description: 'ID of the field to set.',
},
{
displayName: 'Field Value',
name: 'fieldValue',
type: 'string',
default: '',
description: 'Value of the field to set.',
},
],
},
],
},
{
displayName: 'Email',
name: 'email',
Expand Down
27 changes: 27 additions & 0 deletions packages/nodes-base/nodes/Mautic/Mautic.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ export class Mautic implements INodeType {
}
return returnData;
},
// Get all the available contact fields to display them to user so that he can
// select them easily
async getContactFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const fields = await mauticApiRequestAllItems.call(this, 'fields', 'GET', '/fields/contact');
for (const field of fields) {
returnData.push({
name: field.label,
value: field.alias,
});
}
return returnData;
},
},
};

Expand Down Expand Up @@ -327,6 +340,13 @@ export class Mautic implements INodeType {
body.twitter = socialMediaValues.twitter as string;
}
}
if (additionalFields.customFieldsUi) {
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
if (customFields) {
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
Object.assign(body, data);
}
}
if (additionalFields.b2bOrb2c) {
body.b2b_or_b2c = additionalFields.b2bOrb2c as string;
}
Expand Down Expand Up @@ -429,6 +449,13 @@ export class Mautic implements INodeType {
body.twitter = socialMediaValues.twitter as string;
}
}
if (updateFields.customFieldsUi) {
const customFields = (updateFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
if (customFields) {
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
Object.assign(body, data);
}
}
if (updateFields.b2bOrb2c) {
body.b2b_or_b2c = updateFields.b2bOrb2c as string;
}
Expand Down