Skip to content

Commit a729387

Browse files
authored
Feedback UI fixes (#82)
* Add feedback widget with gtag event * Add index file that I forgot :) * Change star rating to thumbs up/down instead. * Update feedback to thumbs up/thumbs down approach
1 parent 4c1df9b commit a729387

File tree

1 file changed

+111
-20
lines changed

1 file changed

+111
-20
lines changed

src/components/Feedback/index.js

Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,126 @@
1-
import React, { useState, useEffect } from 'react';
2-
import { Rating } from 'react-simple-star-rating';
1+
import React, {useState} from 'react';
32

43
const Feedback = () => {
5-
const [rating, setRating] = useState(0);
4+
const [feedback, setFeedback] = useState(null);
5+
const [showTextBox, setShowTextBox] = useState(false);
6+
const [textBoxContent, setTextBoxContent] = useState('');
7+
const [submitted, setSubmitted] = useState(false);
68

7-
const handleRating = (rate) => {
8-
setRating(rate);
9-
console.log(window.location.pathname.toString())
9+
const handleFeedback = (type) => {
10+
setFeedback(type);
11+
if (type === 'thumbs_down') {
12+
setShowTextBox(true);
13+
} else {
14+
setShowTextBox(false);
15+
sendFeedback(type, '');
16+
}
17+
};
18+
19+
const handleTextBoxChange = (event) => {
20+
setTextBoxContent(event.target.value);
21+
};
1022

23+
const sendFeedback = (type, text) => {
1124
if (window.gtag) {
12-
window.gtag('event', 'rating', {
25+
window.gtag('event', 'feedback', {
1326
event_category: 'Feedback',
1427
event_label: window.location.pathname,
15-
value: rate,
28+
feedback_type: type,
29+
feedback_text: text,
1630
});
1731
}
32+
setSubmitted(true);
33+
};
34+
35+
const handleSubmit = () => {
36+
sendFeedback(feedback, textBoxContent);
37+
setShowTextBox(false);
38+
setTextBoxContent('');
1839
};
1940

2041
return (
21-
<div style={{ textAlign: 'left', marginTop: '0vh' }}>
22-
<Rating
23-
onClick={handleRating}
24-
ratingValue={rating}
25-
size={40}
26-
fillColor="orange"
27-
emptyColor="lightgray"
28-
transition
29-
/>
30-
{/*<div style={{ marginTop: '20px', fontSize: '18px' }}>*/}
31-
{/* Your Rating: {rating / 20} stars*/}
32-
{/*</div>*/}
42+
<div style={{ textAlign: 'left', marginBottom: '2vh' }}>
43+
{!submitted ? (
44+
<>
45+
<p style={{ fontWeight: 'bold' }}>Was this article helpful?</p>
46+
<div style={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
47+
<button
48+
onClick={() => handleFeedback('thumbs_up')}
49+
style={{
50+
display: 'flex',
51+
alignItems: 'center',
52+
justifyContent: 'center',
53+
cursor: 'pointer',
54+
color: feedback === 'thumbs_up' ? 'var(--ifm-color-primary)' : 'gray',
55+
backgroundColor: '#f0f0f0',
56+
border: '1px #f0f0f0',
57+
borderRadius: '8px',
58+
padding: '10px 20px',
59+
fontSize: '16px',
60+
fontFamily: 'var(--ifm-font-family-base)',
61+
gap: '5px',
62+
}}
63+
>
64+
👍 Yes
65+
</button>
66+
<button
67+
onClick={() => handleFeedback('thumbs_down')}
68+
style={{
69+
display: 'flex',
70+
alignItems: 'center',
71+
justifyContent: 'center',
72+
cursor: 'pointer',
73+
color: feedback === 'thumbs_down' ? 'var(--ifm-color-primary)' : 'gray',
74+
backgroundColor: '#f0f0f0',
75+
border: '1px #f0f0f0',
76+
borderRadius: '8px',
77+
padding: '10px 20px',
78+
fontSize: '16px',
79+
fontFamily: 'var(--ifm-font-family-base)',
80+
gap: '5px',
81+
}}
82+
>
83+
👎 No
84+
</button>
85+
</div>
86+
{showTextBox && (
87+
<div style={{ marginTop: '20px' }}>
88+
<textarea
89+
value={textBoxContent}
90+
onChange={handleTextBoxChange}
91+
placeholder="How can we make it better?"
92+
style={{
93+
width: '100%',
94+
height: '100px',
95+
padding: '10px',
96+
borderColor: 'lightgray',
97+
borderRadius: '8px',
98+
fontFamily: 'var(--ifm-font-family-base)',
99+
}}
100+
/>
101+
<button
102+
onClick={handleSubmit}
103+
style={{
104+
marginTop: '10px',
105+
padding: '10px 20px',
106+
backgroundColor: 'var(--ifm-color-primary)',
107+
color: 'white',
108+
border: 'none',
109+
cursor: 'pointer',
110+
fontFamily: 'var(--ifm-font-family-base)',
111+
borderRadius: '8px',
112+
}}
113+
>
114+
Submit Feedback
115+
</button>
116+
</div>
117+
)}
118+
</>
119+
) : (
120+
<p style={{ fontWeight: 'bold', color: 'var(--ifm-color-primary)' }}>
121+
Thank you for your feedback!
122+
</p>
123+
)}
33124
</div>
34125
);
35126
};

0 commit comments

Comments
 (0)