'use client' import { useState, useTransition } from 'react' import { IconMoodNeutral as Meh, IconMoodSad as Frown, IconMoodSmile as Smile } from '@tabler/icons-react' import { toast } from 'sonner' import { submitFeedback } from '@/lib/actions/site-feedback' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Textarea } from '@/components/ui/textarea' type Sentiment = 'positive' | 'neutral' | 'negative' interface FeedbackModalProps { open: boolean onOpenChange: (open: boolean) => void } export function FeedbackModal({ open, onOpenChange }: FeedbackModalProps) { const [sentiment, setSentiment] = useState(null) const [message, setMessage] = useState('') const [isPending, startTransition] = useTransition() const handleSubmit = () => { if (!sentiment || !message.trim()) { toast.error('Please select your sentiment and write a message') return } startTransition(async () => { const result = await submitFeedback({ sentiment, message: message.trim(), pageUrl: window.location.href }) if (result.success) { toast.success('Thank you for your feedback!') // Reset form and close modal setSentiment(null) setMessage('') onOpenChange(false) } else { toast.error('Failed to submit feedback. Please try again later.') } }) } const handleCancel = () => { setSentiment(null) setMessage('') onOpenChange(false) } return ( Give feedback Your feedback helps us improve Morphic. Let us know what you think!