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',