docs: improved feedback component (#3026)
This commit is contained in:
1 parent
e1292dca5f
commit
dc26a28a53
3 files changed
+44
-11
No files matched your search
@@ -32,6 +32,7 @@
|
|||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
"react-transition-group": "^4.4.5",
|
"react-transition-group": "^4.4.5",
|
||||||
|
"react-uuid": "^2.0.0",
|
||||||
"redocusaurus": "^1.4.0",
|
"redocusaurus": "^1.4.0",
|
||||||
"url-loader": "^4.1.1"
|
"url-loader": "^4.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState, useEffect } from 'react';
|
||||||
import { CSSTransition, SwitchTransition } from 'react-transition-group';
|
import { CSSTransition, SwitchTransition } from 'react-transition-group';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||||
import {useLocation} from '@docusaurus/router';
|
import {useLocation} from '@docusaurus/router';
|
||||||
|
import uuid from 'react-uuid';
|
||||||
|
|
||||||
export default function Feedback ({
|
export default function Feedback ({
|
||||||
event,
|
event,
|
||||||
@@ -21,46 +22,69 @@ export default function Feedback ({
|
|||||||
const inlineFeedbackRef = useRef(null);
|
const inlineFeedbackRef = useRef(null);
|
||||||
const inlineQuestionRef = useRef(null);
|
const inlineQuestionRef = useRef(null);
|
||||||
const inlineMessageRef = useRef(null)
|
const inlineMessageRef = useRef(null)
|
||||||
const [positiveFeedback, setPositiveFeedbac] = useState(false);
|
const [positiveFeedback, setPositiveFeedback] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
|
const [id, setId] = useState(null)
|
||||||
const nodeRef = submittedFeedback ? inlineMessageRef : (showForm ? inlineQuestionRef : inlineFeedbackRef);
|
const nodeRef = submittedFeedback ? inlineMessageRef : (showForm ? inlineQuestionRef : inlineFeedbackRef);
|
||||||
|
|
||||||
const isBrowser = useIsBrowser();
|
const isBrowser = useIsBrowser();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
function handleFeedback (e) {
|
function handleFeedback (e) {
|
||||||
submitFeedback()
|
const feedback = e.target.classList.contains('positive');
|
||||||
setPositiveFeedbac(e.target.classList.contains('positive'));
|
submitFeedback(e, feedback)
|
||||||
|
setPositiveFeedback(feedback);
|
||||||
setShowForm(true);
|
setShowForm(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitFeedback () {
|
function submitFeedback (e, feedback = null) {
|
||||||
|
console.log(id, feedback, (feedback !== null && feedback) || (feedback === null && positiveFeedback) ? 'yes' : 'no')
|
||||||
if (isBrowser) {
|
if (isBrowser) {
|
||||||
|
console.log("here1");
|
||||||
if (window.analytics) {
|
if (window.analytics) {
|
||||||
|
console.log("here3");
|
||||||
if (showForm) {
|
if (showForm) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
}
|
}
|
||||||
|
console.log("here4");
|
||||||
window.analytics.track(event, {
|
window.analytics.track(event, {
|
||||||
url: location.pathname,
|
url: location.pathname,
|
||||||
label: document.title,
|
label: document.title,
|
||||||
feedback: positiveFeedback ? 'yes' : 'no',
|
feedback: (feedback !== null && feedback) || (feedback === null && positiveFeedback) ? 'yes' : 'no',
|
||||||
message
|
message,
|
||||||
|
uuid: id
|
||||||
}, function () {
|
}, function () {
|
||||||
|
console.log("here5");
|
||||||
if (showForm) {
|
if (showForm) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setShowForm(false);
|
console.log("here6");
|
||||||
setSubmittedFeedback(true);
|
resetForm();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
console.log("here7");
|
||||||
if (showForm) {
|
if (showForm) {
|
||||||
setShowForm(false);
|
console.log("here8");
|
||||||
setSubmittedFeedback(true);
|
resetForm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetForm () {
|
||||||
|
setShowForm(false);
|
||||||
|
setSubmittedFeedback(true);
|
||||||
|
if (message) {
|
||||||
|
setId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id) {
|
||||||
|
setId(uuid())
|
||||||
|
}
|
||||||
|
}, [id])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='feedback-container'>
|
<div className='feedback-container'>
|
||||||
<SwitchTransition mode="out-in">
|
<SwitchTransition mode="out-in">
|
||||||
|
|||||||
@@ -5528,6 +5528,7 @@ __metadata:
|
|||||||
react: ^17.0.1
|
react: ^17.0.1
|
||||||
react-dom: ^17.0.1
|
react-dom: ^17.0.1
|
||||||
react-transition-group: ^4.4.5
|
react-transition-group: ^4.4.5
|
||||||
|
react-uuid: ^2.0.0
|
||||||
redocusaurus: ^1.4.0
|
redocusaurus: ^1.4.0
|
||||||
url-loader: ^4.1.1
|
url-loader: ^4.1.1
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
@@ -9892,6 +9893,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"react-uuid@npm:^2.0.0":
|
||||||
|
version: 2.0.0
|
||||||
|
resolution: "react-uuid@npm:2.0.0"
|
||||||
|
checksum: 91f35c83911a2072f181eee0092b45f9ea3590d22268cf8418721756d53205dd9029a873b36a00913807651a0ea5548cc0fc60bad8c4f09bcd7cb03e6ae39ecf
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"react@npm:^17.0.1":
|
"react@npm:^17.0.1":
|
||||||
version: 17.0.2
|
version: 17.0.2
|
||||||
resolution: "react@npm:17.0.2"
|
resolution: "react@npm:17.0.2"
|
||||||
|
|||||||
Reference in new issue
Block a user