import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { Badge, Button, MessageBar, MessageBarBody, Text, } from "@fluentui/react-components"; import { ArrowClockwiseRegular, ArrowSyncRegular, PauseRegular, PlayRegular, StopRegular, } from "@fluentui/react-icons"; import { useCommonSectionStyles } from "../../components/commonStyles"; import { useJailDetailPageStyles } from "./jailDetailPageStyles"; import type { Jail } from "../../types/jail"; interface JailInfoProps { jail: Jail; onRefresh: () => void; onStart: () => Promise; onStop: () => Promise; onSetIdle: (on: boolean) => Promise; onReload: () => Promise; } export function JailInfoSection({ jail, onRefresh, onStart, onStop, onSetIdle, onReload }: JailInfoProps): React.JSX.Element { const styles = useJailDetailPageStyles(); const sectionStyles = useCommonSectionStyles(); const navigate = useNavigate(); const [ctrlError, setCtrlError] = useState(null); const handle = (fn: () => Promise, postNavigate = false) => (): void => { setCtrlError(null); fn() .then(() => { if (postNavigate) { navigate("/jails"); } else { onRefresh(); } }) .catch((err: unknown) => { const msg = err instanceof Error ? err.message : String(err); setCtrlError(msg); }); }; return (
{jail.name} {jail.running ? ( jail.idle ? ( idle ) : ( running ) ) : ( stopped )}
{ctrlError && ( {ctrlError} )}
{jail.running ? ( ) : ( )}
{jail.status && (
Currently banned: {String(jail.status.currently_banned)} Total banned: {String(jail.status.total_banned)} Currently failed: {String(jail.status.currently_failed)} Total failed: {String(jail.status.total_failed)}
)}
Backend: {jail.backend} Find time: {String(jail.find_time)} Ban time: {String(jail.ban_time)} Max retry: {String(jail.max_retry)} {jail.date_pattern && ( <> Date pattern: {jail.date_pattern} )} {jail.log_encoding && ( <> Log encoding: {jail.log_encoding} )}
); }