Compare commits

...
15 changed files with 281 additions and 146 deletions
+8 -2
View File
@@ -3,7 +3,7 @@ import { mapGetters, mapActions } from 'vuex';
import { setHeader } from 'widget/helpers/axios'; import { setHeader } from 'widget/helpers/axios';
import addHours from 'date-fns/addHours'; import addHours from 'date-fns/addHours';
import { IFrameHelper, RNHelper } from 'widget/helpers/utils'; import { IFrameHelper, RNHelper } from 'widget/helpers/utils';
import configMixin from './mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import availabilityMixin from 'widget/mixins/availability'; import availabilityMixin from 'widget/mixins/availability';
import { getLocale } from './helpers/urlParamsHelper'; import { getLocale } from './helpers/urlParamsHelper';
import { isEmptyObject } from 'widget/helpers/utils'; import { isEmptyObject } from 'widget/helpers/utils';
@@ -27,7 +27,13 @@ export default {
components: { components: {
Spinner, Spinner,
}, },
mixins: [availabilityMixin, configMixin, routerMixin, darkModeMixin], mixins: [availabilityMixin, routerMixin, darkModeMixin],
setup() {
const { shouldShowPreChatForm } = useConfig();
return {
shouldShowPreChatForm,
};
},
data() { data() {
return { return {
isMobile: false, isMobile: false,
@@ -8,8 +8,8 @@ import VideoBubble from 'widget/components/VideoBubble.vue';
import FileBubble from 'widget/components/FileBubble.vue'; import FileBubble from 'widget/components/FileBubble.vue';
import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue'; import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue';
import { MESSAGE_TYPE } from 'widget/helpers/constants'; import { MESSAGE_TYPE } from 'widget/helpers/constants';
import configMixin from '../mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import messageMixin from '../mixins/messageMixin'; import { useMessage } from '../composables/useMessage';
import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper'; import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper';
import darkModeMixin from 'widget/mixins/darkModeMixin.js'; import darkModeMixin from 'widget/mixins/darkModeMixin.js';
import ReplyToChip from 'widget/components/ReplyToChip.vue'; import ReplyToChip from 'widget/components/ReplyToChip.vue';
@@ -28,7 +28,7 @@ export default {
MessageReplyButton, MessageReplyButton,
ReplyToChip, ReplyToChip,
}, },
mixins: [configMixin, messageMixin, darkModeMixin], mixins: [darkModeMixin],
props: { props: {
message: { message: {
type: Object, type: Object,
@@ -39,6 +39,19 @@ export default {
default: () => {}, default: () => {},
}, },
}, },
setup(props) {
const { messageContentAttributes, hasAttachments } = useMessage(
props.message
);
const { useInboxAvatarForBot, inboxAvatarUrl, channelConfig } = useConfig();
return {
messageContentAttributes,
hasAttachments,
useInboxAvatarForBot,
inboxAvatarUrl,
channelConfig,
};
},
data() { data() {
return { return {
hasImageError: false, hasImageError: false,
@@ -3,7 +3,7 @@ import { mapGetters } from 'vuex';
import ChatAttachmentButton from 'widget/components/ChatAttachment.vue'; import ChatAttachmentButton from 'widget/components/ChatAttachment.vue';
import ChatSendButton from 'widget/components/ChatSendButton.vue'; import ChatSendButton from 'widget/components/ChatSendButton.vue';
import configMixin from '../mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import FluentIcon from 'shared/components/FluentIcon/Index.vue'; import FluentIcon from 'shared/components/FluentIcon/Index.vue';
import ResizableTextArea from 'shared/components/ResizableTextArea.vue'; import ResizableTextArea from 'shared/components/ResizableTextArea.vue';
import darkModeMixin from 'widget/mixins/darkModeMixin.js'; import darkModeMixin from 'widget/mixins/darkModeMixin.js';
@@ -19,7 +19,7 @@ export default {
FluentIcon, FluentIcon,
ResizableTextArea, ResizableTextArea,
}, },
mixins: [configMixin, darkModeMixin], mixins: [darkModeMixin],
props: { props: {
onSendMessage: { onSendMessage: {
type: Function, type: Function,
@@ -30,7 +30,13 @@ export default {
default: () => {}, default: () => {},
}, },
}, },
setup() {
const { hasEmojiPickerEnabled, hasAttachmentsEnabled } = useConfig();
return {
hasEmojiPickerEnabled,
hasAttachmentsEnabled,
};
},
data() { data() {
return { return {
userInput: '', userInput: '',
@@ -4,13 +4,13 @@ import { IFrameHelper, RNHelper } from 'widget/helpers/utils';
import { popoutChatWindow } from '../helpers/popoutHelper'; import { popoutChatWindow } from '../helpers/popoutHelper';
import FluentIcon from 'shared/components/FluentIcon/Index.vue'; import FluentIcon from 'shared/components/FluentIcon/Index.vue';
import darkModeMixin from 'widget/mixins/darkModeMixin'; import darkModeMixin from 'widget/mixins/darkModeMixin';
import configMixin from 'widget/mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import { CONVERSATION_STATUS } from 'shared/constants/messages'; import { CONVERSATION_STATUS } from 'shared/constants/messages';
export default { export default {
name: 'HeaderActions', name: 'HeaderActions',
components: { FluentIcon }, components: { FluentIcon },
mixins: [configMixin, darkModeMixin], mixins: [darkModeMixin],
props: { props: {
showPopoutButton: { showPopoutButton: {
type: Boolean, type: Boolean,
@@ -21,6 +21,12 @@ export default {
default: true, default: true,
}, },
}, },
setup() {
const { hasEndConversationEnabled } = useConfig();
return {
hasEndConversationEnabled,
};
},
computed: { computed: {
...mapGetters({ ...mapGetters({
conversationAttributes: 'conversationAttributes/getConversationParams', conversationAttributes: 'conversationAttributes/getConversationParams',
@@ -8,14 +8,14 @@ import { getRegexp } from 'shared/helpers/Validators';
import { useMessageFormatter } from 'shared/composables/useMessageFormatter'; import { useMessageFormatter } from 'shared/composables/useMessageFormatter';
import routerMixin from 'widget/mixins/routerMixin'; import routerMixin from 'widget/mixins/routerMixin';
import darkModeMixin from 'widget/mixins/darkModeMixin'; import darkModeMixin from 'widget/mixins/darkModeMixin';
import configMixin from 'widget/mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
export default { export default {
components: { components: {
CustomButton, CustomButton,
Spinner, Spinner,
}, },
mixins: [routerMixin, darkModeMixin, configMixin], mixins: [routerMixin, darkModeMixin, messageFormatterMixin],
props: { props: {
options: { options: {
type: Object, type: Object,
@@ -23,8 +23,10 @@ export default {
}, },
}, },
setup() { setup() {
const { preChatFormEnabled } = useConfig();
const { formatMessage } = useMessageFormatter(); const { formatMessage } = useMessageFormatter();
return { return {
preChatFormEnabled,
formatMessage, formatMessage,
}; };
}, },
@@ -3,7 +3,7 @@ import { mapGetters } from 'vuex';
import { getContrastingTextColor } from '@chatwoot/utils'; import { getContrastingTextColor } from '@chatwoot/utils';
import nextAvailabilityTime from 'widget/mixins/nextAvailabilityTime'; import nextAvailabilityTime from 'widget/mixins/nextAvailabilityTime';
import AvailableAgents from 'widget/components/AvailableAgents.vue'; import AvailableAgents from 'widget/components/AvailableAgents.vue';
import configMixin from 'widget/mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import availabilityMixin from 'widget/mixins/availability'; import availabilityMixin from 'widget/mixins/availability';
import FluentIcon from 'shared/components/FluentIcon/Index.vue'; import FluentIcon from 'shared/components/FluentIcon/Index.vue';
import { IFrameHelper } from 'widget/helpers/utils'; import { IFrameHelper } from 'widget/helpers/utils';
@@ -15,7 +15,7 @@ export default {
AvailableAgents, AvailableAgents,
FluentIcon, FluentIcon,
}, },
mixins: [configMixin, nextAvailabilityTime, availabilityMixin], mixins: [nextAvailabilityTime, availabilityMixin],
props: { props: {
availableAgents: { availableAgents: {
type: Array, type: Array,
@@ -26,7 +26,12 @@ export default {
default: false, default: false,
}, },
}, },
setup() {
const { channelConfig } = useConfig();
return {
channelConfig,
};
},
computed: { computed: {
...mapGetters({ ...mapGetters({
widgetColor: 'appConfig/getWidgetColor', widgetColor: 'appConfig/getWidgetColor',
@@ -1,7 +1,7 @@
<script> <script>
import { useMessageFormatter } from 'shared/composables/useMessageFormatter'; import { useMessageFormatter } from 'shared/composables/useMessageFormatter';
import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue'; import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue';
import configMixin from '../mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import { isEmptyObject } from 'widget/helpers/utils'; import { isEmptyObject } from 'widget/helpers/utils';
import { import {
ON_CAMPAIGN_MESSAGE_CLICK, ON_CAMPAIGN_MESSAGE_CLICK,
@@ -11,7 +11,7 @@ import darkModeMixin from 'widget/mixins/darkModeMixin';
export default { export default {
name: 'UnreadMessage', name: 'UnreadMessage',
components: { Thumbnail }, components: { Thumbnail },
mixins: [configMixin, darkModeMixin], mixins: [messageFormatterMixin, darkModeMixin],
props: { props: {
message: { message: {
type: String, type: String,
@@ -31,8 +31,12 @@ export default {
}, },
}, },
setup() { setup() {
const { useInboxAvatarForBot, inboxAvatarUrl, channelConfig } = useConfig();
const { formatMessage } = useMessageFormatter(); const { formatMessage } = useMessageFormatter();
return { return {
useInboxAvatarForBot,
inboxAvatarUrl,
channelConfig,
formatMessage, formatMessage,
}; };
}, },
@@ -1,6 +1,5 @@
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import configMixin from '../mixins/configMixin';
import { ON_UNREAD_MESSAGE_CLICK } from '../constants/widgetBusEvents'; import { ON_UNREAD_MESSAGE_CLICK } from '../constants/widgetBusEvents';
import FluentIcon from 'shared/components/FluentIcon/Index.vue'; import FluentIcon from 'shared/components/FluentIcon/Index.vue';
import UnreadMessage from 'widget/components/UnreadMessage.vue'; import UnreadMessage from 'widget/components/UnreadMessage.vue';
@@ -12,7 +11,6 @@ export default {
FluentIcon, FluentIcon,
UnreadMessage, UnreadMessage,
}, },
mixins: [configMixin],
props: { props: {
messages: { messages: {
type: Array, type: Array,
@@ -3,7 +3,7 @@ import Banner from '../Banner.vue';
import Branding from 'shared/components/Branding.vue'; import Branding from 'shared/components/Branding.vue';
import ChatHeader from '../ChatHeader.vue'; import ChatHeader from '../ChatHeader.vue';
import ChatHeaderExpanded from '../ChatHeaderExpanded.vue'; import ChatHeaderExpanded from '../ChatHeaderExpanded.vue';
import configMixin from '../../mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { IFrameHelper } from 'widget/helpers/utils'; import { IFrameHelper } from 'widget/helpers/utils';
@@ -14,7 +14,12 @@ export default {
ChatHeader, ChatHeader,
ChatHeaderExpanded, ChatHeaderExpanded,
}, },
mixins: [configMixin], setup() {
const { channelConfig } = useConfig();
return {
channelConfig,
};
},
data() { data() {
return { return {
showPopoutButton: false, showPopoutButton: false,
@@ -0,0 +1,118 @@
import { useConfig } from '../useConfig';
describe('useConfig composable', () => {
beforeEach(() => {
global.window.chatwootWebChannel = {
avatarUrl: 'https://test.url',
hasAConnectedAgentBot: 'AgentBot',
enabledFeatures: [
'emoji_picker',
'attachments',
'end_conversation',
'use_inbox_avatar_for_bot',
],
preChatFormOptions: {
pre_chat_message: '',
pre_chat_fields: [
{
label: 'Email Id',
name: 'emailAddress',
type: 'email',
field_type: 'standard',
required: false,
enabled: false,
},
{
label: 'Full name',
name: 'fullName',
type: 'text',
field_type: 'standard',
required: true,
enabled: true,
},
],
},
preChatFormEnabled: true,
};
});
it('should return correct values for computed properties', () => {
const {
useInboxAvatarForBot,
hasAConnectedAgentBot,
inboxAvatarUrl,
channelConfig,
hasEmojiPickerEnabled,
hasAttachmentsEnabled,
hasEndConversationEnabled,
preChatFormEnabled,
preChatFormOptions,
shouldShowPreChatForm,
} = useConfig();
expect(useInboxAvatarForBot.value).toBe(true);
expect(hasAConnectedAgentBot.value).toBe(true);
expect(inboxAvatarUrl.value).toBe('https://test.url');
expect(channelConfig.value).toEqual({
avatarUrl: 'https://test.url',
hasAConnectedAgentBot: 'AgentBot',
enabledFeatures: [
'emoji_picker',
'attachments',
'end_conversation',
'use_inbox_avatar_for_bot',
],
preChatFormOptions: {
pre_chat_message: '',
pre_chat_fields: [
{
label: 'Email Id',
name: 'emailAddress',
type: 'email',
field_type: 'standard',
required: false,
enabled: false,
},
{
label: 'Full name',
name: 'fullName',
type: 'text',
field_type: 'standard',
required: true,
enabled: true,
},
],
},
preChatFormEnabled: true,
});
expect(hasEmojiPickerEnabled.value).toBe(true);
expect(hasAttachmentsEnabled.value).toBe(true);
expect(hasEndConversationEnabled.value).toBe(true);
expect(preChatFormEnabled.value).toBe(true);
expect(preChatFormOptions.value).toEqual({
preChatMessage: '',
preChatFields: [
{
label: 'Email Id',
name: 'emailAddress',
type: 'email',
field_type: 'standard',
required: false,
enabled: false,
},
{
label: 'Full name',
name: 'fullName',
type: 'text',
field_type: 'standard',
required: true,
enabled: true,
},
],
});
expect(shouldShowPreChatForm.value).toBe(true);
});
});
@@ -0,0 +1,81 @@
import { computed } from 'vue';
/**
* Composable for handling config-related computations.
* @returns {Object} An object containing computed properties for various configuration settings.
*/
export function useConfig() {
/**
* Computed property to get the channel config.
* @returns {Object} The channel configuration object.
*/
const channelConfig = computed(() => window.chatwootWebChannel);
const createFeatureChecker = feature =>
computed(() => channelConfig.value.enabledFeatures.includes(feature));
// Use the helper function for feature checks
const useInboxAvatarForBot = createFeatureChecker('use_inbox_avatar_for_bot');
const hasEmojiPickerEnabled = createFeatureChecker('emoji_picker');
const hasAttachmentsEnabled = createFeatureChecker('attachments');
const hasEndConversationEnabled = createFeatureChecker('end_conversation');
/**
* Computed property to check if the agent bot is connected.
* @returns {Boolean} True if the agent bot is connected, false otherwise.
*/
const hasAConnectedAgentBot = computed(
() => !!channelConfig.value.hasAConnectedAgentBot
);
/**
* Computed property to get the inbox avatar URL.
* @returns {String} The inbox avatar URL.
*/
const inboxAvatarUrl = computed(() => channelConfig.value.avatarUrl);
/**
* Computed property to check if the pre-chat form is enabled.
* @returns {Boolean} True if the pre-chat form is enabled, false otherwise.
*/
const preChatFormEnabled = computed(
() => channelConfig.value.preChatFormEnabled
);
/**
* Computed property to get the pre-chat form options.
* @returns {Object} An object containing pre-chat message and fields.
*/
const preChatFormOptions = computed(() => {
const options = channelConfig.value.preChatFormOptions || {};
const preChatMessage = options.pre_chat_message || '';
const preChatFields = options.pre_chat_fields || [];
return {
preChatMessage,
preChatFields,
};
});
/**
* Computed property to determine if the pre-chat form should be shown.
* @returns {Boolean} True if the pre-chat form should be shown, false otherwise.
*/
const shouldShowPreChatForm = computed(() => {
if (!preChatFormEnabled.value) return false;
const { preChatFields } = preChatFormOptions.value;
return preChatFields.some(field => field.enabled);
});
return {
useInboxAvatarForBot,
hasAConnectedAgentBot,
inboxAvatarUrl,
channelConfig,
hasEmojiPickerEnabled,
hasAttachmentsEnabled,
hasEndConversationEnabled,
preChatFormEnabled,
preChatFormOptions,
shouldShowPreChatForm,
};
}
@@ -1,47 +0,0 @@
export default {
computed: {
useInboxAvatarForBot() {
return this.channelConfig.enabledFeatures.includes(
'use_inbox_avatar_for_bot'
);
},
hasAConnectedAgentBot() {
return !!window.chatwootWebChannel.hasAConnectedAgentBot;
},
inboxAvatarUrl() {
return window.chatwootWebChannel.avatarUrl;
},
channelConfig() {
return window.chatwootWebChannel;
},
hasEmojiPickerEnabled() {
return this.channelConfig.enabledFeatures.includes('emoji_picker');
},
hasAttachmentsEnabled() {
return this.channelConfig.enabledFeatures.includes('attachments');
},
hasEndConversationEnabled() {
return this.channelConfig.enabledFeatures.includes('end_conversation');
},
preChatFormEnabled() {
return window.chatwootWebChannel.preChatFormEnabled;
},
preChatFormOptions() {
let preChatMessage = '';
const options = window.chatwootWebChannel.preChatFormOptions || {};
preChatMessage = options.pre_chat_message;
const { pre_chat_fields: preChatFields = [] } = options;
return {
preChatMessage,
preChatFields,
};
},
shouldShowPreChatForm() {
const { preChatFields } = this.preChatFormOptions;
// Check if at least one enabled field in pre-chat fields
const hasEnabledFields =
preChatFields.filter(field => field.enabled).length > 0;
return this.preChatFormEnabled && hasEnabledFields;
},
},
};
@@ -1,74 +0,0 @@
import { createWrapper } from '@vue/test-utils';
import configMixin from '../configMixin';
import Vue from 'vue';
const preChatFields = [
{
label: 'Email Id',
name: 'emailAddress',
type: 'email',
field_type: 'standard',
required: false,
enabled: false,
},
{
label: 'Full name',
name: 'fullName',
type: 'text',
field_type: 'standard',
required: true,
enabled: true,
},
];
global.chatwootWebChannel = {
avatarUrl: 'https://test.url',
hasAConnectedAgentBot: 'AgentBot',
enabledFeatures: [
'emoji_picker',
'attachments',
'end_conversation',
'use_inbox_avatar_for_bot',
],
preChatFormOptions: { pre_chat_fields: preChatFields, pre_chat_message: '' },
preChatFormEnabled: true,
};
describe('configMixin', () => {
test('returns config', () => {
const Component = {
render() {},
title: 'TestComponent',
mixins: [configMixin],
};
const Constructor = Vue.extend(Component);
const vm = new Constructor().$mount();
const wrapper = createWrapper(vm);
expect(wrapper.vm.hasEmojiPickerEnabled).toBe(true);
expect(wrapper.vm.hasEndConversationEnabled).toBe(true);
expect(wrapper.vm.hasAttachmentsEnabled).toBe(true);
expect(wrapper.vm.hasAConnectedAgentBot).toBe(true);
expect(wrapper.vm.useInboxAvatarForBot).toBe(true);
expect(wrapper.vm.inboxAvatarUrl).toBe('https://test.url');
expect(wrapper.vm.channelConfig).toEqual({
avatarUrl: 'https://test.url',
hasAConnectedAgentBot: 'AgentBot',
enabledFeatures: [
'emoji_picker',
'attachments',
'end_conversation',
'use_inbox_avatar_for_bot',
],
preChatFormOptions: {
pre_chat_message: '',
pre_chat_fields: preChatFields,
},
preChatFormEnabled: true,
});
expect(wrapper.vm.preChatFormOptions).toEqual({
preChatMessage: '',
preChatFields: preChatFields,
});
expect(wrapper.vm.preChatFormEnabled).toEqual(true);
expect(wrapper.vm.shouldShowPreChatForm).toEqual(true);
});
});
+8 -2
View File
@@ -6,7 +6,7 @@ import ArticleCardSkeletonLoader from 'widget/components/ArticleCardSkeletonLoad
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import darkModeMixin from 'widget/mixins/darkModeMixin'; import darkModeMixin from 'widget/mixins/darkModeMixin';
import routerMixin from 'widget/mixins/routerMixin'; import routerMixin from 'widget/mixins/routerMixin';
import configMixin from 'widget/mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
export default { export default {
name: 'Home', name: 'Home',
@@ -15,7 +15,13 @@ export default {
TeamAvailability, TeamAvailability,
ArticleCardSkeletonLoader, ArticleCardSkeletonLoader,
}, },
mixins: [configMixin, routerMixin, darkModeMixin], mixins: [routerMixin, darkModeMixin],
setup() {
const { preChatFormEnabled } = useConfig();
return {
preChatFormEnabled,
};
},
computed: { computed: {
...mapGetters({ ...mapGetters({
availableAgents: 'agent/availableAgents', availableAgents: 'agent/availableAgents',
+8 -2
View File
@@ -1,6 +1,6 @@
<script> <script>
import PreChatForm from '../components/PreChat/Form.vue'; import PreChatForm from '../components/PreChat/Form.vue';
import configMixin from '../mixins/configMixin'; import { useConfig } from 'widget/composables/useConfig';
import routerMixin from '../mixins/routerMixin'; import routerMixin from '../mixins/routerMixin';
import { isEmptyObject } from 'widget/helpers/utils'; import { isEmptyObject } from 'widget/helpers/utils';
import { ON_CONVERSATION_CREATED } from '../constants/widgetBusEvents'; import { ON_CONVERSATION_CREATED } from '../constants/widgetBusEvents';
@@ -9,7 +9,13 @@ export default {
components: { components: {
PreChatForm, PreChatForm,
}, },
mixins: [configMixin, routerMixin], mixins: [routerMixin],
setup() {
const { preChatFormOptions } = useConfig();
return {
preChatFormOptions,
};
},
mounted() { mounted() {
this.$emitter.on(ON_CONVERSATION_CREATED, () => { this.$emitter.on(ON_CONVERSATION_CREATED, () => {
// Redirect to messages page after conversation is created // Redirect to messages page after conversation is created