"use client" import React, { useRef, useState } from "react" import { CSSTransition, SwitchTransition } from "react-transition-group" import Solutions from "./Solutions/index" import Button from "../Button" import { ExtraData, useAnalytics } from "@/providers/analytics" import { usePathname } from "next/navigation" import Link from "next/link" import { useArea } from "../../providers/area" import clsx from "clsx" import TextArea from "../TextArea" import Label from "../Label" type FeedbackProps = { event: string question?: string positiveBtn?: string negativeBtn?: string positiveQuestion?: string negativeQuestion?: string submitBtn?: string submitMessage?: string showPossibleSolutions?: boolean className?: string extraData?: ExtraData sectionTitle?: string vertical?: boolean } & React.HTMLAttributes const Feedback: React.FC = ({ event, question = "Was this section helpful?", positiveBtn = "Yes", negativeBtn = "No", positiveQuestion = "What was most helpful?", negativeQuestion = "What can we improve?", submitBtn = "Submit", submitMessage = "Thank you for helping improve our documentation!", showPossibleSolutions = true, className = "", extraData = {}, sectionTitle = "", vertical = false, }) => { const [showForm, setShowForm] = useState(false) const [submittedFeedback, setSubmittedFeedback] = useState(false) const [loading, setLoading] = useState(false) const inlineFeedbackRef = useRef(null) const inlineQuestionRef = useRef(null) const inlineMessageRef = useRef(null) const [positiveFeedback, setPositiveFeedback] = useState(false) const [message, setMessage] = useState("") const nodeRef: React.RefObject = submittedFeedback ? inlineMessageRef : showForm ? inlineQuestionRef : inlineFeedbackRef const pathname = usePathname() const { loaded, track } = useAnalytics() const { area } = useArea() function handleFeedback(e: React.MouseEvent) { if (!loaded) { return } const feedback = (e.target as Element).classList.contains("positive") setPositiveFeedback(feedback) setShowForm(true) submitFeedback(e, feedback) } function submitFeedback( e: React.MouseEvent, feedback = false ) { if (showForm) { setLoading(true) } track( event, { url: pathname, label: document.title, feedback: (feedback !== null && feedback) || (feedback === null && positiveFeedback) ? "yes" : "no", message: message?.length ? message : null, os: window.navigator.userAgent, ...extraData, }, function () { if (showForm) { setLoading(false) resetForm() } } ) } function resetForm() { setShowForm(false) setSubmittedFeedback(true) } return (
{ nodeRef.current?.addEventListener("transitionend", done, false) }} classNames={{ enter: "animate-fadeIn animate-fill-forwards animate-fast", exit: "animate-fadeOut animate-fill-forwards animate-fast", }} > <> {!showForm && !submittedFeedback && (
Report Issue
)} {showForm && !submittedFeedback && (