2021-10-30 01:39:46 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
2022-02-07 07:34:27 +00:00
|
|
|
import { isValidURL } from '../helper/URLHelper';
|
2021-10-30 01:39:46 +00:00
|
|
|
export default {
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
currentChat: 'getSelectedChat',
|
|
|
|
accountId: 'getCurrentAccountId',
|
|
|
|
}),
|
|
|
|
attributes() {
|
|
|
|
return this.$store.getters['attributes/getAttributesByModel'](
|
2021-11-11 09:53:33 +00:00
|
|
|
this.attributeType
|
2021-10-30 01:39:46 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
customAttributes() {
|
2021-11-11 09:53:33 +00:00
|
|
|
if (this.attributeType === 'conversation_attribute')
|
|
|
|
return this.currentChat.custom_attributes || {};
|
|
|
|
return this.contact.custom_attributes || {};
|
|
|
|
},
|
|
|
|
contactIdentifier() {
|
|
|
|
return (
|
|
|
|
this.currentChat.meta?.sender?.id ||
|
|
|
|
this.$route.params.contactId ||
|
|
|
|
this.contactId
|
|
|
|
);
|
|
|
|
},
|
|
|
|
contact() {
|
|
|
|
return this.$store.getters['contacts/getContact'](this.contactIdentifier);
|
2021-10-30 01:39:46 +00:00
|
|
|
},
|
|
|
|
conversationId() {
|
|
|
|
return this.currentChat.id;
|
|
|
|
},
|
2021-11-15 09:26:35 +00:00
|
|
|
|
2021-10-30 01:39:46 +00:00
|
|
|
filteredAttributes() {
|
2021-11-11 09:53:33 +00:00
|
|
|
return Object.keys(this.customAttributes).map(key => {
|
|
|
|
const item = this.attributes.find(
|
|
|
|
attribute => attribute.attribute_key === key
|
|
|
|
);
|
|
|
|
if (item) {
|
2021-10-30 01:39:46 +00:00
|
|
|
return {
|
|
|
|
...item,
|
|
|
|
value: this.customAttributes[key],
|
|
|
|
};
|
2021-11-11 09:53:33 +00:00
|
|
|
}
|
2021-11-15 09:26:35 +00:00
|
|
|
|
2021-11-11 09:53:33 +00:00
|
|
|
return {
|
|
|
|
...item,
|
|
|
|
value: this.customAttributes[key],
|
|
|
|
attribute_description: key,
|
|
|
|
attribute_display_name: key,
|
2021-11-15 09:26:35 +00:00
|
|
|
attribute_display_type: this.attributeDisplayType(
|
|
|
|
this.customAttributes[key]
|
|
|
|
),
|
2021-11-11 09:53:33 +00:00
|
|
|
attribute_key: key,
|
|
|
|
attribute_model: this.attributeType,
|
|
|
|
id: Math.random(),
|
|
|
|
};
|
|
|
|
});
|
2021-10-30 01:39:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2021-11-15 09:26:35 +00:00
|
|
|
isAttributeNumber(attributeValue) {
|
|
|
|
return (
|
|
|
|
Number.isInteger(Number(attributeValue)) && Number(attributeValue) > 0
|
|
|
|
);
|
|
|
|
},
|
|
|
|
attributeDisplayType(attributeValue) {
|
|
|
|
if (this.isAttributeNumber(attributeValue)) {
|
|
|
|
return 'number';
|
|
|
|
}
|
2022-02-07 07:34:27 +00:00
|
|
|
if (isValidURL(attributeValue)) {
|
2021-11-15 09:26:35 +00:00
|
|
|
return 'link';
|
2021-10-30 01:39:46 +00:00
|
|
|
}
|
2021-11-15 09:26:35 +00:00
|
|
|
return 'text';
|
2021-10-30 01:39:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|