From daa38ab846599d499bf0d991849a966763ec1127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Thu, 22 Feb 2024 14:14:49 +0300 Subject: [PATCH] feat(bigin-by-zoho-crm): add create company action --- .../actions/create-company/index.js | 161 ++++++++++++++++++ .../apps/bigin-by-zoho-crm/actions/index.js | 3 +- .../pages/apps/bigin-by-zoho-crm/actions.md | 2 + 3 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/bigin-by-zoho-crm/actions/create-company/index.js diff --git a/packages/backend/src/apps/bigin-by-zoho-crm/actions/create-company/index.js b/packages/backend/src/apps/bigin-by-zoho-crm/actions/create-company/index.js new file mode 100644 index 00000000..6b9eb3db --- /dev/null +++ b/packages/backend/src/apps/bigin-by-zoho-crm/actions/create-company/index.js @@ -0,0 +1,161 @@ +import defineAction from '../../../../helpers/define-action.js'; + +export default defineAction({ + name: 'Create company', + key: 'createCompany', + description: 'Creates a new company.', + arguments: [ + { + label: 'Company Owner', + key: 'companyOwnerId', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listContactOwners', + }, + ], + }, + }, + { + label: 'Company Name', + key: 'companyName', + type: 'string', + required: true, + description: '', + variables: true, + }, + { + label: 'Phone', + key: 'phone', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Website', + key: 'website', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Tags', + key: 'tags', + type: 'dynamic', + required: false, + description: '', + fields: [ + { + label: 'Tag', + key: 'tag', + type: 'string', + required: false, + variables: true, + }, + ], + }, + { + label: 'Description', + key: 'description', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Billing Street', + key: 'billingStreet', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Billing City', + key: 'billingCity', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Billing State', + key: 'billingState', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Billing Country', + key: 'billingCountry', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Billing Code', + key: 'billingCode', + type: 'string', + required: false, + description: '', + variables: true, + }, + ], + + async run($) { + const { + contactOwnerId, + companyName, + phone, + website, + tags, + description, + billingStreet, + billingCity, + billingState, + billingCountry, + billingCode, + } = $.step.parameters; + + const allTags = tags.map((tag) => ({ + name: tag.tag, + })); + + const body = { + data: [ + { + Owner: { + id: contactOwnerId, + }, + Account_Name: companyName, + Phone: phone, + Website: website, + Tag: allTags, + Description: description, + Billing_Street: billingStreet, + Billing_City: billingCity, + Billing_State: billingState, + Billing_Country: billingCountry, + Billing_Code: billingCode, + }, + ], + }; + + const { data } = await $.http.post(`/bigin/v2/Accounts`, body); + + $.setActionItem({ + raw: data[0], + }); + }, +}); diff --git a/packages/backend/src/apps/bigin-by-zoho-crm/actions/index.js b/packages/backend/src/apps/bigin-by-zoho-crm/actions/index.js index 156a5196..bbe2f7cb 100644 --- a/packages/backend/src/apps/bigin-by-zoho-crm/actions/index.js +++ b/packages/backend/src/apps/bigin-by-zoho-crm/actions/index.js @@ -1,4 +1,5 @@ +import createCompany from './create-company/index.js'; import createContact from './create-contact/index.js'; import createEvent from './create-event/index.js'; -export default [createContact, createEvent]; +export default [createCompany, createContact, createEvent]; diff --git a/packages/docs/pages/apps/bigin-by-zoho-crm/actions.md b/packages/docs/pages/apps/bigin-by-zoho-crm/actions.md index d8e3faf2..045f72d7 100644 --- a/packages/docs/pages/apps/bigin-by-zoho-crm/actions.md +++ b/packages/docs/pages/apps/bigin-by-zoho-crm/actions.md @@ -1,6 +1,8 @@ --- favicon: /favicons/bigin-by-zoho-crm.svg items: + - name: Create company + desc: Creates a new company. - name: Create contact desc: Creates a new contact. - name: Create event