Skip to content

fix(app-admin): call onClose callback when dialog is closed #4694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

swapnilmmane
Copy link
Contributor

@swapnilmmane swapnilmmane commented Aug 15, 2025

Changes

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).

How Has This Been Tested?

I tested it manually using this code example.

import React, { useState } from "react";  
import { useDialogs } from "@webiny/app-admin";  
  
const DialogTest = () => {  
    const { showDialog } = useDialogs();  
    const [closeCount, setCloseCount] = useState(0);  
  
    const handleShowDialog = () => {  
        showDialog({  
            title: "Test Dialog",  
            content: "This is a test dialog to verify onClose callback works.",  
            acceptLabel: "Accept",  
            cancelLabel: "Cancel",  
            onAccept: (data) => {  
                console.log("Dialog accepted with data:", data);  
            },  
            onClose: () => {  
                console.log("Dialog closed!");  
                setCloseCount(prev => prev + 1);  
            }  
        });  
    };  
  
    return (  
        <div style={{ padding: "20px", border: "1px solid #ccc", margin: "10px" }}>  
            <h3>Dialog Test Component</h3>  
            <button onClick={handleShowDialog}>  
                Show Test Dialog  
            </button>  
            <p>Dialog closed {closeCount} times</p>  
        </div>  
    );  
};  
  
export default DialogTest;

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).
@swapnilmmane swapnilmmane requested a review from Pavel910 August 15, 2025 10:27
@Pavel910 Pavel910 added this to the 5.43.4 milestone Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants