Skip to content

Commit 04b8969

Browse files
committed
fix(app-admin): call onClose callback when dialog is closed
The useDialogs hook was not triggering the onClose callback when dialogs were dismissed. The closeDialog function in DialogsContext only removed the dialog from state without executing the user-provided onClose callback. This fix retrieves the dialog from state before removal and calls the onClose callback if it exists, ensuring proper cleanup and event handling when dialogs are closed through any method (cancel button, accept button, or programmatic closure).
1 parent c6d623e commit 04b8969

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/app-admin/src/components/Dialogs/DialogsContext.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ export const DialogsProvider = ({ children }: DialogsProviderProps) => {
7575
};
7676

7777
const closeDialog = (id: string) => {
78+
const dialog = dialogs.get(id);
79+
80+
// Call the onClose callback if it exists
81+
if (dialog?.onClose && typeof dialog.onClose === "function") {
82+
try {
83+
dialog.onClose();
84+
} catch (error) {
85+
// Log error but don't prevent dialog cleanup
86+
console.error("Error in dialog onClose callback:", error);
87+
}
88+
}
89+
7890
setDialogs(dialogs => {
7991
const newDialogs = new Map(dialogs);
8092
newDialogs.delete(id);

0 commit comments

Comments
 (0)