"use client"; import { useState, type FormEvent } from "react"; import { trackEvent } from "@/lib/analytics-events"; import type { Dictionary } from "@/lib/i18n"; type FeedbackType = "bug" | "suggestion" | "general"; type FeedbackModalProps = { dateKey: string; onClose: () => void; t: Dictionary; }; export default function FeedbackModal({ dateKey, onClose, t }: FeedbackModalProps) { const [type, setType] = useState("general"); const [message, setMessage] = useState(""); const [isSending, setIsSending] = useState(false); const [status, setStatus] = useState<"idle" | "success" | "error">("idle"); async function submit(event: FormEvent) { event.preventDefault(); if (!message.trim() || isSending) return; setIsSending(true); setStatus("idle"); try { const response = await fetch("/api/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ dateKey, message: message.trim(), type, page: window.location.pathname, locale: window.navigator.language, source: "hidden11", }), }); if (!response.ok) { throw new Error("feedback request failed"); } setStatus("success"); setMessage(""); trackEvent("feedback_sent", { type }); } catch { setStatus("error"); } finally { setIsSending(false); } } return (

{t.feedback}

Tell us what to improve.