Enterprise-CMCS / eAPD

CMS (Centers for Medicare and Medicaid Services) eAPD - Modernizing the APD experience
https://eapd.cms.gov
Other
58 stars 25 forks source link

[Feature] Track navigating away from the the APD outside of the app #4656

Open thetif opened 1 year ago

thetif commented 1 year ago

Description and related issues

Implement way to catch the following cases:

It looks like there is a window listener for this. But we need it across the application, maybe this could go in the Root component. Before the tab unloads the application call a closing APD action. This action should only be called if they are in a locked APD when they leave the application.

Example

useEffect(() => {
    window.addEventListener('beforeunload', alertUser)
    window.addEventListener('unload', handleTabClosing)
    return () => {
        window.removeEventListener('beforeunload', alertUser)
        window.removeEventListener('unload', handleTabClosing)
    }
})

const handleTabClosing = () => {
    removePlayerFromGame()
}

const alertUser = (event:any) => {
    event.preventDefault()
    event.returnValue = ''
}

Acceptance criteria

Testing criteria

Given When Then Covered
user is inside a locked APD a user closes the tab the browser prevents the action long enough to call the close APD action
user is inside a locked APD a user closes the browser the browser prevents the action long enough to call the close APD action
user is inside a locked APD a user clicks a link that goes navigates to another site in the same tab the browser prevents the action long enough to call the close APD action
user is inside a locked APD a user changes the url to another site in the same tab the browser prevents the action long enough to call the close APD action
user is outside of a locked APD user closes the tab tab closes normally
user is outside of a locked APD user closes the browser browser closes normally
user is outside of a locked APD a user clicks a link that goes navigates to another site in the same tab the browser navigates normall
user is outside of a locked APD a user changes the url to another site in the same tab the browser navigates normally
stephanieboydcms commented 1 year ago

Good to go!

jeromeleecms commented 1 year ago

Just a few clarification in the acceptance criteria