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 @@ -