Skip to content

Commit

Permalink
Refresh user when navigating to Account Status
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Sep 14, 2023
1 parent 1fa61c6 commit a1579e2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions settings/src/components/screen-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { useCallback, useContext } from '@wordpress/element';
* Internal dependencies
*/
import { GlobalContext } from '../script';
import { refreshRecord } from '../utilities/common';

export default function ScreenLink( { screen, anchorText, buttonStyle = false, ariaLabel } ) {
const { navigateToScreen } = useContext( GlobalContext );
const {
user: { userRecord },
navigateToScreen,
} = useContext( GlobalContext );
const classes = [];
const screenUrl = new URL( document.location.href );

Expand All @@ -24,11 +28,19 @@ export default function ScreenLink( { screen, anchorText, buttonStyle = false, a
}

const onClick = useCallback(
( event ) => {
async ( event ) => {
event.preventDefault();

// Sometimes the record will have been updated, and those changes need to be reflected on Account
// Status, but it's not possible for the current screen to refresh the record. For example, Backup
// Codes can't refresh it if the user generates codes but then clicks "Back" before clicking "All Finished".
if ( 'account-status' === screen ) {
await refreshRecord( userRecord );
}

navigateToScreen( screen );
},
[ navigateToScreen ]
[ navigateToScreen, userRecord, screen ]
);

return (
Expand Down

0 comments on commit a1579e2

Please sign in to comment.