Skip to content

Commit 0fb709a

Browse files
committed
fix(webapp): reset feedback topic to default when the dialog closes
1 parent 27a8602 commit 0fb709a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

apps/webapp/app/components/Feedback.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { parseWithZod } from "@conform-to/zod";
99
import { InformationCircleIcon, ArrowUpCircleIcon } from "@heroicons/react/20/solid";
1010
import { EnvelopeIcon, ShieldCheckIcon } from "@heroicons/react/24/solid";
1111
import { Form, useActionData, useLocation, useNavigation, useSearchParams } from "@remix-run/react";
12-
import { type ReactNode, useEffect, useState } from "react";
12+
import { type ReactNode, useEffect, useRef, useState } from "react";
1313
import { type FeedbackType, feedbackTypes, schema } from "~/routes/resources.feedback";
1414
import { Button } from "./primitives/Buttons";
1515
import { Dialog, DialogContent, DialogHeader, DialogTrigger } from "./primitives/Dialog";
@@ -85,6 +85,18 @@ export function Feedback({
8585
}
8686
}, [searchParams]);
8787

88+
// Reset the topic to the default once the dialog closes, so reopening always starts fresh. The
89+
// dialog is now persistently mounted (hosted outside the popover), so without this it would keep
90+
// the previously chosen topic selected and risk filing feedback under the wrong category. Keyed
91+
// on the close transition (not just `!open`) so the ?feedbackPanel= open path isn't clobbered.
92+
const wasOpen = useRef(open);
93+
useEffect(() => {
94+
if (wasOpen.current && !open) {
95+
setType(defaultValue);
96+
}
97+
wasOpen.current = open;
98+
}, [open, defaultValue]);
99+
88100
const handleOpenChange = (value: boolean) => {
89101
setOpen(value);
90102
onOpenChange?.(value);

0 commit comments

Comments
 (0)