-
Notifications
You must be signed in to change notification settings - Fork 159
/
index.js
104 lines (92 loc) · 2.65 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import useIsBrowser from "@docusaurus/useIsBrowser";
import React, { useEffect, useState } from "react";
import { v4 as uuid } from "uuid";
import styles from "./styles.module.css";
const Feedback = () => {
const isBrowser = useIsBrowser();
const [feedback, setFeedback] = useState("");
const [message, setMessage] = useState("");
const [sent, setSent] = useState(false);
const [id, setId] = useState(null);
const submit = () => {
if (isBrowser && window.analytics) {
window.analytics.track(feedback, {
pathname: window.location.pathname,
title: document.title,
feedback: `feedback_${feedback}`,
message,
uuid: id,
});
}
setFeedback("");
setMessage("");
setSent(true);
};
const formQuestion = () => {
return feedback === "positive"
? "What was most helpful?"
: "What can we improve?";
};
useEffect(() => {
if (!id) {
setId(uuid());
}
}, [id]);
return (
<>
<hr className="docusaurus-mt-lg" />
{feedback === "" && !sent && (
<div className="row">
<div className="col">
<span className="padding-right--lg">Was this page helpful?</span>
<span className={styles.buttons}>
<button
onClick={() => setFeedback("positive")}
className="button button--primary button--sm margin-right--md"
>
Yes
</button>
<button
onClick={() => setFeedback("negative")}
className="button button--primary button--sm margin-right--md"
>
No
</button>
</span>
</div>
</div>
)}
{feedback !== "" && !sent && (
<div className="row">
<div className="col">
<div>{formQuestion()}</div>
<textarea
className={styles.message}
rows={4}
value={message}
onChange={(event) => setMessage(event.target.value)}
autoFocus
></textarea>
<div>
<button
className="button button--primary button--sm margin-right--md"
onClick={submit}
>
Submit
</button>
<button
className="button button--link button--sm"
onClick={() => setFeedback("")}
>
Cancel
</button>
</div>
</div>
</div>
)}
{sent && <strong>Thank you for your feedback!</strong>}
<hr />
</>
);
};
export default Feedback;