From 5d2efdc7fc6011e833fdcd5be295717cd3dbb71d Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Tue, 26 Nov 2019 00:10:27 +0530 Subject: [PATCH] Update widget colors based on the widgetConfig (#276) --- .eslintrc.js | 1 + app/javascript/packs/sdk.js | 35 ++++++++++--------- app/javascript/widget/App.vue | 3 ++ .../widget/components/ChatHeaderExpanded.vue | 9 ++++- .../widget/components/UserMessageBubble.vue | 13 +++++-- app/javascript/widget/store/index.js | 2 ++ .../widget/store/modules/appConfig.js | 29 +++++++++++++++ app/javascript/widget/store/types.js | 1 + app/views/widgets/index.html.erb | 5 ++- ...24091232_add_widget_color_to_web_widget.rb | 5 +++ db/schema.rb | 3 +- 11 files changed, 85 insertions(+), 21 deletions(-) create mode 100644 app/javascript/widget/store/modules/appConfig.js create mode 100644 app/javascript/widget/store/types.js create mode 100644 db/migrate/20191124091232_add_widget_color_to_web_widget.rb diff --git a/.eslintrc.js b/.eslintrc.js index 8afa4fbe0..b61be8bb6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,6 +9,7 @@ module.exports = { rules: { 'prettier/prettier': ['error'], camelcase: 'off', + 'no-param-reassign': 'off', 'import/no-extraneous-dependencies': 'off', 'import/prefer-default-export': 'off', 'import/no-named-as-default': 'off', diff --git a/app/javascript/packs/sdk.js b/app/javascript/packs/sdk.js index 8d98a82ad..7fc33ad91 100755 --- a/app/javascript/packs/sdk.js +++ b/app/javascript/packs/sdk.js @@ -153,11 +153,11 @@ const IFrameHelper = { if (message.event === 'loaded') { Cookies.set('cw_conversation', message.config.authToken); IFrameHelper.sendMessage('config-set', {}); - IFrameHelper.onLoad(); + IFrameHelper.onLoad(message.config.channelConfig); } }; }, - onLoad: () => { + onLoad: ({ widget_color: widgetColor }) => { const iframe = IFrameHelper.getAppFrame(); iframe.style.visibility = ''; iframe.setAttribute('id', `chatwoot_live_chat_widget`); @@ -167,20 +167,23 @@ const IFrameHelper = { loadCSS(); createBubbleHolder(); - bubbleHolder.appendChild( - createBubbleIcon({ - className: 'woot-widget-bubble', - src: bubbleImg, - target: chatBubble, - }) - ); - bubbleHolder.appendChild( - createBubbleIcon({ - className: 'woot-widget-bubble woot--close woot--hide', - src: closeImg, - target: closeBubble, - }) - ); + const chatIcon = createBubbleIcon({ + className: 'woot-widget-bubble', + src: bubbleImg, + target: chatBubble, + }); + + const closeIcon = createBubbleIcon({ + className: 'woot-widget-bubble woot--close woot--hide', + src: closeImg, + target: closeBubble, + }); + + chatIcon.style.background = widgetColor; + closeIcon.style.background = widgetColor; + + bubbleHolder.appendChild(chatIcon); + bubbleHolder.appendChild(closeIcon); bubbleHolder.appendChild(createNotificationBubble()); onClickChatBubble(); }, diff --git a/app/javascript/widget/App.vue b/app/javascript/widget/App.vue index f5d031279..43bfb10b9 100755 --- a/app/javascript/widget/App.vue +++ b/app/javascript/widget/App.vue @@ -22,6 +22,7 @@ export default { name: 'App', methods: { + ...mapActions('appConfig', ['setWidgetColor']), ...mapActions('conversation', ['fetchOldConversations']), scrollConversationToBottom() { const container = this.$el.querySelector('.conversation-wrap'); @@ -35,10 +36,12 @@ export default { event: 'loaded', config: { authToken: window.authToken, + channelConfig: window.chatwootWebChannel, }, }); setHeader('X-Auth-Token', window.authToken); } + this.setWidgetColor(window.chatwootWebChannel); window.addEventListener('message', e => { if ( diff --git a/app/javascript/widget/components/ChatHeaderExpanded.vue b/app/javascript/widget/components/ChatHeaderExpanded.vue index 15ff35ae8..1b30dc37d 100755 --- a/app/javascript/widget/components/ChatHeaderExpanded.vue +++ b/app/javascript/widget/components/ChatHeaderExpanded.vue @@ -1,5 +1,5 @@ -