Skip to content

Commit

Permalink
fix: reset form on navigation (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Feb 3, 2024
1 parent e61d523 commit 3580d5f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/ui/app/src/custom-docs-page/Feedback.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from "classnames";
import { FC, useRef, useState } from "react";
import { useRouter } from "next/router";
import { FC, useEffect, useRef, useState } from "react";
import { capturePosthogEvent } from "../analytics/posthog";
import { FernButton } from "../components/FernButton";
import { FernCollapse } from "../components/FernCollapse";
Expand All @@ -9,10 +10,24 @@ interface FeedbackProps {
}

export const Feedback: FC<FeedbackProps> = ({ className }) => {
const router = useRouter();
const [sent, setSent] = useState(false);
const [feedback, setFeedback] = useState<"yes" | "no" | null>(null);
const [showFeedbackInput, setShowFeedbackInput] = useState(false);
const textareaRef = useRef<HTMLTextAreaElement>(null);

useEffect(() => {
const resetForm = () => {
setSent(false);
setFeedback(null);
setShowFeedbackInput(false);
};
router.events.on("routeChangeComplete", resetForm);
return () => {
router.events.off("routeChangeComplete", resetForm);
};
}, [router.events]);

const handleYes = () => {
setFeedback("yes");
setShowFeedbackInput(true);
Expand Down

0 comments on commit 3580d5f

Please sign in to comment.