diff --git a/frontend/src/components/thread/feedback-modal.tsx b/frontend/src/components/thread/feedback-modal.tsx index ba9efdcf..ccc0e58e 100644 --- a/frontend/src/components/thread/feedback-modal.tsx +++ b/frontend/src/components/thread/feedback-modal.tsx @@ -4,68 +4,83 @@ import { ThumbsDown, ThumbsUp } from "lucide-react"; import { useState } from "react"; import { Textarea } from "../ui/textarea"; import { toast } from "sonner"; +import { apiClient } from '@/lib/api-client'; +interface FeedbackProps { + messageId: string; +} -export default function Feedback({ messageId }: { messageId: string }) { +export default function Feedback({ messageId }: FeedbackProps) { const [open, setOpen] = useState(false); - const [feedback, setFeedback] = useState<'positive' | 'negative' | null>(null); - const [comment, setComment] = useState(''); + const [responseIsGood, setResponseIsGood] = useState(null); + const [feedback, setFeedback] = useState(''); + const [submitting, setSubmitting] = useState(false); - const handleClick = (feedback: 'positive' | 'negative') => { - setFeedback(feedback); + const handleClick = (isGood: boolean) => { + setResponseIsGood(isGood); setOpen(true); - } + }; - const handleSubmit = () => { - if(!feedback) return; - console.log(messageId, feedback, comment); - setOpen(false); - setFeedback(null); - setComment(''); - toast.success('Feedback submitted'); - } + const handleSubmit = async () => { + if (responseIsGood === null) return; + setSubmitting(true); + const { success } = await apiClient.post('/api/feedback', { + message_id: messageId, + response_is_good: responseIsGood, + comment: feedback.trim() || null, + }); + setSubmitting(false); + if (success) { + toast.success('Feedback submitted - thank you!'); + setOpen(false); + setFeedback(''); + setResponseIsGood(null); + } + }; return (
- Feedback + {responseIsGood ? 'Good response' : 'Bad response'} - {`What was ${feedback === 'negative' ? 'un' : ''}satisifying about this response?`} + {`What was ${responseIsGood === false ? 'un' : ''}satisifying about this response?`}