Skip to content

Commit 346ee3a

Browse files
Fix: support dialog closing when opened (#4490)
* Working feedback dialog * stop dialog from auto closing when opened --------- Co-authored-by: Meg Stepp <[email protected]>
1 parent 3ef549c commit 346ee3a

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

apps/dashboard/components/dashboard/feedback-component.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
toast,
1616
} from "@unkey/ui";
1717
import { parseAsBoolean, useQueryState } from "nuqs";
18+
import { useEffect, useRef, useState } from "react";
1819
import { Controller, useForm } from "react-hook-form";
1920
import { z } from "zod";
2021

@@ -35,6 +36,21 @@ type FormValues = z.infer<typeof feedbackSchema>;
3536

3637
export const Feedback: React.FC = () => {
3738
const [open, setOpen] = useFeedback();
39+
const [internalOpen, setInternalOpen] = useState(false);
40+
const justOpenedRef = useRef(false);
41+
42+
// Sync internal state with URL query state
43+
useEffect(() => {
44+
if (open) {
45+
setInternalOpen(true);
46+
justOpenedRef.current = true;
47+
const timer = setTimeout(() => {
48+
justOpenedRef.current = false;
49+
}, 500);
50+
return () => clearTimeout(timer);
51+
}
52+
setInternalOpen(false);
53+
}, [open]);
3854

3955
const {
4056
handleSubmit,
@@ -68,10 +84,23 @@ export const Feedback: React.FC = () => {
6884
}
6985
};
7086

87+
const handleClose = () => {
88+
if (justOpenedRef.current) {
89+
return; // Prevent closing if just opened
90+
}
91+
setOpen(false);
92+
};
93+
7194
return (
7295
<DialogContainer
73-
isOpen={Boolean(open)}
74-
onOpenChange={setOpen}
96+
isOpen={internalOpen}
97+
onOpenChange={(newOpen) => {
98+
if (!newOpen) {
99+
handleClose();
100+
}
101+
}}
102+
showCloseWarning={false}
103+
onAttemptClose={handleClose}
75104
title="Report an issue"
76105
subTitle="What went wrong or how can we improve?"
77106
footer={

0 commit comments

Comments
 (0)