From d8d622712593d92db0eced39a6b174d1f587077a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Wed, 17 Jan 2024 11:01:01 +0300 Subject: [PATCH] feat(vtiger-crm): add create lead action --- .../vtiger-crm/actions/create-lead/fields.js | 395 ++++++++++++++++++ .../vtiger-crm/actions/create-lead/index.js | 88 ++++ .../src/apps/vtiger-crm/actions/index.js | 3 +- .../src/apps/vtiger-crm/dynamic-data/index.js | 2 + .../dynamic-data/list-lead-options/index.js | 56 +++ .../docs/pages/apps/vtiger-crm/actions.md | 2 + 6 files changed, 545 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/vtiger-crm/actions/create-lead/fields.js create mode 100644 packages/backend/src/apps/vtiger-crm/actions/create-lead/index.js create mode 100644 packages/backend/src/apps/vtiger-crm/dynamic-data/list-lead-options/index.js diff --git a/packages/backend/src/apps/vtiger-crm/actions/create-lead/fields.js b/packages/backend/src/apps/vtiger-crm/actions/create-lead/fields.js new file mode 100644 index 00000000..f8f28e20 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/actions/create-lead/fields.js @@ -0,0 +1,395 @@ +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: 'Company', + key: 'company', + type: 'string', + required: false, + 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: 'Designation', + key: 'designation', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listLeadOptions', + }, + { + name: 'parameters.designation', + value: 'designation', + }, + ], + }, + }, + { + label: 'Mobile Phone', + key: 'mobilePhone', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Industry', + key: 'industry', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listLeadOptions', + }, + { + name: 'parameters.industry', + value: 'industry', + }, + ], + }, + }, + { + label: 'Website', + key: 'website', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Annual Revenue', + key: 'annualRevenue', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Lead Source', + key: 'leadSource', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listLeadOptions', + }, + { + name: 'parameters.leadSource', + value: 'leadsource', + }, + ], + }, + }, + { + label: 'Lead Status', + key: 'leadStatus', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listLeadOptions', + }, + { + name: 'parameters.leadStatus', + value: 'leadstatus', + }, + ], + }, + }, + { + label: 'Assigned To', + key: 'assignedTo', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Fax', + key: 'fax', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Number of Employees', + key: 'numberOfEmployees', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Twitter Username', + key: 'twitterUsername', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Record Currency', + key: 'recordCurrency', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listRecordCurrencies', + }, + ], + }, + }, + { + label: 'Email Opt-in', + key: 'emailOptin', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listLeadOptions', + }, + { + 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: 'listLeadOptions', + }, + { + 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: 'listLeadOptions', + }, + { + 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: 'Country', + key: 'country', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listLeadOptions', + }, + { + name: 'parameters.country', + value: 'country', + }, + ], + }, + }, + { + label: 'Street', + key: 'street', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'PO Box', + key: 'poBox', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Postal Code', + key: 'postalCode', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'City', + key: 'city', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'State', + key: 'state', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listLeadOptions', + }, + { + name: 'parameters.state', + value: 'state', + }, + ], + }, + }, + { + label: 'Description', + key: 'description', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Lead Image', + key: 'leadImage', + type: 'string', + required: false, + description: '', + variables: true, + }, +]; diff --git a/packages/backend/src/apps/vtiger-crm/actions/create-lead/index.js b/packages/backend/src/apps/vtiger-crm/actions/create-lead/index.js new file mode 100644 index 00000000..95d4a32f --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/actions/create-lead/index.js @@ -0,0 +1,88 @@ +import defineAction from '../../../../helpers/define-action.js'; +import { fields } from './fields.js'; + +export default defineAction({ + name: 'Create lead', + key: 'createLead', + description: 'Create a new lead.', + arguments: fields, + + async run($) { + const { + salutation, + firstName, + lastName, + company, + primaryEmail, + officePhone, + designation, + mobilePhone, + industry, + website, + annualRevenue, + leadSource, + leadStatus, + assignedTo, + fax, + numberOfEmployees, + twitterUsername, + recordCurrency, + emailOptin, + smsOptin, + language, + sourceCampaign, + country, + street, + poBox, + postalCode, + city, + state, + description, + leadImage, + } = $.step.parameters; + + const elementData = { + salutationtype: salutation, + firstname: firstName, + lastname: lastName, + company: company, + email: primaryEmail, + phone: officePhone, + designation: designation, + mobile: mobilePhone, + industry: industry, + website: website, + annualrevenue: annualRevenue, + leadsource: leadSource, + leadstatus: leadStatus, + assigned_user_id: assignedTo || $.auth.data.userId, + fax: fax, + noofemployees: numberOfEmployees, + primary_twitter: twitterUsername, + record_currency_id: recordCurrency, + emailoptin: emailOptin, + smsoptin: smsOptin, + language: language, + source_campaign: sourceCampaign, + country: country, + lane: street, + pobox: poBox, + code: postalCode, + city: city, + state: state, + description: description, + imagename: leadImage, + }; + + const body = { + operation: 'create', + sessionName: $.auth.data.sessionName, + element: JSON.stringify(elementData), + elementType: 'Leads', + }; + + 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 b2a966c4..ec1e52f9 100644 --- a/packages/backend/src/apps/vtiger-crm/actions/index.js +++ b/packages/backend/src/apps/vtiger-crm/actions/index.js @@ -1,4 +1,5 @@ +import createLead from './create-lead/index.js'; import createOpportunity from './create-opportunity/index.js'; import createTodo from './create-todo/index.js'; -export default [createOpportunity, createTodo]; +export default [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 7f991f6a..7b55a1b6 100644 --- a/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/index.js @@ -1,5 +1,6 @@ import listCampaignSources from './list-campaign-sources/index.js'; import listContacts from './list-contacts/index.js'; +import listLeadOptions from './list-lead-options/index.js'; import listMilestones from './list-milestones/index.js'; import listOpportunityOptions from './list-opportunity-options/index.js'; import listOrganizations from './list-organizations/index.js'; @@ -13,6 +14,7 @@ import listTodoOptions from './list-todo-options/index.js'; export default [ listCampaignSources, listContacts, + listLeadOptions, listMilestones, listOpportunityOptions, listOrganizations, diff --git a/packages/backend/src/apps/vtiger-crm/dynamic-data/list-lead-options/index.js b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-lead-options/index.js new file mode 100644 index 00000000..bd7ab650 --- /dev/null +++ b/packages/backend/src/apps/vtiger-crm/dynamic-data/list-lead-options/index.js @@ -0,0 +1,56 @@ +export default { + name: 'List lead options', + key: 'listLeadOptions', + + async run($) { + const leadOptions = { + data: [], + }; + const { + designation, + industry, + leadSource, + leadStatus, + emailOptin, + smsOptin, + language, + country, + state, + } = $.step.parameters; + + const picklistFields = [ + designation, + industry, + leadSource, + leadStatus, + emailOptin, + smsOptin, + language, + country, + state, + ]; + + const params = { + operation: 'describe', + sessionName: $.auth.data.sessionName, + elementType: 'Leads', + }; + + 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 3d335f57..4fe54e66 100644 --- a/packages/docs/pages/apps/vtiger-crm/actions.md +++ b/packages/docs/pages/apps/vtiger-crm/actions.md @@ -5,6 +5,8 @@ items: desc: Create a new opportunity. - name: Create todo desc: Create a new todo. + - name: Create lead + desc: Create a new lead. ---