import {
ArrowPathIcon,
ArrowTopRightOnSquareIcon,
} from '@heroicons/react/20/solid';
import { useState } from 'react';
import HowItWorks from './HowItWorks';
import { WebUiLogo } from '../WebUiLogo';
interface StatusBannerArgs {
mode: string;
level: number;
/**
* Ask for a mode. May return the write's promise; when it does, the
* optimistic value is dropped once it settles, so a failed write does not
* leave the banner spinning (Redmine #25049).
*/
onMode: ( value: string ) => Promise< unknown > | void;
}
const levelNames = [ 'Light', 'Standard', 'Maximum' ];
// Placeholder artwork — simple line drawings standing in until the supplied
// SVGs arrive. Replace the paths, keep the viewBox and currentColor stroke.
function WatchingArt( { dimmed = false }: { dimmed?: boolean } ) {
return (
);
}
// Placeholder artwork — see the note above.
function ProtectingArt() {
return (
);
}
export default function StatusBanner( {
mode,
level,
onMode,
}: StatusBannerArgs ) {
// Null means "use the server value". Once set, the frontend shows the
// clicked value while the write is in flight. Same idiom as the level list.
const [ visualMode, setVisualMode ] = useState< string | null >( null );
function requestMode( value: string ) {
if ( mode === visualMode || visualMode === null ) {
setVisualMode( value );
const write = onMode( value );
if ( write && 'function' === typeof write.finally ) {
// Settled either way: on success `mode` has already caught
// up, so nothing moves; on failure the server value shows.
write.finally( () => setVisualMode( null ) );
}
}
}
const current = null === visualMode ? mode : visualMode;
const pending = null !== visualMode && visualMode !== mode;
const levelName = levelNames[ level ] ?? levelNames[ 0 ];
// The banner is a staged journey (Off → Monitor → Protect), not a
// three-way switch: one step forward, one step back, per state.
const states: Record<
string,
{ heading: string; body: string; hint: string }
> = {
off: {
heading: 'Sentry is off',
body: 'Sentry is not watching sign-ins or blocking anything.',
hint: 'Turn watching on to start recording where sign-ins come from.',
},
// Same story as HowItWorks step 1 and 3 (Redmine #25592): Watch
// records sign-in attempts and blocks only the addresses blocked by
// hand; Protect blocks automatically after the level's failure count.
monitor: {
heading: 'Sentry is watching your sign-ins',
body: 'Sentry records sign-in attempts and blocks only the addresses you have blocked yourself. It is learning where your users sign in from, so you can allow the ones you expect before turning protection on.',
hint: 'Review Successful logins below first — protection uses your allow list.',
},
protect: {
heading: 'Sentry is protecting your site',
body: `An address that breaks your rules is blocked automatically once it reaches the ${ levelName } level's failure count. Sentry keeps recording activity below.`,
hint: 'Watching mode stops automatic blocking but keeps recording, and keeps the addresses you have blocked yourself.',
},
};
const state = states[ current ] ?? states.monitor;
return (
{ 'protect' === current ? (
) : (
) }
{ state.heading }
{ pending && (
) }
{ state.body }
{ 'off' === current && (
) }
{ 'monitor' === current && (
<>
>
) }
{ 'protect' === current && (
) }
{ state.hint }