From ab5d8ce311536e37088a9d365e4df8827a5a04ea Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed Date: Fri, 13 May 2022 16:44:35 +0530 Subject: [PATCH] Refactor Mixin --- .../dashboard/helper/automationHelper.js | 11 ++++++++ .../mixins/automations/methodsMixin.js | 25 +++++-------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/javascript/dashboard/helper/automationHelper.js b/app/javascript/dashboard/helper/automationHelper.js index cfba2d382..9448a3f1e 100644 --- a/app/javascript/dashboard/helper/automationHelper.js +++ b/app/javascript/dashboard/helper/automationHelper.js @@ -76,3 +76,14 @@ export const getOperatorTypes = key => { return operatorMap[key] || OPERATOR_TYPES_1; }; + +export const generateCustomAttributeTypes = customAttributes => { + return customAttributes.map(attr => { + return { + key: attr.attribute_key, + name: attr.attribute_display_name, + inputType: getCustomAttributeInputType(attr.attribute_display_type), + filterOperators: getOperatorTypes(attr.attribute_display_type), + }; + }); +}; diff --git a/app/javascript/dashboard/mixins/automations/methodsMixin.js b/app/javascript/dashboard/mixins/automations/methodsMixin.js index 0db80e250..390f83785 100644 --- a/app/javascript/dashboard/mixins/automations/methodsMixin.js +++ b/app/javascript/dashboard/mixins/automations/methodsMixin.js @@ -10,6 +10,7 @@ import { isCustomAttributeCheckbox, isCustomAttributeList, getOperatorTypes, + generateCustomAttributeTypes, } from '../../helper/automationHelper.js'; const MESASAGE_CONDITION_VALUES = [ @@ -344,27 +345,13 @@ export default { 'attributes/getAttributesByModel' ]('contact_attribute'); - const conversationCustomAttributeTypes = conversationCustomAttributesRaw.map( - attr => { - return { - key: attr.attribute_key, - name: attr.attribute_display_name, - inputType: getCustomAttributeInputType(attr.attribute_display_type), - filterOperators: getOperatorTypes(attr.attribute_display_type), - }; - } + const conversationCustomAttributeTypes = generateCustomAttributeTypes( + conversationCustomAttributesRaw + ); + const contactCustomAttributeTypes = generateCustomAttributeTypes( + contactCustomAttributesRaw ); - const contactCustomAttributeTypes = contactCustomAttributesRaw.map( - attr => { - return { - key: attr.attribute_key, - name: attr.attribute_display_name, - inputType: getCustomAttributeInputType(attr.attribute_display_type), - filterOperators: getOperatorTypes(attr.attribute_display_type), - }; - } - ); const manifestedCustomAttributes = [ { key: 'conversation_custom_attribute',