From 04b89693a74eb14d5f2559708d494dbf6ad34f4e Mon Sep 17 00:00:00 2001 From: Swapnil M Mane Date: Fri, 15 Aug 2025 15:53:00 +0530 Subject: [PATCH] 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). --- .../src/components/Dialogs/DialogsContext.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/app-admin/src/components/Dialogs/DialogsContext.tsx b/packages/app-admin/src/components/Dialogs/DialogsContext.tsx index b73797e98b..8d7bb833e3 100644 --- a/packages/app-admin/src/components/Dialogs/DialogsContext.tsx +++ b/packages/app-admin/src/components/Dialogs/DialogsContext.tsx @@ -75,6 +75,18 @@ export const DialogsProvider = ({ children }: DialogsProviderProps) => { }; const closeDialog = (id: string) => { + const dialog = dialogs.get(id); + + // Call the onClose callback if it exists + if (dialog?.onClose && typeof dialog.onClose === "function") { + try { + dialog.onClose(); + } catch (error) { + // Log error but don't prevent dialog cleanup + console.error("Error in dialog onClose callback:", error); + } + } + setDialogs(dialogs => { const newDialogs = new Map(dialogs); newDialogs.delete(id);