-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add value to Protect card - Cleanup, refactor, & final enhancements. (#…
- Loading branch information
1 parent
36b2d52
commit 4b63023
Showing
10 changed files
with
431 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
...s/my-jetpack/_inc/components/product-cards-section/protect-card/logins-blocked-status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import useProduct from '../../../data/products/use-product'; | ||
import { getMyJetpackWindowInitialState } from '../../../data/utils/get-my-jetpack-window-state'; | ||
import useMyJetpackConnection from '../../../hooks/use-my-jetpack-connection'; | ||
import { isJetpackPluginActive } from '../../../utils/is-jetpack-plugin-active'; | ||
import ShieldOff from './assets/shield-off.svg'; | ||
import ShieldPartial from './assets/shield-partial.svg'; | ||
import { InfoTooltip } from './info-tooltip'; | ||
import { useProtectTooltipCopy } from './use-protect-tooltip-copy'; | ||
import type { ReactElement, PropsWithChildren } from 'react'; | ||
|
||
export const LoginsBlockedStatus = () => { | ||
const slug = 'protect'; | ||
const { detail } = useProduct( slug ); | ||
const { isPluginActive: isProtectPluginActive = false } = detail || {}; | ||
const { isSiteConnected } = useMyJetpackConnection(); | ||
const { | ||
protect: { wafConfig: wafData }, | ||
} = getMyJetpackWindowInitialState(); | ||
const { blocked_logins: blockedLoginsCount, brute_force_protection: hasBruteForceProtection } = | ||
wafData || {}; | ||
|
||
// The Brute Force Protection module is available when either the Jetpack plugin Or the Protect plugin is active. | ||
const isPluginActive = isProtectPluginActive || isJetpackPluginActive(); | ||
|
||
if ( isPluginActive && isSiteConnected ) { | ||
if ( hasBruteForceProtection ) { | ||
return <BlockedStatus status="active" />; | ||
} | ||
|
||
return <BlockedStatus status="inactive" />; | ||
} | ||
if ( isSiteConnected && blockedLoginsCount > 0 ) { | ||
// logins have been blocked previoulsy, but either the Jetpack or Protect plugin is not active | ||
return <BlockedStatus status="inactive" />; | ||
} | ||
return <BlockedStatus status="off" />; | ||
}; | ||
|
||
/** | ||
* BlockedStatus component | ||
* | ||
* @param {PropsWithChildren} props - The component props | ||
* @param {'active' | 'inactive' | 'off'} props.status - The status of Brute Force Protection | ||
* | ||
* @returns {ReactElement} rendered component | ||
*/ | ||
function BlockedStatus( { status }: { status: 'active' | 'inactive' | 'off' } ) { | ||
const { | ||
protect: { wafConfig: wafData }, | ||
} = getMyJetpackWindowInitialState(); | ||
const { blocked_logins: blockedLoginsCount } = wafData || {}; | ||
|
||
const tooltipContent = useProtectTooltipCopy(); | ||
const { blockedLoginsTooltip } = tooltipContent; | ||
|
||
if ( status === 'active' ) { | ||
return blockedLoginsCount > 0 ? ( | ||
<div className="logins_blocked__count">{ blockedLoginsCount }</div> | ||
) : ( | ||
<> | ||
<div> | ||
<img | ||
className="value-section__status-icon" | ||
src={ ShieldPartial } | ||
alt={ __( | ||
'Shield icon - Brute Force Protection Status: Active', | ||
'jetpack-my-jetpack' | ||
) } | ||
/> | ||
</div> | ||
<InfoTooltip | ||
tracksEventName={ 'protect_card_tooltip_open' } | ||
tracksEventProps={ { | ||
location: 'blocked-logins', | ||
status: status, | ||
message: 'no data yet', | ||
} } | ||
> | ||
<> | ||
<h3 className="value-section__tooltip-heading">{ blockedLoginsTooltip.title }</h3> | ||
<p className="value-section__tooltip-content">{ blockedLoginsTooltip.text }</p> | ||
</> | ||
</InfoTooltip> | ||
</> | ||
); | ||
} | ||
if ( status === 'inactive' ) { | ||
return ( | ||
<> | ||
{ blockedLoginsCount > 0 ? ( | ||
<> | ||
<div> | ||
<img | ||
className="value-section__status-icon" | ||
src={ ShieldOff } | ||
alt={ __( | ||
'Shield icon - Brute Force Protection Status: Inactive', | ||
'jetpack-my-jetpack' | ||
) } | ||
/> | ||
</div> | ||
<div className="logins_blocked__count">{ blockedLoginsCount }</div> | ||
</> | ||
) : ( | ||
<div> | ||
<img | ||
className="value-section__status-icon" | ||
src={ ShieldOff } | ||
alt={ __( | ||
'Shield icon - Brute Force Protection Status: Inactive', | ||
'jetpack-my-jetpack' | ||
) } | ||
/> | ||
</div> | ||
) } | ||
<InfoTooltip | ||
tracksEventName={ 'protect_card_tooltip_open' } | ||
tracksEventProps={ { | ||
location: 'blocked-logins', | ||
status: status, | ||
} } | ||
> | ||
<> | ||
<h3 className="value-section__tooltip-heading">{ blockedLoginsTooltip.title }</h3> | ||
<p className="value-section__tooltip-content">{ blockedLoginsTooltip.text }</p> | ||
</> | ||
</InfoTooltip> | ||
</> | ||
); | ||
} | ||
return ( | ||
<> | ||
<div> | ||
<img | ||
className="value-section__status-icon" | ||
src={ ShieldOff } | ||
alt={ __( 'Shield icon - Brute Force Protection Status: Off', 'jetpack-my-jetpack' ) } | ||
/> | ||
</div> | ||
<div className="value-section__status-text">{ __( 'Off', 'jetpack-my-jetpack' ) }</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.