Skip to content

Commit

Permalink
Streamline the flow of rendering Modal for DRYness
Browse files Browse the repository at this point in the history
  • Loading branch information
renintw committed Jun 9, 2023
1 parent ac7d3b5 commit 1d193fb
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions settings/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,22 @@ function Main( { userId } ) {
<CardBody className={ 'wporg-2fa__' + screen }>{ currentScreen }</CardBody>
</Card>
);
} else if (
}

const isRevalidationExpired =
twoFactorRequiredScreens.includes( screen ) &&
hasPrimaryProvider &&
record[ '2fa_revalidation' ]?.expires_at <= new Date().getTime() / 1000
) {
screenContent = (
<>
{ currentScreen }
<RevalidateModal />
</>
);
}
record[ '2fa_revalidation' ]?.expires_at <= new Date().getTime() / 1000;

const shouldRevalidate = 'revalidation_required' === error.code || isRevalidationExpired;

return (
<GlobalContext.Provider
value={ { navigateToScreen, user, setGlobalNotice, setError, error } }
>
<GlobalNotice notice={ globalNotice } setNotice={ setGlobalNotice } />
{ screenContent }
{ 'revalidation_required' === error.code && <RevalidateModal /> }
{ shouldRevalidate && <RevalidateModal /> }
</GlobalContext.Provider>
);
}

0 comments on commit 1d193fb

Please sign in to comment.