11'use client' ;
22import { Fragment , useEffect , useState } from 'react' ;
33import { CheckIcon as Check } from '@radix-ui/react-icons' ;
4+ import { Button } from '@radix-ui/themes' ;
45import * as Sentry from '@sentry/browser' ;
56
67import { usePlausibleEvent } from 'sentry-docs/hooks/usePlausibleEvent' ;
78
8- import { Modal } from '../modal' ;
9-
109type Props = {
1110 pathname : string ;
1211} ;
1312
1413export function DocFeedback ( { pathname} : Props ) {
1514 const { emit} = usePlausibleEvent ( ) ;
16- const [ showFeedbackModal , setShowFeedbackModal ] = useState ( false ) ;
15+ const [ showFeedback , setShowFeedback ] = useState ( false ) ;
1716 const [ feedbackSubmitted , setFeedbackSubmitted ] = useState ( false ) ;
17+ const [ feedbackType , setFeedbackType ] = useState < 'helpful' | 'not_helpful' | null > (
18+ null
19+ ) ;
1820
1921 // Initialize feedback state from sessionStorage
2022 useEffect ( ( ) => {
@@ -24,26 +26,10 @@ export function DocFeedback({pathname}: Props) {
2426 }
2527 } , [ pathname ] ) ;
2628
27- // Auto-close modal after feedback submission
28- useEffect ( ( ) => {
29- if ( feedbackSubmitted && showFeedbackModal ) {
30- const timer = setTimeout ( ( ) => {
31- setShowFeedbackModal ( false ) ;
32- } , 3000 ) ;
33-
34- return ( ) => clearTimeout ( timer ) ;
35- }
36- } , [ feedbackSubmitted , showFeedbackModal ] ) ;
37-
3829 const handleFeedback = ( helpful : boolean ) => {
3930 emit ( 'Doc Feedback' , { props : { page : pathname , helpful} } ) ;
40-
41- if ( helpful ) {
42- setFeedbackSubmitted ( true ) ;
43- sessionStorage . setItem ( `feedback_${ pathname } ` , 'submitted' ) ;
44- } else {
45- setShowFeedbackModal ( true ) ;
46- }
31+ setFeedbackType ( helpful ? 'helpful' : 'not_helpful' ) ;
32+ setShowFeedback ( true ) ;
4733 } ;
4834
4935 const handleSubmitFeedback = ( e : React . FormEvent < HTMLFormElement > ) => {
@@ -53,8 +39,10 @@ export function DocFeedback({pathname}: Props) {
5339
5440 try {
5541 Sentry . captureFeedback (
56- { message : comments } ,
57- { captureContext : { tags : { page : pathname } } }
42+ {
43+ message : comments ,
44+ } ,
45+ { captureContext : { tags : { page : pathname , type : feedbackType } } }
5846 ) ;
5947 setFeedbackSubmitted ( true ) ;
6048 sessionStorage . setItem ( `feedback_${ pathname } ` , 'submitted' ) ;
@@ -69,85 +57,64 @@ export function DocFeedback({pathname}: Props) {
6957
7058 return (
7159 < Fragment >
72- < div className = "flex items-center gap-2 py-4 border-t border-[var(--gray-6)]" >
60+ < div className = "space-y-4 py-4 border-[var(--gray-6)]" >
7361 { feedbackSubmitted ? (
7462 < div className = "flex items-center gap-2 text-sm text-[var(--gray-11)]" >
7563 < Check className = "w-4 h-4" /> Thanks for your feedback
7664 </ div >
7765 ) : (
7866 < Fragment >
79- < span className = "text-sm" > Was this helpful?</ span >
80- < button
81- onClick = { ( ) => {
82- handleFeedback ( true ) ;
83- } }
84- className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
85- aria-label = "Yes, this was helpful"
86- >
87- Yes 🙂
88- </ button >
89- < button
90- onClick = { ( ) => handleFeedback ( false ) }
91- className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
92- aria-label = "No, this wasn't helpful"
93- >
94- No 🙁
95- </ button >
96- </ Fragment >
97- ) }
98- </ div >
99-
100- < Modal
101- isOpen = { showFeedbackModal }
102- onClose = { ( ) => {
103- setShowFeedbackModal ( false ) ;
104- setFeedbackSubmitted ( false ) ;
105- } }
106- title = { feedbackSubmitted ? 'Thanks for your feedback!' : 'Help us improve' }
107- >
108- { feedbackSubmitted ? (
109- < div className = "text-center" >
110- < p className = "text-[var(--gray-11)] p-0 m-0" >
111- We appreciate your help in making our documentation better.
112- </ p >
113- </ div >
114- ) : (
115- < form onSubmit = { handleSubmitFeedback } className = "space-y-4" >
116- < p className = "text-[var(--gray-11)] p-0 m-0" >
117- We'd love to hear more about how we can improve this page. Your feedback
118- helps us make our documentation better for everyone.
119- </ p >
120- < div >
121- < label htmlFor = "comments" className = "block text-sm font-medium mb-4" >
122- What could we improve?
123- </ label >
124- < textarea
125- id = "comments"
126- name = "comments"
127- required
128- rows = { 4 }
129- className = "w-full px-3 py-2 border border-[var(--gray-6)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent)] bg-transparent"
130- placeholder = "Please share your suggestions..."
131- />
132- </ div >
133- < div className = "flex justify-end gap-3" >
67+ < div className = "flex items-center gap-2" >
68+ < span className = "text-sm" > Was this helpful?</ span >
13469 < button
135- type = "button"
136- onClick = { ( ) => setShowFeedbackModal ( false ) }
137- className = "px-4 py-2 text-sm hover:bg-[var(--gray-3)] rounded-lg "
70+ onClick = { ( ) => handleFeedback ( true ) }
71+ className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
72+ aria-label = "Yes, this was helpful "
13873 >
139- Cancel
74+ Yes 🙂
14075 </ button >
14176 < button
142- type = "submit"
143- className = "px-4 py-2 text-sm bg-[var(--accent-purple)] rounded-lg"
77+ onClick = { ( ) => handleFeedback ( false ) }
78+ className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
79+ aria-label = "No, this wasn't helpful"
14480 >
145- Submit feedback
81+ No 🙁
14682 </ button >
14783 </ div >
148- </ form >
84+
85+ < div
86+ className = { `overflow-hidden transition-all duration-300 ease-in-out ${
87+ showFeedback ? 'max-h-[300px] opacity-100' : 'max-h-0 opacity-0'
88+ } `}
89+ >
90+ < form onSubmit = { handleSubmitFeedback } className = "space-y-4" >
91+ < div >
92+ < label htmlFor = "comments" className = "block text-sm font-medium mb-4" >
93+ { feedbackType === 'helpful'
94+ ? 'What did you like about this page?'
95+ : 'How can we improve this page?' }
96+ </ label >
97+ < textarea
98+ id = "comments"
99+ name = "comments"
100+ required
101+ rows = { 2 }
102+ className = "w-[calc(100%-4px)] ml-[2px] px-3 py-2 border border-[var(--gray-6)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent)] bg-transparent text-sm"
103+ placeholder = "Please share your thoughts..."
104+ />
105+ </ div >
106+ < Button
107+ type = "submit"
108+ className = "px-4 py-2 text-sm rounded-lg bg-[var(--accent-purple)]"
109+ size = { '3' }
110+ >
111+ Submit feedback
112+ </ Button >
113+ </ form >
114+ </ div >
115+ </ Fragment >
149116 ) }
150- </ Modal >
117+ </ div >
151118 </ Fragment >
152119 ) ;
153120}
0 commit comments