import Link from "next/link"; import { Menu, Transition } from "@headlessui/react"; import { t } from "@lingui/core/macro"; import { Fragment, useRef, useState } from "react"; import { useForm } from "react-hook-form"; import chatIconDark from "~/assets/chat-dark.json"; import chatIconLight from "~/assets/chat-light.json"; import Button from "~/components/Button"; import Input from "~/components/Input"; import LottieIcon from "~/components/LottieIcon"; import { usePopup } from "~/providers/popup"; import { useTheme } from "~/providers/theme"; import { api } from "~/utils/api"; interface NewFeedbackFormInput { feedback: string; } const FeedbackButton: React.FC = () => { const outsideRef = useRef(null); const { activeTheme } = useTheme(); const { showPopup } = usePopup(); const [isHovered, setIsHovered] = useState(false); const [index, setIndex] = useState(0); const { handleSubmit, setValue, watch, reset } = useForm({ defaultValues: { feedback: "", }, }); const createFeedback = api.feedback.create.useMutation({ onSuccess: async () => { reset(); showPopup({ header: t`Feedback sent`, message: t`Thank you for your feedback!`, icon: "success", }); }, onError: async () => { showPopup({ header: t`Unable to send feedback`, message: t`Please try again later, or contact customer support.`, icon: "error", }); }, }); const handleMouseEnter = () => { setIsHovered(true); setIndex((index) => index + 1); }; const onSubmit = (values: NewFeedbackFormInput) => { createFeedback.mutate({ feedback: values.feedback, url: window.location.href, }); }; return ( <>
{t`Feedback`}
{ setValue("feedback", e.target.value); }} value={watch("feedback")} contentEditable className="max-h-[300px] min-h-[100px]" onKeyDown={async (e) => { e.stopPropagation(); if (e.key === "Enter" && e.shiftKey) { e.preventDefault(); await handleSubmit(onSubmit)(); } }} />

{t`Need help?`}{" "} {t`Contact us`} {t`, or see our`}{" "} {t`docs`} .

); }; export default FeedbackButton;