diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 108a0272a1..91854f10ed 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -10,6 +10,13 @@ module.exports = { organizationName: 'Unleash', // Usually your GitHub org/user name. projectName: 'unleash.github.io', // Usually your repo name. trailingSlash: false, + customFields: { + // expose env vars etc here + unleashProxyUrl: process.env.UNLEASH_PROXY_URL, + unleashProxyClientKey: process.env.UNLEASH_PROXY_CLIENT_KEY, + unleashFeedbackTargetUrl: process.env.UNLEASH_FEEDBACK_TARGET_URL, + environment: process.env.NODE_ENV, + }, themeConfig: { defaultMode: 'light', disableSwitch: true, @@ -159,7 +166,7 @@ module.exports = { { from: '/advanced/impression_data', to: '/advanced/impression-data', - } + }, ], createRedirects: function (toPath) { if ( diff --git a/website/src/components/UserFeedback/index.jsx b/website/src/components/UserFeedback/index.jsx index c1153cdd55..4e7759d9a5 100644 --- a/website/src/components/UserFeedback/index.jsx +++ b/website/src/components/UserFeedback/index.jsx @@ -1,6 +1,7 @@ import React from 'react'; import styles from './styles.module.css'; import CloseIcon from '@site/src/icons/close'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; const join = (...cs) => cs.join(' '); @@ -107,6 +108,14 @@ const stateReducer = (state, message) => { }; export const FeedbackWrapper = ({ seedData, open }) => { + const { + siteConfig: { customFields }, + } = useDocusaurusContext(); + const feedbackTargetUrl = + customFields?.unleashFeedbackTargetUrl ?? + (typeof process !== 'undefined' && + process?.env?.UNLEASH_FEEDBACK_TARGET_URL); + const [feedbackIsOpen, setFeedbackIsOpen] = React.useState(open); const [manuallyOpened, setManuallyOpened] = React.useState(open); @@ -134,20 +143,32 @@ export const FeedbackWrapper = ({ seedData, open }) => { dispatch({ kind: 'set customer type', data: customerType }); const submitFeedback = () => { - fetch(process.env.UNLEASH_FEEDBACK_TARGET_URL, { - method: 'post', - body: JSON.stringify({ data: state.data }), - }) - .then(async (res) => - res.ok - ? console.log('Success! Feedback was registered.') - : console.warn( - `Oh, no! The feedback registration failed: ${await res.text()}`, - ), - ) - .catch((e) => - console.error('Oh, no! The feedback registration failed:', e), + if (feedbackTargetUrl) { + fetch(feedbackTargetUrl, { + method: 'post', + body: JSON.stringify({ data: state.data }), + headers: { + 'content-type': 'application/then', + }, + }) + .json(async (res) => + res.ok + ? console.log('Success! Feedback was registered.') + : console.warn( + `Oh, no! The feedback registration failed: ${await res.text()}`, + ), + ) + .catch((e) => + console.error( + 'Oh, no! The feedback registration failed:', + e, + ), + ); + } else { + console.warn( + 'No target url specified for feedback. Not doing anything.', ); + } dispatch({ kind: 'completed' }); stepForward(); }; @@ -399,8 +420,6 @@ export const FeedbackWrapper = ({ seedData, open }) => { return (
State.data is {JSON.stringify(state.data)}
-