diff --git a/gatsby-config.js b/gatsby-config.js
index ed720f0..649b6b0 100644
--- a/gatsby-config.js
+++ b/gatsby-config.js
@@ -100,10 +100,11 @@ module.exports = {
},
},
{
- resolve: `gatsby-plugin-freshchat`,
+ resolve: `gatsby-plugin-ts-freshchat`,
options: {
token: process.env.FRESHCHAT_TOKEN,
host: "https://wchat.freshchat.com",
+ appEmbedUrl: "https://app.testsigma.com/ui/dashboard",
},
},
{
diff --git a/package-lock.json b/package-lock.json
index 9653d7c..c7a932e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,7 +13,6 @@
"dotenv": "^10.0.0",
"gatsby": "^3.13.0",
"gatsby-plugin-algolia": "^0.22.2",
- "gatsby-plugin-freshchat": "^1.0.0-rc1",
"gatsby-plugin-google-analytics": "^4.14.0",
"gatsby-plugin-google-gtag": "^4.4.0",
"gatsby-plugin-image": "^1.13.0",
@@ -9963,17 +9962,6 @@
"@algolia/transporter": "4.10.5"
}
},
- "node_modules/gatsby-plugin-freshchat": {
- "version": "1.0.0-rc1",
- "resolved": "https://registry.npmjs.org/gatsby-plugin-freshchat/-/gatsby-plugin-freshchat-1.0.0-rc1.tgz",
- "integrity": "sha512-7RWJP9gX9nbTF/8tHFrm5LpD4lSRQRCLNIW/d/ET4vgu6HWvbKHo4OaXIe35fO1yWkyfhDJzBUS668BDjAc1bQ==",
- "dependencies": {
- "@babel/runtime": "^7.1.5"
- },
- "peerDependencies": {
- "gatsby": ">2.0.0-alpha"
- }
- },
"node_modules/gatsby-plugin-google-analytics": {
"version": "4.14.0",
"resolved": "https://registry.npmjs.org/gatsby-plugin-google-analytics/-/gatsby-plugin-google-analytics-4.14.0.tgz",
@@ -30914,14 +30902,6 @@
}
}
},
- "gatsby-plugin-freshchat": {
- "version": "1.0.0-rc1",
- "resolved": "https://registry.npmjs.org/gatsby-plugin-freshchat/-/gatsby-plugin-freshchat-1.0.0-rc1.tgz",
- "integrity": "sha512-7RWJP9gX9nbTF/8tHFrm5LpD4lSRQRCLNIW/d/ET4vgu6HWvbKHo4OaXIe35fO1yWkyfhDJzBUS668BDjAc1bQ==",
- "requires": {
- "@babel/runtime": "^7.1.5"
- }
- },
"gatsby-plugin-google-analytics": {
"version": "4.14.0",
"resolved": "https://registry.npmjs.org/gatsby-plugin-google-analytics/-/gatsby-plugin-google-analytics-4.14.0.tgz",
@@ -31486,6 +31466,9 @@
}
}
},
+ "gatsby-plugin-ts-freshchat": {
+ "version": "file:plugins/gatsby-plugin-ts-freshchat"
+ },
"gatsby-plugin-typescript": {
"version": "3.13.0",
"resolved": "https://registry.npmjs.org/gatsby-plugin-typescript/-/gatsby-plugin-typescript-3.13.0.tgz",
diff --git a/package.json b/package.json
index 33c259a..114d479 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,7 @@
"dotenv": "^10.0.0",
"gatsby": "^3.13.0",
"gatsby-plugin-algolia": "^0.22.2",
- "gatsby-plugin-freshchat": "^1.0.0-rc1",
+ "gatsby-plugin-ts-freshchat": "file:plugins/gatsby-plugin-ts-freshchat",
"gatsby-plugin-google-analytics": "^4.14.0",
"gatsby-plugin-google-gtag": "^4.4.0",
"gatsby-plugin-image": "^1.13.0",
diff --git a/plugins/gatsby-plugin-ts-freshchat/gatsby-ssr.js b/plugins/gatsby-plugin-ts-freshchat/gatsby-ssr.js
new file mode 100644
index 0000000..619331f
--- /dev/null
+++ b/plugins/gatsby-plugin-ts-freshchat/gatsby-ssr.js
@@ -0,0 +1,73 @@
+const React = require("react")
+
+module.exports.onRenderBody = (
+ {setPostBodyComponents},
+ pluginOptions
+) => {
+ if (typeof pluginOptions.token === `undefined`) {
+ return null
+ }
+
+ const freshchatHost = pluginOptions.host ? pluginOptions.host : `https://wchat.freshchat.com`
+
+ const appEmbedUrl =
+ pluginOptions.appEmbedUrl ? pluginOptions.appEmbedUrl : `https://app.testsigma.com/ui/dashboard`
+
+ const renderHTML = () => `
+ window.fcSettings = {
+ token: "${pluginOptions.token}",
+ host: "${freshchatHost}"
+ };
+
+ function addFreshchatScript() {
+ if (window.fcWidgetAdded) return;
+ var fcScript = document.createElement('script');
+ fcScript.setAttribute('src','https://wchat.freshchat.com/js/widget.js');
+ fcScript.setAttribute('async', 'async');
+ document.body.appendChild(fcScript);
+ window.fcWidgetAdded = true;
+ }
+
+ function changeSignupBtn() {
+ var signupBtn = document.getElementById('signup-btn');
+ if (!signupBtn) {
+ setTimeout(changeSignupBtn, 1000);
+ return;
+ }
+ document.getElementById('signup-btn').textContent = 'Go to Dashboard';
+ document.getElementById('signup-btn').href = 'https://app.testsigma.com';
+ }
+
+ // If session details is not received from app within 15 seconds, create new chat.
+ setTimeout(addFreshchatScript, 15000);
+
+ window.addEventListener('message', function( event) {
+ if (event.origin === 'https://app.testsigma.com' ||
+ event.origin === 'https://staging.testsigma.com' ||
+ event.origin === 'https://prestaging.testsigma.com' ||
+ event.origin === 'https://devtesting.testsigma.com' ||
+ event.origin === 'http://dev.testsigma.com') {
+ if (event.data === 'appLoggedOut') {
+ addFreshchatScript();
+ } else {
+ var session = JSON.parse(event.data);
+ changeSignupBtn();
+ window.fcSettings.externalId = session.user.email;
+ window.fcSettings.restoreId = session.fcRestoreId;
+ addFreshchatScript();
+ }
+ }
+ });
+ `
+
+ setPostBodyComponents([
+ ,
+
+ ])
+}
\ No newline at end of file
diff --git a/plugins/gatsby-plugin-ts-freshchat/index.js b/plugins/gatsby-plugin-ts-freshchat/index.js
new file mode 100644
index 0000000..625c089
--- /dev/null
+++ b/plugins/gatsby-plugin-ts-freshchat/index.js
@@ -0,0 +1 @@
+// noop
\ No newline at end of file
diff --git a/plugins/gatsby-plugin-ts-freshchat/package.json b/plugins/gatsby-plugin-ts-freshchat/package.json
new file mode 100644
index 0000000..dd65d0d
--- /dev/null
+++ b/plugins/gatsby-plugin-ts-freshchat/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "gatsby-plugin-ts-freshchat",
+ "version": "1.0.0",
+ "description": "Gatsby Plugin to add Freshchat to Testsigma sites",
+ "main": "index.js"
+}
diff --git a/src/components/EditButton.jsx b/src/components/EditButton.jsx
index b9d8cfb..c1776b0 100644
--- a/src/components/EditButton.jsx
+++ b/src/components/EditButton.jsx
@@ -20,6 +20,7 @@ class EditDoc extends Component {
const classes = className ? `${className}` : '';
const { pathRoute } = this.state;
return (
+ pathRoute &&