diff --git a/components/OverallStatus.tsx b/components/OverallStatus.tsx index 72252d6..c81aee9 100644 --- a/components/OverallStatus.tsx +++ b/components/OverallStatus.tsx @@ -1,30 +1,33 @@ -import { Center, Title } from '@mantine/core' -import { IconCircleCheck, IconAlertCircle } from '@tabler/icons-react' -import { useEffect, useState } from 'react'; +import { Maintenances } from '@/types/config' +import { Alert, Card, Center, Container, List, ListItem, Text, Title } from '@mantine/core' +import { IconCircleCheck, IconAlertCircle, IconInfoCircle } from '@tabler/icons-react' +import { useEffect, useState } from 'react' function useWindowVisibility() { - const [isVisible, setIsVisible] = useState(true); + const [isVisible, setIsVisible] = useState(true) useEffect(() => { const handleVisibilityChange = () => { - console.log('visibility change', document.visibilityState); - setIsVisible(document.visibilityState === 'visible'); - }; + console.log('visibility change', document.visibilityState) + setIsVisible(document.visibilityState === 'visible') + } - document.addEventListener('visibilitychange', handleVisibilityChange); + document.addEventListener('visibilitychange', handleVisibilityChange) return () => { - document.removeEventListener('visibilitychange', handleVisibilityChange); - }; - }, []); + document.removeEventListener('visibilitychange', handleVisibilityChange) + } + }, []) - return isVisible; + return isVisible } export default function OverallStatus({ state, + maintenances, }: { state: { overallUp: number; overallDown: number; lastUpdate: number } + maintenances?: Maintenances[] }) { let statusString = '' let icon = @@ -36,12 +39,14 @@ export default function OverallStatus({ statusString = 'All systems operational' icon = } else { - statusString = `Some systems not operational (${state.overallDown} out of ${state.overallUp + state.overallDown})` + statusString = `Some systems not operational (${state.overallDown} out of ${ + state.overallUp + state.overallDown + })` } const [openTime] = useState(Math.round(Date.now() / 1000)) const [currentTime, setCurrentTime] = useState(Math.round(Date.now() / 1000)) - const isWindowVisible = useWindowVisibility(); + const isWindowVisible = useWindowVisibility() useEffect(() => { const interval = setInterval(() => { @@ -58,16 +63,61 @@ export default function OverallStatus({ return () => clearInterval(interval) }) + // @TODO make dynamic + const showMaintenance = maintenances + return ( <> -
{icon}
- - {statusString} - - - Last updated on:{' '} - {`${new Date(state.lastUpdate * 1000).toLocaleString()} (${currentTime - state.lastUpdate} sec ago)`} - + +
{icon}
+ + {statusString} + + + Last updated on:{' '} + {`${new Date(state.lastUpdate * 1000).toLocaleString()} (${ + currentTime - state.lastUpdate + } sec ago)`} + + {showMaintenance && + maintenances.map((maintenance, idx) => ( + } + title={maintenance.title} + color={maintenance.color || 'primary'} + mt="md" + withCloseButton={false} + > + + {maintenance.start && ( + <> + From: {maintenance.start.toLocaleString()} +
+ + )} + {maintenance.end && ( + <> + To: {maintenance.end.toLocaleString()} + + )} +
+ {maintenance.body && {maintenance.body}} + {maintenance.monitors && maintenance.monitors.length > 0 && ( + <> + + Affected components: + + + {maintenance.monitors.map((comp, compIdx) => ( + {comp} + ))} + + + )} +
+ ))} +
) }