"use client" import { useState } from "react" import { dmSans125ClassName, dmSansClassName } from "@/lib/fonts" import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@ui/components/dialog" import { Textarea } from "@ui/components/textarea" import { Button } from "@ui/components/button" import { cn } from "@lib/utils" import * as DialogPrimitive from "@radix-ui/react-dialog" import { XIcon, Loader2 } from "lucide-react" import { usePostHog } from "@lib/posthog" import { toast } from "sonner" interface FeedbackModalProps { isOpen: boolean onClose: () => void } const FEEDBACK_SURVEY_ID = "019bf2dd-f002-0000-d819-8a914cb23999" const FEEDBACK_QUESTION_ID = "0af81ccd-cb43-43a3-a61b-3a74c08a922a" const FEEDBACK_QUESTION = "What can we do to improve our product?" export function FeedbackModal({ isOpen, onClose }: FeedbackModalProps) { const [feedback, setFeedback] = useState("") const [isSubmitting, setIsSubmitting] = useState(false) const posthog = usePostHog() const handleSubmit = async () => { if (!feedback.trim() || isSubmitting) return setIsSubmitting(true) try { if (posthog.__loaded) { const responseKey = FEEDBACK_QUESTION_ID.replace(/-/g, "_") posthog.capture("survey sent", { $survey_id: FEEDBACK_SURVEY_ID, $survey_questions: [ { id: FEEDBACK_QUESTION_ID, question: FEEDBACK_QUESTION, }, ], [`$survey_response_${responseKey}`]: feedback.trim(), $survey_name: "Nova feedback", $survey_completed: true, }) } setFeedback("") toast.success("Thank you for your feedback!") onClose() } catch (error) { console.error("Failed to submit feedback:", error) toast.error("Failed to submit feedback. Please try again.") } finally { setIsSubmitting(false) } } const handleClose = () => { if (!isSubmitting) { setFeedback("") onClose() } } const handleKeyDown = (e: React.KeyboardEvent) => { if ( e.key === "Enter" && (e.metaKey || e.ctrlKey) && feedback.trim() && !isSubmitting ) { e.preventDefault() handleSubmit() } } return ( !open && handleClose()}>
Feedback

{FEEDBACK_QUESTION}

Close