1
- import React , { useState } from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
3
3
const Feedback = ( ) => {
4
4
const [ feedback , setFeedback ] = useState ( null ) ;
5
5
const [ showTextBox , setShowTextBox ] = useState ( false ) ;
6
6
const [ textBoxContent , setTextBoxContent ] = useState ( '' ) ;
7
+ const [ submitted , setSubmitted ] = useState ( false ) ;
7
8
8
9
const handleFeedback = ( type ) => {
9
10
setFeedback ( type ) ;
@@ -28,69 +29,97 @@ const Feedback = () => {
28
29
feedback_text : text ,
29
30
} ) ;
30
31
}
32
+ setSubmitted ( true ) ;
31
33
} ;
32
34
33
35
const handleSubmit = ( ) => {
34
36
sendFeedback ( feedback , textBoxContent ) ;
35
37
setShowTextBox ( false ) ;
36
38
setTextBoxContent ( '' ) ;
37
- alert ( 'Thank you for your feedback!' ) ;
38
39
} ;
39
40
40
41
return (
41
42
< 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 >
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 >
94
123
) }
95
124
</ div >
96
125
) ;
0 commit comments