|
1 |
| -import React, { useState, useEffect } from 'react'; |
2 |
| -import { Rating } from 'react-simple-star-rating'; |
| 1 | +import React, { useState } from 'react'; |
3 | 2 |
|
4 | 3 | 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(''); |
6 | 7 |
|
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 | + }; |
10 | 21 |
|
| 22 | + const sendFeedback = (type, text) => { |
11 | 23 | if (window.gtag) {
|
12 |
| - window.gtag('event', 'rating', { |
| 24 | + window.gtag('event', 'feedback', { |
13 | 25 | event_category: 'Feedback',
|
14 | 26 | event_label: window.location.pathname,
|
15 |
| - value: rate, |
| 27 | + feedback_type: type, |
| 28 | + feedback_text: text, |
16 | 29 | });
|
17 | 30 | }
|
18 | 31 | };
|
19 | 32 |
|
| 33 | + const handleSubmit = () => { |
| 34 | + sendFeedback(feedback, textBoxContent); |
| 35 | + setShowTextBox(false); |
| 36 | + setTextBoxContent(''); |
| 37 | + alert('Thank you for your feedback!'); |
| 38 | + }; |
| 39 | + |
20 | 40 | 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 | + )} |
33 | 95 | </div>
|
34 | 96 | );
|
35 | 97 | };
|
|
0 commit comments