diff --git a/.eslintrc b/.eslintrc index 0cd19a8e..95dbafbe 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,5 +11,8 @@ "brace-style": ["warn", "1tbs", { "allowSingleLine": true }], "max-len": [1, 160, 2], "spaced-comment": "off" + }, + "env": { + "browser": true } } diff --git a/src/css/feedback.css b/src/css/feedback.css index cfdb3c70..73a7793f 100644 --- a/src/css/feedback.css +++ b/src/css/feedback.css @@ -1,13 +1,13 @@ .feedback { position: fixed; bottom: 0; - right: 2rem; + left: 1rem; border-top-left-radius: 0.25rem; border-top-right-radius: 0.25rem; background: var(--feedback-background-color); color: var(--feedback-color); padding: 0.5rem 1rem; - width: 320px; + width: calc(var(--nav-width) - 2rem); font-size: 0.8rem; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); z-index: 1000; @@ -74,6 +74,10 @@ font-size: 0.8rem; } +.feedback div.more-information { + margin: 10px 0; +} + .feedback textarea { border-radius: 0.25rem; border: 1px solid var(--color-blue-300); @@ -105,6 +109,7 @@ font-weight: 600; margin-right: 0.5rem; margin-bottom: 1rem; + cursor: pointer; } .feedback .primary:focus, @@ -151,6 +156,10 @@ margin-bottom: 0.5rem; } +.feedback .error { + font-size: 0.8rem; +} + @media all and (max-width: 1024px) { .feedback { position: relative; @@ -159,7 +168,7 @@ max-width: var(--doc-max-width); min-width: 0; right: auto; - width: auto; + width: calc(var(--nav-width) - 2rem); box-shadow: none; margin-bottom: 2rem; } diff --git a/src/css/vars.css b/src/css/vars.css index feb11088..e70d34f4 100644 --- a/src/css/vars.css +++ b/src/css/vars.css @@ -378,8 +378,9 @@ --nav-panel-height: calc(var(--nav-height) - var(--drawer-height)); --nav-panel-height--desktop: calc( - var(--nav-height--desktop) - var(--drawer-height) - ); + var(--nav-height--desktop) - var(--drawer-height) - var(--feedback-height) - 1rem + ); /* 1rem is feedback padding */ + --nav-width: 18rem; --toc-top: calc(var(--body-top) + var(--toolbar-height)); --kb-metadata-top: calc(var(--body-top) + var(--toolbar-height)); @@ -392,6 +393,7 @@ --doc-max-width: calc(720 / var(--rem-base) * 1rem); --doc-max-width--desktop: calc(980 / var(--rem-base) * 1rem); --cheat-sheet-max-width--desktop: calc(1100 / var(--rem-base) * 1rem); + --feedback-height: 2.75rem; /* stacking */ --z-index-nav: 1; diff --git a/src/js/11-feedback.js b/src/js/11-feedback.js index 5fb81ef8..9308aeec 100644 --- a/src/js/11-feedback.js +++ b/src/js/11-feedback.js @@ -1,23 +1,35 @@ const { getCookie } = require('./modules/cookies') +const URL = 'https://uglfznxroe.execute-api.us-east-1.amazonaws.com/dev/Feedback' /* global fetch */ ;(function () { 'use strict' - var url = 'https://uglfznxroe.execute-api.us-east-1.amazonaws.com/dev/Feedback' + const updateUserJourney = function () { + var journey = JSON.parse(localStorage.getItem('userJourney')) + if (journey == null) journey = [] + journey.push({ + url: window.location.href, + title: document.title, + landTime: Math.round(Date.now() / 1000), + }) + localStorage.setItem('userJourney', JSON.stringify(journey)) + } + updateUserJourney() + var feedback = document.querySelector('.feedback') if (!feedback) return var original = feedback.innerHTML var edit = '' - var editLink = document.querySelector('.edit-this-page a') + /*var editLink = document.querySelector('.edit-this-page a') if (editLink) { edit = ' Edit this page' - } + }*/ - var sendFeedback = function (helpful, reason, moreInformation) { + var sendRequest = function (parameters) { const identity = getCookie('neo_identity') const gid = getCookie('_gid') const uetsid = getCookie('_uetsid') @@ -30,7 +42,6 @@ const { getCookie } = require('./modules/cookies') var body = 'project=' + encodeURIComponent(project) body += '&url=' + encodeURIComponent(window.location.href) - body += '&helpful=' + helpful.toString() if (identity) { body += '&identity=' + identity @@ -42,36 +53,90 @@ const { getCookie } = require('./modules/cookies') body += '&uetsid=' + uetsid } - if (!helpful) { - body += '&reason=' + encodeURIComponent(reason) + for (const [paramKey, paramVal] of Object.entries(parameters)) { + body += '&' + paramKey + '=' + encodeURIComponent(paramVal) + } - if (moreInformation) { - body += '&moreInformation=' + encodeURIComponent(moreInformation) - } + var userJourney = localStorage.getItem('userJourney') + if (JSON.parse(userJourney).length > 1) { + body += '&userJourney=' + encodeURIComponent(userJourney) } - fetch(url, { + //console.log(body) + fetch(URL, { method: 'post', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: body, }) + localStorage.removeItem('userJourney') } var isHelpful = function () { - sendFeedback(true) - feedback.classList.add('positive') + feedback.style.height = null + feedback.innerHTML = `
+ ` + + feedback.querySelector('.cancel').addEventListener('click', function (e) { + e.preventDefault() + sendRequest({ helpful: true }) // get positive feedback even if thet bail out before completion + setTimeout(() => { fadeOut(feedback, 50) }, 0) + + if (window.mixpanel) { + window.mixpanel.track('DOCS_FEEDBACK_POSITIVE', { + pathname: window.location.origin + window.location.pathname, + search: window.location.search, + hash: window.location.hash, + }) + } + }) + + feedback.querySelector('.primary').addEventListener('click', function (e) { + e.preventDefault() + + var moreInformation = feedback.querySelector('textarea[name="more-information"]').value + + sendRequest({ + helpful: true, + moreInformation: moreInformation, + }) + feedback.innerHTML = 'Thank you for your feedback!
Thank you for your feedback!
Thank you for your feedback!
-We will take this information into account while updating our documentation.
+Thank you!
+We will consider your feedback while updating our documentation.
` - if (editLink) { + /*if (editLink) { thankyou += 'You can also help us by ' + edit.replace('Edit', 'editing') + '.
Was this page helpful?
+Is this page helpful?