From a6cc1566c798969448daddaeedec7b9df889f156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Wed, 17 Jan 2024 11:13:32 +0300 Subject: [PATCH] feat(vtiger-crm): add create contact action --- .../actions/create-contact/fields.js | 649 ++++++++++++++++++ .../actions/create-contact/index.js | 129 ++++ .../src/apps/vtiger-crm/actions/index.js | 3 +- .../src/apps/vtiger-crm/dynamic-data/index.js | 2 + .../list-contact-options/index.js | 62 ++ .../docs/pages/apps/vtiger-crm/actions.md | 2 + 6 files changed, 846 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/vtiger-crm/actions/create-contact/fields.js create mode 100644 packages/backend/src/apps/vtiger-crm/actions/create-contact/index.js create mode 100644 packages/backend/src/apps/vtiger-crm/dynamic-data/list-contact-options/index.js diff --git a/packages/backend/src/apps/vtiger-crm/actions/create-contact/fields.js b/packages/backend/src/apps/vtiger-crm/actions/create-contact/fields.js new file mode 100644 index 00000000..b4b72e18 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/actions/create-contact/fields.js @@ -0,0 +1,649 @@ +export const fields = [ + { + label: 'Salutation', + key: 'salutation', + type: 'dropdown', + required: false, + description: '', + variables: true, + options: [ + { label: 'Mr.', value: 'Mr.' }, + { label: 'Ms.', value: 'Ms.' }, + { label: 'Mrs.', value: 'Mrs.' }, + { label: 'Dr.', value: 'Dr.' }, + { label: 'Prof.', value: 'Prof.' }, + ], + }, + { + label: 'First Name', + key: 'firstName', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Last Name', + key: 'lastName', + type: 'string', + required: true, + description: '', + variables: true, + }, + { + label: 'Primary Email', + key: 'primaryEmail', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Office Phone', + key: 'officePhone', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Mobile Phone', + key: 'mobilePhone', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Home Phone', + key: 'homePhone', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Date of Birth', + key: 'dateOfBirth', + type: 'string', + required: false, + description: 'format: yyyy-mm-dd', + variables: true, + }, + { + label: 'Fax', + key: 'fax', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Organization Name', + key: 'organizationName', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listOrganizations', + }, + ], + }, + }, + { + label: 'Title', + key: 'title', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.title', + value: 'listContactOptions', + }, + ], + }, + }, + { + label: 'Department', + key: 'department', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Reports To', + key: 'reportsTo', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContacts', + }, + ], + }, + }, + { + label: 'Lead Source', + key: 'leadSource', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.leadSource', + value: 'leadsource', + }, + ], + }, + }, + { + label: 'Secondary Email', + key: 'secondaryEmail', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Assigned To', + key: 'assignedTo', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Do Not Call', + key: 'doNotCall', + type: 'dropdown', + required: false, + description: '', + variables: true, + options: [ + { label: 'True', value: '1' }, + { label: 'False', value: '-1' }, + ], + }, + { + label: 'Notify Owner', + key: 'notifyOwner', + type: 'dropdown', + required: false, + description: '', + variables: true, + options: [ + { label: 'True', value: '1' }, + { label: 'False', value: '-1' }, + ], + }, + { + label: 'Twitter Username', + key: 'twitterUsername', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'SLA Name', + key: 'slaName', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listSlaNames', + }, + ], + }, + }, + { + label: 'Lifecycle Stage', + key: 'lifecycleStage', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.lifecycleStage', + value: 'contacttype', + }, + ], + }, + }, + { + label: 'Status', + key: 'status', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.status', + value: 'contactstatus', + }, + ], + }, + }, + { + label: 'Happiness Rating', + key: 'happinessRating', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.happinessRating', + value: 'happiness_rating', + }, + ], + }, + }, + { + label: 'Record Currency', + key: 'recordCurrency', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listRecordCurrencies', + }, + ], + }, + }, + { + label: 'Referred By', + key: 'referredBy', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContacts', + }, + ], + }, + }, + { + label: 'Email Opt-in', + key: 'emailOptin', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.emailOptin', + value: 'emailoptin', + }, + ], + }, + }, + { + label: 'SMS Opt-in', + key: 'smsOptin', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.smsOptin', + value: 'smsoptin', + }, + ], + }, + }, + { + label: 'Language', + key: 'language', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.language', + value: 'language', + }, + ], + }, + }, + { + label: 'Source Campaign', + key: 'sourceCampaign', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listCampaignSources', + }, + ], + }, + }, + { + label: 'Portal User', + key: 'portalUser', + type: 'dropdown', + required: false, + description: '', + variables: true, + options: [ + { label: 'True', value: '1' }, + { label: 'False', value: '-1' }, + ], + }, + { + label: 'Support Start Date', + key: 'supportStartDate', + type: 'string', + required: false, + description: 'format: yyyy-mm-dd', + variables: true, + }, + { + label: 'Support End Date', + key: 'supportEndDate', + type: 'string', + required: false, + description: 'format: yyyy-mm-dd', + variables: true, + }, + { + label: 'Other Country', + key: 'otherCountry', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.otherCountry', + value: 'othercountry', + }, + ], + }, + }, + { + label: 'Mailing Country', + key: 'mailingCountry', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.mailingCountry', + value: 'mailingcountry', + }, + ], + }, + }, + { + label: 'Mailing Street', + key: 'mailingStreet', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Other Street', + key: 'otherStreet', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Mailing PO Box', + key: 'mailingPoBox', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Other PO Box', + key: 'otherPoBox', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Mailing City', + key: 'mailingCity', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Other City', + key: 'otherCity', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Mailing State', + key: 'mailingState', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.mailingState', + value: 'mailingstate', + }, + ], + }, + }, + { + label: 'Other State', + key: 'otherState', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOptions', + }, + { + name: 'parameters.otherState', + value: 'otherstate', + }, + ], + }, + }, + { + label: 'Mailing Zip', + key: 'mailingZip', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Other Zip', + key: 'otherZip', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Description', + key: 'description', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Contact Image', + key: 'contactImage', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Linkedin URL', + key: 'linkedinUrl', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Linkedin Followers', + key: 'linkedinFollowers', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Facebook URL', + key: 'facebookUrl', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Facebook Followers', + key: 'facebookFollowers', + type: 'string', + required: false, + description: '', + variables: true, + }, +]; diff --git a/packages/backend/src/apps/vtiger-crm/actions/create-contact/index.js b/packages/backend/src/apps/vtiger-crm/actions/create-contact/index.js new file mode 100644 index 00000000..35722c4d --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/actions/create-contact/index.js @@ -0,0 +1,129 @@ +import defineAction from '../../../../helpers/define-action.js'; +import { fields } from './fields.js'; + +export default defineAction({ + name: 'Create contact', + key: 'createContact', + description: 'Create a new contact.', + arguments: fields, + + async run($) { + const { + salutation, + firstName, + lastName, + primaryEmail, + officePhone, + mobilePhone, + homePhone, + dateOfBirth, + fax, + organizationName, + title, + department, + reportsTo, + leadSource, + secondaryEmail, + assignedTo, + doNotCall, + notifyOwner, + twitterUsername, + slaName, + lifecycleStage, + status, + happinessRating, + recordCurrency, + referredBy, + emailOptin, + smsOptin, + language, + sourceCampaign, + portalUser, + supportStartDate, + supportEndDate, + otherCountry, + mailingCountry, + mailingStreet, + otherStreet, + mailingPoBox, + otherPoBox, + mailingCity, + otherCity, + mailingState, + otherState, + mailingZip, + otherZip, + description, + contactImage, + linkedinUrl, + linkedinFollowers, + facebookUrl, + facebookFollowers, + } = $.step.parameters; + + const elementData = { + salutationtype: salutation, + firstname: firstName, + lastname: lastName, + email: primaryEmail, + phone: officePhone, + mobile: mobilePhone, + homephone: homePhone, + birthday: dateOfBirth, + fax: fax, + account_id: organizationName, + title: title, + department: department, + contact_id: reportsTo, + leadsource: leadSource, + secondaryemail: secondaryEmail, + assigned_user_id: assignedTo || $.auth.data.userId, + donotcall: doNotCall, + notify_owner: notifyOwner, + emailoptout: emailOptin, + primary_twitter: twitterUsername, + slaid: slaName, + contacttype: lifecycleStage, + contactstatus: status, + happiness_rating: happinessRating, + record_currency_id: recordCurrency, + referred_by: referredBy, + emailoptin: emailOptin, + smsoptin: smsOptin, + language: language, + source_campaign: sourceCampaign, + portal: portalUser, + support_start_date: supportStartDate, + support_end_date: supportEndDate, + othercountry: otherCountry, + mailingcountry: mailingCountry, + mailingstreet: mailingStreet, + otherstreet: otherStreet, + mailingpobox: mailingPoBox, + otherpobox: otherPoBox, + mailingcity: mailingCity, + othercity: otherCity, + mailingstate: mailingState, + otherstate: otherState, + mailingzip: mailingZip, + otherzip: otherZip, + description: description, + imagename: contactImage, + primary_linkedin: linkedinUrl, + followers_linkedin: linkedinFollowers, + primary_facebook: facebookUrl, + followers_facebook: facebookFollowers, + }; + + const body = { + operation: 'create', + sessionName: $.auth.data.sessionName, + element: JSON.stringify(elementData), + elementType: 'Contacts', + }; + + const response = await $.http.post('/webservice.php', body); + + $.setActionItem({ raw: response.data }); + }, +}); diff --git a/packages/backend/src/apps/vtiger-crm/actions/index.js b/packages/backend/src/apps/vtiger-crm/actions/index.js index ec1e52f9..48fe4fc1 100644 --- a/packages/backend/src/apps/vtiger-crm/actions/index.js +++ b/packages/backend/src/apps/vtiger-crm/actions/index.js @@ -1,5 +1,6 @@ +import createContact from './create-contact/index.js'; import createLead from './create-lead/index.js'; import createOpportunity from './create-opportunity/index.js'; import createTodo from './create-todo/index.js'; -export default [createLead, createOpportunity, createTodo]; +export default [createContact, createLead, createOpportunity, createTodo]; diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js index 7b55a1b6..f183c9d9 100644 --- a/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js @@ -1,4 +1,5 @@ import listCampaignSources from './list-campaign-sources/index.js'; +import listContactOptions from './list-contact-options/index.js'; import listContacts from './list-contacts/index.js'; import listLeadOptions from './list-lead-options/index.js'; import listMilestones from './list-milestones/index.js'; @@ -13,6 +14,7 @@ import listTodoOptions from './list-todo-options/index.js'; export default [ listCampaignSources, + listContactOptions, listContacts, listLeadOptions, listMilestones, diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/list-contact-options/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-contact-options/index.js new file mode 100644 index 00000000..e27257d4 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-contact-options/index.js @@ -0,0 +1,62 @@ +export default { + name: 'List contact options', + key: 'listContactOptions', + + async run($) { + const leadOptions = { + data: [], + }; + const { + leadSource, + lifecycleStage, + status, + title, + happinessRating, + emailOptin, + smsOptin, + language, + otherCountry, + mailingCountry, + mailingState, + otherState, + } = $.step.parameters; + + const picklistFields = [ + leadSource, + lifecycleStage, + status, + title, + happinessRating, + emailOptin, + smsOptin, + language, + otherCountry, + mailingCountry, + mailingState, + otherState, + ]; + + const params = { + operation: 'describe', + sessionName: $.auth.data.sessionName, + elementType: 'Contacts', + }; + + const { data } = await $.http.get(`/webservice.php`, { params }); + + if (data.result.fields?.length) { + for (const field of data.result.fields) { + if (picklistFields.includes(field.name)) { + field.type.picklistValues.map((item) => + leadOptions.data.push({ + value: item.value, + name: item.label, + }) + ); + } + } + } + + return leadOptions; + }, +}; diff --git a/packages/docs/pages/apps/vtiger-crm/actions.md b/packages/docs/pages/apps/vtiger-crm/actions.md index 4fe54e66..6494da09 100644 --- a/packages/docs/pages/apps/vtiger-crm/actions.md +++ b/packages/docs/pages/apps/vtiger-crm/actions.md @@ -1,6 +1,8 @@ --- favicon: /favicons/vtiger-crm.svg items: + - name: Create contact + desc: Create a new contact. - name: Create opportunity desc: Create a new opportunity. - name: Create todo