@@ -18,6 +18,7 @@ import { Button } from "@/components/ui/button";
1818import { DynamicHeight } from "@/components/ui/DynamicHeight" ;
1919import { Spinner } from "@/components/ui/Spinner/Spinner" ;
2020import { AutoResizeTextarea } from "@/components/ui/textarea" ;
21+ import { useLocalStorage } from "@/hooks/useLocalStorage" ;
2122import { cn } from "@/lib/utils" ;
2223import { ThirdwebMiniLogo } from "../../../../../../components/ThirdwebMiniLogo" ;
2324import { submitSupportFeedback } from "../apis/feedback" ;
@@ -33,10 +34,6 @@ interface SupportCaseDetailsProps {
3334 team : Team ;
3435}
3536
36- // Helper function to generate localStorage key for feedback submission
37- const getFeedbackSubmittedKey = ( ticketId : string ) =>
38- `feedback_submitted_${ ticketId } ` ;
39-
4037export function SupportCaseDetails ( { ticket, team } : SupportCaseDetailsProps ) {
4138 const [ replyMessage , setReplyMessage ] = useState ( "" ) ;
4239 const [ isSubmittingReply , setIsSubmittingReply ] = useState ( false ) ;
@@ -47,14 +44,11 @@ export function SupportCaseDetails({ ticket, team }: SupportCaseDetailsProps) {
4744 const [ feedback , setFeedback ] = useState ( "" ) ;
4845
4946 // Check if feedback has already been submitted for this ticket
50- const [ feedbackSubmitted , setFeedbackSubmitted ] = useState ( ( ) => {
51- if ( typeof window !== "undefined" ) {
52- return (
53- localStorage . getItem ( getFeedbackSubmittedKey ( ticket . id ) ) === "true"
54- ) ;
55- }
56- return false ;
57- } ) ;
47+ const [ feedbackSubmitted , setFeedbackSubmitted ] = useLocalStorage (
48+ `feedback_submitted_${ ticket . id } ` ,
49+ false ,
50+ false ,
51+ ) ;
5852
5953 const handleStarClick = ( starIndex : number ) => {
6054 setRating ( starIndex + 1 ) ;
@@ -78,8 +72,7 @@ export function SupportCaseDetails({ ticket, team }: SupportCaseDetailsProps) {
7872 throw new Error ( result . error ) ;
7973 }
8074
81- // Mark feedback as submitted in localStorage
82- localStorage . setItem ( getFeedbackSubmittedKey ( ticket . id ) , "true" ) ;
75+ // Mark feedback as submitted
8376 setFeedbackSubmitted ( true ) ;
8477
8578 toast . success ( "Thank you for your feedback!" ) ;
@@ -89,7 +82,7 @@ export function SupportCaseDetails({ ticket, team }: SupportCaseDetailsProps) {
8982 console . error ( "Failed to submit feedback:" , error ) ;
9083 toast . error ( "Failed to submit feedback. Please try again." ) ;
9184 }
92- } , [ rating , feedback , ticket . id , team . id ] ) ;
85+ } , [ rating , feedback , ticket . id , team . id , setFeedbackSubmitted ] ) ;
9386
9487 const handleSendReply = async ( ) => {
9588 if ( ! team . unthreadCustomerId ) {
0 commit comments