From 9c31d7c672d4f9743ce3a18910d905fe841be7cf Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Wed, 12 Jan 2022 02:55:27 -0800 Subject: [PATCH] feat: Use vue-router on widget route management (#3415) * feat: Add vue-router to widget Co-authored-by: Pranav * Move to dynamic imports * Move to routerMixin * Fix popup button display * Remove unnecessary import * router -> route * Fix open state * Fix issues * Remove used CSS * Fix specs * Fix specs * Fix widgetColor specs * Fix mutation specs * Fixes broken lint errors * Fixes issues with widget flow Co-authored-by: Nithin Co-authored-by: Nithin David <1277421+nithindavid@users.noreply.github.com> Co-authored-by: Muhsin Keloth --- .../dashboard/components/widgets/Avatar.vue | 4 +- app/javascript/packs/widget.js | 2 + app/javascript/sdk/IFrameHelper.js | 48 ++-- .../shared/components/FluentIcon/icons.json | 1 + app/javascript/widget/App.vue | 188 +++++++-------- app/javascript/widget/assets/scss/woot.scss | 7 - .../widget/components/ChatFooter.vue | 64 +++-- .../widget/components/ChatHeader.vue | 75 +++--- .../widget/components/ChatHeaderExpanded.vue | 20 +- .../widget/components/ChatInputWrap.vue | 10 +- .../widget/components/HeaderActions.vue | 4 +- .../widget/components/PreChat/Form.vue | 35 ++- .../widget/components/TeamAvailability.vue | 10 +- .../widget/components/UnreadMessage.vue | 8 +- .../UnreadMessageList.vue} | 69 ++---- .../components/layouts/ViewWithHeader.vue | 118 ++++++++++ .../widget/constants/widgetBusEvents.js | 3 + app/javascript/widget/helpers/actionCable.js | 5 +- app/javascript/widget/i18n/locale/en.json | 1 + app/javascript/widget/mixins/configMixin.js | 6 +- app/javascript/widget/mixins/routerMixin.js | 10 + app/javascript/widget/router.js | 44 ++-- .../widget/store/modules/appConfig.js | 43 +++- .../widget/store/modules/campaign.js | 28 ++- app/javascript/widget/store/modules/events.js | 14 +- .../modules/specs/agent/mutations.spec.js | 2 +- .../modules/specs/appConfig/actions.spec.js | 6 +- .../modules/specs/appConfig/mutations.spec.js | 2 +- .../modules/specs/campaign/actions.spec.js | 51 +++- .../modules/specs/campaign/getters.spec.js | 13 -- .../modules/specs/campaign/mutations.spec.js | 16 -- app/javascript/widget/store/types.js | 11 +- app/javascript/widget/views/Campaigns.vue | 28 +++ app/javascript/widget/views/Home.vue | 218 ++---------------- app/javascript/widget/views/Messages.vue | 27 +++ app/javascript/widget/views/PreChatForm.vue | 49 ++++ app/javascript/widget/views/Router.vue | 82 ------- .../widget/views/UnreadMessages.vue | 20 ++ 38 files changed, 617 insertions(+), 725 deletions(-) rename app/javascript/widget/{views/Unread.vue => components/UnreadMessageList.vue} (68%) create mode 100644 app/javascript/widget/components/layouts/ViewWithHeader.vue create mode 100644 app/javascript/widget/constants/widgetBusEvents.js create mode 100644 app/javascript/widget/mixins/routerMixin.js create mode 100644 app/javascript/widget/views/Campaigns.vue create mode 100644 app/javascript/widget/views/Messages.vue create mode 100644 app/javascript/widget/views/PreChatForm.vue delete mode 100644 app/javascript/widget/views/Router.vue create mode 100644 app/javascript/widget/views/UnreadMessages.vue diff --git a/app/javascript/dashboard/components/widgets/Avatar.vue b/app/javascript/dashboard/components/widgets/Avatar.vue index 9a409f18b..1d67842a2 100644 --- a/app/javascript/dashboard/components/widgets/Avatar.vue +++ b/app/javascript/dashboard/components/widgets/Avatar.vue @@ -18,11 +18,11 @@ export default { }, backgroundColor: { type: String, - default: 'white', + default: '#c2e1ff', }, color: { type: String, - default: '', + default: '#1976cc', }, customStyle: { type: Object, diff --git a/app/javascript/packs/widget.js b/app/javascript/packs/widget.js index 7aeaf4545..f9f57e2ef 100644 --- a/app/javascript/packs/widget.js +++ b/app/javascript/packs/widget.js @@ -7,6 +7,7 @@ import ActionCableConnector from '../widget/helpers/actionCable'; import { getAlertAudio } from 'shared/helpers/AudioNotificationHelper'; import i18n from '../widget/i18n'; +import router from '../widget/router'; Vue.use(VueI18n); Vue.use(Vuelidate); @@ -22,6 +23,7 @@ Vue.config.productionTip = false; window.onload = () => { window.WOOT_WIDGET = new Vue({ + router, store, i18n: i18nConfig, render: h => h(App), diff --git a/app/javascript/sdk/IFrameHelper.js b/app/javascript/sdk/IFrameHelper.js index ff9bcca91..e10feac6d 100644 --- a/app/javascript/sdk/IFrameHelper.js +++ b/app/javascript/sdk/IFrameHelper.js @@ -150,11 +150,14 @@ export const IFrameHelper = { onBubbleClick(bubbleState); }, + closeWindow: () => { + onBubbleClick({ toggleValue: false }); + removeUnreadClass(); + }, + onBubbleToggle: isOpen => { IFrameHelper.sendMessage('toggle-open', { isOpen }); - if (!isOpen) { - IFrameHelper.events.resetUnreadMode(); - } else { + if (isOpen) { IFrameHelper.pushEvent('webwidget.triggered'); } }, @@ -164,28 +167,6 @@ export const IFrameHelper = { referrerHost, }); }, - - setUnreadMode: message => { - const { unreadMessageCount } = message; - const { isOpen } = window.$chatwoot; - const toggleValue = true; - - if (!isOpen && unreadMessageCount > 0) { - IFrameHelper.sendMessage('set-unread-view'); - onBubbleClick({ toggleValue }); - addUnreadClass(); - } - }, - - setCampaignMode: () => { - const { isOpen } = window.$chatwoot; - const toggleValue = true; - if (!isOpen) { - onBubbleClick({ toggleValue }); - addUnreadClass(); - } - }, - updateIframeHeight: message => { const { extraHeight = 0, isFixedHeight } = message; if (!extraHeight) return; @@ -193,11 +174,12 @@ export const IFrameHelper = { IFrameHelper.setFrameHeightToFitContent(extraHeight, isFixedHeight); }, - resetUnreadMode: () => { - IFrameHelper.sendMessage('unset-unread-view'); - removeUnreadClass(); + setUnreadMode: () => { + addUnreadClass(); + onBubbleClick({ toggleValue: true }); }, + resetUnreadMode: () => removeUnreadClass(), handleNotificationDot: event => { if (window.$chatwoot.hideMessageBubble) { return; @@ -253,14 +235,10 @@ export const IFrameHelper = { } }, toggleCloseButton: () => { + let isMobile = false; if (window.matchMedia('(max-width: 668px)').matches) { - IFrameHelper.sendMessage('toggle-close-button', { - showClose: true, - }); - } else { - IFrameHelper.sendMessage('toggle-close-button', { - showClose: false, - }); + isMobile = true; } + IFrameHelper.sendMessage('toggle-close-button', { isMobile }); }, }; diff --git a/app/javascript/shared/components/FluentIcon/icons.json b/app/javascript/shared/components/FluentIcon/icons.json index f3dc089b7..62798657d 100644 --- a/app/javascript/shared/components/FluentIcon/icons.json +++ b/app/javascript/shared/components/FluentIcon/icons.json @@ -2,6 +2,7 @@ "arrow-clockwise-outline": "M12 4.75a7.25 7.25 0 1 0 7.201 6.406c-.068-.588.358-1.156.95-1.156.515 0 .968.358 1.03.87a9.25 9.25 0 1 1-3.432-6.116V4.25a1 1 0 1 1 2.001 0v2.698l.034.052h-.034v.25a1 1 0 0 1-1 1h-3a1 1 0 1 1 0-2h.666A7.219 7.219 0 0 0 12 4.75Z", "arrow-right-outline": "M13.267 4.209a.75.75 0 0 0-1.034 1.086l6.251 5.955H3.75a.75.75 0 0 0 0 1.5h14.734l-6.251 5.954a.75.75 0 0 0 1.034 1.087l7.42-7.067a.996.996 0 0 0 .3-.58.758.758 0 0 0-.001-.29.995.995 0 0 0-.3-.578l-7.419-7.067Z", "attach-outline": "M11.772 3.743a6 6 0 0 1 8.66 8.302l-.19.197-8.8 8.798-.036.03a3.723 3.723 0 0 1-5.489-4.973.764.764 0 0 1 .085-.13l.054-.06.086-.088.142-.148.002.003 7.436-7.454a.75.75 0 0 1 .977-.074l.084.073a.75.75 0 0 1 .074.976l-.073.084-7.594 7.613a2.23 2.23 0 0 0 3.174 3.106l8.832-8.83A4.502 4.502 0 0 0 13 4.644l-.168.16-.013.014-9.536 9.536a.75.75 0 0 1-1.133-.977l.072-.084 9.549-9.55h.002Z", + "chevron-left-outline": "M15.53 4.22a.75.75 0 0 1 0 1.06L8.81 12l6.72 6.72a.75.75 0 1 1-1.06 1.06l-7.25-7.25a.75.75 0 0 1 0-1.06l7.25-7.25a.75.75 0 0 1 1.06 0Z", "chevron-right-outline": "M8.293 4.293a1 1 0 0 0 0 1.414L14.586 12l-6.293 6.293a1 1 0 1 0 1.414 1.414l7-7a1 1 0 0 0 0-1.414l-7-7a1 1 0 0 0-1.414 0Z", "dismiss-outline": "m4.397 4.554.073-.084a.75.75 0 0 1 .976-.073l.084.073L12 10.939l6.47-6.47a.75.75 0 1 1 1.06 1.061L13.061 12l6.47 6.47a.75.75 0 0 1 .072.976l-.073.084a.75.75 0 0 1-.976.073l-.084-.073L12 13.061l-6.47 6.47a.75.75 0 0 1-1.06-1.061L10.939 12l-6.47-6.47a.75.75 0 0 1-.072-.976l.073-.084-.073.084Z", "document-outline": "M18.5 20a.5.5 0 0 1-.5.5H6a.5.5 0 0 1-.5-.5V4a.5.5 0 0 1 .5-.5h6V8a2 2 0 0 0 2 2h4.5v10Zm-5-15.379L17.378 8.5H14a.5.5 0 0 1-.5-.5V4.621Zm5.914 3.793-5.829-5.828c-.026-.026-.058-.046-.085-.07a2.072 2.072 0 0 0-.219-.18c-.04-.027-.086-.045-.128-.068-.071-.04-.141-.084-.216-.116a1.977 1.977 0 0 0-.624-.138C12.266 2.011 12.22 2 12.172 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9.828a2 2 0 0 0-.586-1.414Z", diff --git a/app/javascript/widget/App.vue b/app/javascript/widget/App.vue index 818ef6db4..6a4d4d7ec 100755 --- a/app/javascript/widget/App.vue +++ b/app/javascript/widget/App.vue @@ -1,61 +1,67 @@ - - diff --git a/app/javascript/widget/components/ChatHeaderExpanded.vue b/app/javascript/widget/components/ChatHeaderExpanded.vue index f80b1b8ab..fc4aab125 100755 --- a/app/javascript/widget/components/ChatHeaderExpanded.vue +++ b/app/javascript/widget/components/ChatHeaderExpanded.vue @@ -1,14 +1,14 @@ @@ -47,6 +49,10 @@ export default { type: Array, default: () => {}, }, + hasConversation: { + type: Boolean, + default: false, + }, }, computed: { ...mapGetters({ widgetColor: 'appConfig/getWidgetColor' }), diff --git a/app/javascript/widget/components/UnreadMessage.vue b/app/javascript/widget/components/UnreadMessage.vue index 48a6b4686..13e8fc250 100644 --- a/app/javascript/widget/components/UnreadMessage.vue +++ b/app/javascript/widget/components/UnreadMessage.vue @@ -21,6 +21,10 @@ import messageFormatterMixin from 'shared/mixins/messageFormatterMixin'; import Thumbnail from 'dashboard/components/widgets/Thumbnail'; import configMixin from '../mixins/configMixin'; import { isEmptyObject } from 'widget/helpers/utils'; +import { + ON_CAMPAIGN_MESSAGE_CLICK, + ON_UNREAD_MESSAGE_CLICK, +} from '../constants/widgetBusEvents'; export default { name: 'UnreadMessage', components: { Thumbnail }, @@ -82,9 +86,9 @@ export default { }, onClickMessage() { if (this.campaignId) { - bus.$emit('on-campaign-view-clicked', this.campaignId); + bus.$emit(ON_CAMPAIGN_MESSAGE_CLICK, this.campaignId); } else { - bus.$emit('on-unread-view-clicked'); + bus.$emit(ON_UNREAD_MESSAGE_CLICK); } }, }, diff --git a/app/javascript/widget/views/Unread.vue b/app/javascript/widget/components/UnreadMessageList.vue similarity index 68% rename from app/javascript/widget/views/Unread.vue rename to app/javascript/widget/components/UnreadMessageList.vue index 7eafbdbe2..a3368d4e9 100644 --- a/app/javascript/widget/views/Unread.vue +++ b/app/javascript/widget/components/UnreadMessageList.vue @@ -1,20 +1,16 @@