From 7db7ae0ed86f44ee9f83fa7ca745088c1708b5f7 Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed Date: Tue, 13 Aug 2024 19:04:55 +0530 Subject: [PATCH] chore: Replace widget config mixin with useConfig composable --- app/javascript/widget/App.vue | 10 +- .../widget/components/AgentMessage.vue | 8 +- .../widget/components/ChatInputWrap.vue | 12 +- .../widget/components/HeaderActions.vue | 10 +- .../widget/components/PreChat/Form.vue | 10 +- .../widget/components/TeamAvailability.vue | 11 +- .../widget/components/UnreadMessage.vue | 12 +- .../widget/components/UnreadMessageList.vue | 2 - .../components/layouts/ViewWithHeader.vue | 9 +- .../composables/specs/useConfig.spec.js | 118 ++++++++++++++++++ .../widget/composables/useConfig.js | 104 +++++++++++++++ app/javascript/widget/mixins/configMixin.js | 47 ------- .../widget/mixins/specs/configMixin.spec.js | 74 ----------- app/javascript/widget/views/Home.vue | 10 +- app/javascript/widget/views/PreChatForm.vue | 10 +- 15 files changed, 302 insertions(+), 145 deletions(-) create mode 100644 app/javascript/widget/composables/specs/useConfig.spec.js create mode 100644 app/javascript/widget/composables/useConfig.js delete mode 100644 app/javascript/widget/mixins/configMixin.js delete mode 100644 app/javascript/widget/mixins/specs/configMixin.spec.js diff --git a/app/javascript/widget/App.vue b/app/javascript/widget/App.vue index 6645465c5..63cab0327 100755 --- a/app/javascript/widget/App.vue +++ b/app/javascript/widget/App.vue @@ -3,7 +3,7 @@ import { mapGetters, mapActions } from 'vuex'; import { setHeader } from 'widget/helpers/axios'; import addHours from 'date-fns/addHours'; 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 { getLocale } from './helpers/urlParamsHelper'; import { isEmptyObject } from 'widget/helpers/utils'; @@ -27,7 +27,13 @@ export default { components: { Spinner, }, - mixins: [availabilityMixin, configMixin, routerMixin, darkModeMixin], + mixins: [availabilityMixin, routerMixin, darkModeMixin], + setup() { + const { shouldShowPreChatForm } = useConfig(); + return { + shouldShowPreChatForm, + }; + }, data() { return { isMobile: false, diff --git a/app/javascript/widget/components/AgentMessage.vue b/app/javascript/widget/components/AgentMessage.vue index e7d592abd..1ca4ab011 100755 --- a/app/javascript/widget/components/AgentMessage.vue +++ b/app/javascript/widget/components/AgentMessage.vue @@ -8,7 +8,7 @@ import VideoBubble from 'widget/components/VideoBubble.vue'; import FileBubble from 'widget/components/FileBubble.vue'; import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue'; import { MESSAGE_TYPE } from 'widget/helpers/constants'; -import configMixin from '../mixins/configMixin'; +import { useConfig } from 'widget/composables/useConfig'; import { useMessage } from '../composables/useMessage'; import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper'; import darkModeMixin from 'widget/mixins/darkModeMixin.js'; @@ -28,7 +28,7 @@ export default { MessageReplyButton, ReplyToChip, }, - mixins: [configMixin, darkModeMixin], + mixins: [darkModeMixin], props: { message: { type: Object, @@ -43,9 +43,13 @@ export default { const { messageContentAttributes, hasAttachments } = useMessage( props.message ); + const { useInboxAvatarForBot, inboxAvatarUrl, channelConfig } = useConfig(); return { messageContentAttributes, hasAttachments, + useInboxAvatarForBot, + inboxAvatarUrl, + channelConfig, }; }, data() { diff --git a/app/javascript/widget/components/ChatInputWrap.vue b/app/javascript/widget/components/ChatInputWrap.vue index c68ec3fdf..9f89885c5 100755 --- a/app/javascript/widget/components/ChatInputWrap.vue +++ b/app/javascript/widget/components/ChatInputWrap.vue @@ -3,7 +3,7 @@ import { mapGetters } from 'vuex'; import ChatAttachmentButton from 'widget/components/ChatAttachment.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 ResizableTextArea from 'shared/components/ResizableTextArea.vue'; import darkModeMixin from 'widget/mixins/darkModeMixin.js'; @@ -19,7 +19,7 @@ export default { FluentIcon, ResizableTextArea, }, - mixins: [configMixin, darkModeMixin], + mixins: [darkModeMixin], props: { onSendMessage: { type: Function, @@ -30,7 +30,13 @@ export default { default: () => {}, }, }, - + setup() { + const { hasEmojiPickerEnabled, hasAttachmentsEnabled } = useConfig(); + return { + hasEmojiPickerEnabled, + hasAttachmentsEnabled, + }; + }, data() { return { userInput: '', diff --git a/app/javascript/widget/components/HeaderActions.vue b/app/javascript/widget/components/HeaderActions.vue index df8b5fdbf..af65bd7f7 100644 --- a/app/javascript/widget/components/HeaderActions.vue +++ b/app/javascript/widget/components/HeaderActions.vue @@ -4,13 +4,13 @@ import { IFrameHelper, RNHelper } from 'widget/helpers/utils'; import { popoutChatWindow } from '../helpers/popoutHelper'; import FluentIcon from 'shared/components/FluentIcon/Index.vue'; 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'; export default { name: 'HeaderActions', components: { FluentIcon }, - mixins: [configMixin, darkModeMixin], + mixins: [darkModeMixin], props: { showPopoutButton: { type: Boolean, @@ -21,6 +21,12 @@ export default { default: true, }, }, + setup() { + const { hasEndConversationEnabled } = useConfig(); + return { + hasEndConversationEnabled, + }; + }, computed: { ...mapGetters({ conversationAttributes: 'conversationAttributes/getConversationParams', diff --git a/app/javascript/widget/components/PreChat/Form.vue b/app/javascript/widget/components/PreChat/Form.vue index 596ba16d9..f144f00f2 100644 --- a/app/javascript/widget/components/PreChat/Form.vue +++ b/app/javascript/widget/components/PreChat/Form.vue @@ -8,20 +8,26 @@ import { getRegexp } from 'shared/helpers/Validators'; import messageFormatterMixin from 'shared/mixins/messageFormatterMixin'; import routerMixin from 'widget/mixins/routerMixin'; import darkModeMixin from 'widget/mixins/darkModeMixin'; -import configMixin from 'widget/mixins/configMixin'; +import { useConfig } from 'widget/composables/useConfig'; export default { components: { CustomButton, Spinner, }, - mixins: [routerMixin, darkModeMixin, messageFormatterMixin, configMixin], + mixins: [routerMixin, darkModeMixin, messageFormatterMixin], props: { options: { type: Object, default: () => {}, }, }, + setup() { + const { preChatFormEnabled } = useConfig(); + return { + preChatFormEnabled, + }; + }, data() { return { locale: this.$root.$i18n.locale, diff --git a/app/javascript/widget/components/TeamAvailability.vue b/app/javascript/widget/components/TeamAvailability.vue index 18aaaccac..92f35b469 100644 --- a/app/javascript/widget/components/TeamAvailability.vue +++ b/app/javascript/widget/components/TeamAvailability.vue @@ -3,7 +3,7 @@ import { mapGetters } from 'vuex'; import { getContrastingTextColor } from '@chatwoot/utils'; import nextAvailabilityTime from 'widget/mixins/nextAvailabilityTime'; 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 FluentIcon from 'shared/components/FluentIcon/Index.vue'; import { IFrameHelper } from 'widget/helpers/utils'; @@ -15,7 +15,7 @@ export default { AvailableAgents, FluentIcon, }, - mixins: [configMixin, nextAvailabilityTime, availabilityMixin], + mixins: [nextAvailabilityTime, availabilityMixin], props: { availableAgents: { type: Array, @@ -26,7 +26,12 @@ export default { default: false, }, }, - + setup() { + const { channelConfig } = useConfig(); + return { + channelConfig, + }; + }, computed: { ...mapGetters({ widgetColor: 'appConfig/getWidgetColor', diff --git a/app/javascript/widget/components/UnreadMessage.vue b/app/javascript/widget/components/UnreadMessage.vue index b90ad9011..b8d65719a 100644 --- a/app/javascript/widget/components/UnreadMessage.vue +++ b/app/javascript/widget/components/UnreadMessage.vue @@ -1,7 +1,7 @@