11import { useState } from 'react'
2+ import { useState } from 'react'
23import { motion , AnimatePresence } from 'framer-motion'
34import { MessageSquarePlus , X , Send , Loader2 , CheckCircle2 } from 'lucide-react'
45import { Button } from '@/components/ui/button'
@@ -23,13 +24,15 @@ export function FeedbackWidget() {
2324 const [ email , setEmail ] = useState ( '' )
2425 const [ sending , setSending ] = useState ( false )
2526 const [ sent , setSent ] = useState ( false )
27+ const [ error , setError ] = useState < string | null > ( null )
2628
2729 const userEmail = session ?. user ?. email || ''
2830
2931 const handleSubmit = async ( ) => {
3032 if ( ! mood && ! message . trim ( ) ) return
3133
3234 setSending ( true )
35+ setError ( null )
3336
3437 try {
3538 const response = await fetch ( `${ API_URL } /api/v1/feedback` , {
@@ -53,9 +56,11 @@ export function FeedbackWidget() {
5356 setMood ( null )
5457 setMessage ( '' )
5558 setEmail ( '' )
59+ setError ( null )
5660 } , 2000 )
57- } catch ( error ) {
58- console . error ( 'Failed to send feedback:' , error )
61+ } catch ( err ) {
62+ const message = err instanceof Error ? err . message : 'Failed to send feedback'
63+ setError ( message )
5964 } finally {
6065 setSending ( false )
6166 }
@@ -67,7 +72,7 @@ export function FeedbackWidget() {
6772 < >
6873 { /* Floating Button */ }
6974 < motion . button
70- onClick = { ( ) => setIsOpen ( true ) }
75+ onClick = { ( ) => { setIsOpen ( true ) ; setError ( null ) } }
7176 className = "fixed bottom-6 right-6 z-40 flex items-center gap-2 px-4 py-3 bg-primary text-primary-foreground rounded-full shadow-lg hover:shadow-xl transition-shadow"
7277 whileHover = { { scale : 1.05 } }
7378 whileTap = { { scale : 0.95 } }
@@ -185,6 +190,10 @@ export function FeedbackWidget() {
185190 />
186191 </ div >
187192 ) }
193+
194+ { error && (
195+ < p className = "text-sm text-red-500" > { error } </ p >
196+ ) }
188197 </ >
189198 ) }
190199 </ div >
0 commit comments