Spaces:
Running
Running
File size: 1,601 Bytes
3299552 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import React from 'react';
import { Alert, AlertTitle, Button, Box, Collapse } from '@mui/material';
import { Close } from '@mui/icons-material';
import styled from '@emotion/styled';
const ErrorContainer = styled(Box)(({ theme }) => ({
marginBottom: theme.spacing(2),
width: '100%',
}));
const ErrorMessage = ({
error,
onRetry,
onClose,
severity = 'error',
title = 'Error',
retryText = 'Try Again',
closable = true
}) => {
const [open, setOpen] = React.useState(true);
const handleClose = () => {
setOpen(false);
if (onClose) onClose();
};
if (!error || !open) return null;
return (
<ErrorContainer>
<Collapse in={open}>
<Alert
severity={severity}
action={
<Box display="flex" gap={1}>
{onRetry && (
<Button
color="inherit"
size="small"
onClick={onRetry}
>
{retryText}
</Button>
)}
{closable && (
<Button
color="inherit"
size="small"
onClick={handleClose}
endIcon={<Close fontSize="small" />}
>
Close
</Button>
)}
</Box>
}
>
<AlertTitle>{title}</AlertTitle>
{typeof error === 'string' ? error : error.message || 'An unknown error occurred'}
</Alert>
</Collapse>
</ErrorContainer>
);
};
export default ErrorMessage; |