Skip to content

Commit 455317a

Browse files
committed
Change star rating to thumbs up/down instead.
1 parent 53a465d commit 455317a

File tree

4 files changed

+86
-43
lines changed

4 files changed

+86
-43
lines changed

package-lock.json

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"clsx": "^2.0.0",
2727
"prism-react-renderer": "^2.3.0",
2828
"react": "^18.0.0",
29-
"react-dom": "^18.0.0",
30-
"react-simple-star-rating": "^5.1.7"
29+
"react-dom": "^18.0.0"
3130
},
3231
"devDependencies": {
3332
"@docusaurus/module-type-aliases": "3.1.1",

src/components/Feedback/index.js

Lines changed: 82 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,97 @@
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('');
67

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

22+
const sendFeedback = (type, text) => {
1123
if (window.gtag) {
12-
window.gtag('event', 'rating', {
24+
window.gtag('event', 'feedback', {
1325
event_category: 'Feedback',
1426
event_label: window.location.pathname,
15-
value: rate,
27+
feedback_type: type,
28+
feedback_text: text,
1629
});
1730
}
1831
};
1932

33+
const handleSubmit = () => {
34+
sendFeedback(feedback, textBoxContent);
35+
setShowTextBox(false);
36+
setTextBoxContent('');
37+
alert('Thank you for your feedback!');
38+
};
39+
2040
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>*/}
41+
<div style={{ textAlign: 'left', marginBottom: '2vh' }}>
42+
<div style={{fontSize: '12px'}}>Was the content helpful?</div>
43+
<div style={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
44+
<div
45+
onClick={() => handleFeedback('thumbs_up')}
46+
style={{
47+
cursor: 'pointer',
48+
color: feedback === 'thumbs_up' ? 'green' : 'gray',
49+
fontSize: '24px',
50+
}}
51+
>
52+
👍
53+
</div>
54+
<div
55+
onClick={() => handleFeedback('thumbs_down')}
56+
style={{
57+
cursor: 'pointer',
58+
color: feedback === 'thumbs_down' ? 'red' : 'gray',
59+
fontSize: '24px',
60+
}}
61+
>
62+
👎
63+
</div>
64+
</div>
65+
{showTextBox && (
66+
<div style={{ marginTop: '20px' }}>
67+
<textarea
68+
value={textBoxContent}
69+
onChange={handleTextBoxChange}
70+
placeholder="Please let us know why you didn't find the content helpful."
71+
style={{
72+
width: '100%',
73+
height: '100px',
74+
padding: '10px',
75+
borderColor: 'lightgray',
76+
}}
77+
/>
78+
<button
79+
onClick={handleSubmit}
80+
style={{
81+
marginTop: '10px',
82+
padding: '10px 20px',
83+
backgroundColor: 'var(--ifm-color-primary)',
84+
color: 'white',
85+
border: 'none',
86+
cursor: 'pointer',
87+
fontFamily: 'var(--ifm-font-family-base)',
88+
borderRadius: '8px', // Rounded edges
89+
}}
90+
>
91+
Send
92+
</button>
93+
</div>
94+
)}
3395
</div>
3496
);
3597
};

yarn.lock

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6956,7 +6956,7 @@ react-dev-utils@^12.0.1:
69566956
strip-ansi "^6.0.1"
69576957
text-table "^0.2.0"
69586958

6959-
react-dom@*, "react-dom@^16.6.0 || ^17.0.0 || ^18.0.0", react-dom@^18.0.0, "react-dom@>= 16.8.0 < 19.0.0", react-dom@>=18.0.0:
6959+
react-dom@*, "react-dom@^16.6.0 || ^17.0.0 || ^18.0.0", react-dom@^18.0.0, "react-dom@>= 16.8.0 < 19.0.0":
69606960
version "18.3.1"
69616961
resolved "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz"
69626962
integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==
@@ -7052,12 +7052,7 @@ react-router@^5.3.4, react-router@>=5, [email protected]:
70527052
tiny-invariant "^1.0.2"
70537053
tiny-warning "^1.0.0"
70547054

7055-
react-simple-star-rating@^5.1.7:
7056-
version "5.1.7"
7057-
resolved "https://registry.npmjs.org/react-simple-star-rating/-/react-simple-star-rating-5.1.7.tgz"
7058-
integrity sha512-NTFkW8W3uwvI82Fv7JW5i7gmDjEZKxJmj+Z9vn+BjYIXT6ILdnU9qnSUP2cWrWN/WAUlue81f9SgM4CQcenltQ==
7059-
7060-
react@*, "react@^16.13.1 || ^17.0.0 || ^18.0.0", "react@^16.6.0 || ^17.0.0 || ^18.0.0", react@^18.0.0, react@^18.3.1, "react@>= 16.8.0 < 19.0.0", react@>=15, react@>=16, react@>=16.0.0, react@>=18.0.0:
7055+
react@*, "react@^16.13.1 || ^17.0.0 || ^18.0.0", "react@^16.6.0 || ^17.0.0 || ^18.0.0", react@^18.0.0, react@^18.3.1, "react@>= 16.8.0 < 19.0.0", react@>=15, react@>=16, react@>=16.0.0:
70617056
version "18.3.1"
70627057
resolved "https://registry.npmjs.org/react/-/react-18.3.1.tgz"
70637058
integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==

0 commit comments

Comments
 (0)