11'use client' ;
2- import { Fragment , useState } from 'react' ;
2+ import { Fragment , useEffect , useState } from 'react' ;
3+ import { CheckIcon as Check } from '@radix-ui/react-icons' ;
34import * as Sentry from '@sentry/browser' ;
45
56import { usePlausibleEvent } from 'sentry-docs/hooks/usePlausibleEvent' ;
@@ -15,10 +16,21 @@ export function DocFeedback({pathname}: Props) {
1516 const [ showFeedbackModal , setShowFeedbackModal ] = useState ( false ) ;
1617 const [ feedbackSubmitted , setFeedbackSubmitted ] = useState ( false ) ;
1718
19+ // Initialize feedback state from sessionStorage
20+ useEffect ( ( ) => {
21+ const storedFeedback = sessionStorage . getItem ( `feedback_${ pathname } ` ) ;
22+ if ( storedFeedback === 'submitted' ) {
23+ setFeedbackSubmitted ( true ) ;
24+ }
25+ } , [ pathname ] ) ;
26+
1827 const handleFeedback = ( helpful : boolean ) => {
1928 emit ( 'Doc Feedback' , { props : { page : pathname , helpful} } ) ;
2029
21- if ( ! helpful ) {
30+ if ( helpful ) {
31+ setFeedbackSubmitted ( true ) ;
32+ sessionStorage . setItem ( `feedback_${ pathname } ` , 'submitted' ) ;
33+ } else {
2234 setShowFeedbackModal ( true ) ;
2335 }
2436 } ;
@@ -34,6 +46,7 @@ export function DocFeedback({pathname}: Props) {
3446 { captureContext : { tags : { page : pathname } } }
3547 ) ;
3648 setFeedbackSubmitted ( true ) ;
49+ sessionStorage . setItem ( `feedback_${ pathname } ` , 'submitted' ) ;
3750 } catch ( error ) {
3851 // eslint-disable-next-line no-console
3952 console . error ( 'Failed to submit feedback:' , error ) ;
@@ -43,21 +56,31 @@ export function DocFeedback({pathname}: Props) {
4356 return (
4457 < Fragment >
4558 < div className = "flex items-center gap-2 py-4 border-t border-[var(--gray-6)]" >
46- < span className = "text-sm" > Was this helpful?</ span >
47- < button
48- onClick = { ( ) => handleFeedback ( true ) }
49- className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
50- aria-label = "Yes, this was helpful"
51- >
52- Yes 👍
53- </ button >
54- < button
55- onClick = { ( ) => handleFeedback ( false ) }
56- className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
57- aria-label = "No, this wasn't helpful"
58- >
59- No 👎
60- </ button >
59+ { feedbackSubmitted ? (
60+ < div className = "flex items-center gap-2 text-sm text-[var(--gray-11)]" >
61+ < Check className = "w-4 h-4" /> Thanks for your feedback
62+ </ div >
63+ ) : (
64+ < Fragment >
65+ < span className = "text-sm" > Was this helpful?</ span >
66+ < button
67+ onClick = { ( ) => {
68+ handleFeedback ( true ) ;
69+ } }
70+ className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
71+ aria-label = "Yes, this was helpful"
72+ >
73+ Yes 👍
74+ </ button >
75+ < button
76+ onClick = { ( ) => handleFeedback ( false ) }
77+ className = "py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center"
78+ aria-label = "No, this wasn't helpful"
79+ >
80+ No 👎
81+ </ button >
82+ </ Fragment >
83+ ) }
6184 </ div >
6285
6386 < Modal
0 commit comments