From 576b2e77e6a853c76ffd1da4df3296a914d67c60 Mon Sep 17 00:00:00 2001
From: Pham Hai Duong <duongph@reapit.com>
Date: Mon, 23 Mar 2020 20:24:25 +0700
Subject: [PATCH] fix: #681 bug live chat after migrate to config.json (#696)

Changes
- Change chatbot App ID from process.env to window.reapit.config
---
 .eslintrc.js                                 | 1 +
 packages/marketplace/src/core/index.tsx      | 1 +
 packages/marketplace/src/scripts/chat-bot.js | 2 +-
 packages/marketplace/src/types/global.d.ts   | 1 +
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/.eslintrc.js b/.eslintrc.js
index fbfc3b52f1..8141b6fd3f 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -45,6 +45,7 @@ module.exports = {
     'packages/*/build',
     'packages/*/dist',
     'packages/*/public/dist',
+    'chat-bot.js'
   ],
   rules: {
     quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: false }],
diff --git a/packages/marketplace/src/core/index.tsx b/packages/marketplace/src/core/index.tsx
index 1c4fa91f66..c7869043b3 100644
--- a/packages/marketplace/src/core/index.tsx
+++ b/packages/marketplace/src/core/index.tsx
@@ -22,6 +22,7 @@ window.reapit = {
     googleAnalyticsKey: '',
     cognitoOAuthUrl: '',
     cognitoUserPoolId: '',
+    chatbotAppId: '',
   },
 }
 
diff --git a/packages/marketplace/src/scripts/chat-bot.js b/packages/marketplace/src/scripts/chat-bot.js
index 6fdc5f268f..b2f71ce644 100644
--- a/packages/marketplace/src/scripts/chat-bot.js
+++ b/packages/marketplace/src/scripts/chat-bot.js
@@ -22,7 +22,7 @@ module.exports = function(loginIdentity) {
       (n.src = 'https://w.chatlio.com/w.chatlio-widget.js'),
       (n.async = !0),
       n.setAttribute('data-embed-version', '2.3')
-    n.setAttribute('data-widget-id', process.env.CHATBOT_APP_ID)
+    n.setAttribute('data-widget-id', window.reapit.config.chatbotAppId)
     c.parentNode.insertBefore(n, c)
 
     if (loginIdentity) {
diff --git a/packages/marketplace/src/types/global.d.ts b/packages/marketplace/src/types/global.d.ts
index ad6c1d25c3..edfe5e457d 100644
--- a/packages/marketplace/src/types/global.d.ts
+++ b/packages/marketplace/src/types/global.d.ts
@@ -10,6 +10,7 @@ export type Config = {
   googleAnalyticsKey: string
   cognitoOAuthUrl: string
   cognitoUserPoolId: string
+  chatbotAppId: string
 }
 
 declare global {