import { Component, type ReactNode } from 'react' import { Button } from '@keystar/ui/button' import { Dialog } from '@keystar/ui/dialog' import { Icon } from '@keystar/ui/icon' import { alertTriangleIcon } from '@keystar/ui/icon/icons/alertTriangleIcon' import { Box, Grid, VStack } from '@keystar/ui/layout' import { Notice } from '@keystar/ui/notice' import { Content, SlotProvider } from '@keystar/ui/slots' import { css, tokenSchema } from '@keystar/ui/style' import { Heading, Text } from '@keystar/ui/typography' type ErrorBoundaryProps = { children: ReactNode } type ErrorBoundaryState = { error?: any hasError: boolean isReloading: boolean } export class ErrorBoundary extends Component { state: ErrorBoundaryState = { hasError: false, isReloading: false } static getDerivedStateFromError(error: any) { return { error, hasError: true } } reloadPage = () => { this.setState({ isReloading: true }) window.location.reload() } render() { if (this.state.hasError) { return ( Unknown error Something went wrong, please try reloading the page. If the problem persists contact your system administrator. ) } return this.props.children } } type ErrorContainerProps = { children: ReactNode } const errorContainerSlots = { heading: { align: 'center', margin: 0 }, text: { align: 'center' }, } as const export function ErrorContainer({ children }: ErrorContainerProps) { return ( {children} ) } export function ErrorDetailsDialog({ title, error }: { title: string; error: Error }) { const { message, stack } = error return ( Error details {message} {message} {stack}
{title}
) }