Added error boundary. Fixed #1976.

This commit is contained in:
Mike Cao 2023-04-25 14:41:54 -07:00
parent d73def80c7
commit 3f1ed750f0
7 changed files with 97 additions and 20 deletions

View file

@ -0,0 +1,33 @@
/* eslint-disable no-console */
import { ErrorBoundary as Boundary } from 'react-error-boundary';
import { Button } from 'react-basics';
import useMessages from 'hooks/useMessages';
import styles from './ErrorBoundry.module.css';
const logError = (error, info) => {
console.error(error, info.componentStack);
};
export function ErrorBoundary({ children }) {
const { formatMessage, messages } = useMessages();
const fallbackRender = ({ error, resetErrorBoundary }) => {
console.log({ error });
return (
<div className={styles.error} role="alert">
<h1>{formatMessage(messages.error)}</h1>
<h3>{error.message}</h3>
<pre>{error.stack}</pre>
<Button onClick={resetErrorBoundary}>OK</Button>
</div>
);
};
return (
<Boundary fallbackRender={fallbackRender} onError={logError}>
{children}
</Boundary>
);
}
export default ErrorBoundary;

View file

@ -0,0 +1,19 @@
.error {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
z-index: var(--z-index-overlay);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 600px;
gap: 20px;
}
.error button {
align-self: center;
}

View file

@ -23,7 +23,7 @@ export function DateFilter({ websiteId, value, className }) {
if (data) {
setDateRange({ value, ...getDateRangeValues(new Date(data.createdAt), Date.now()) });
}
} else {
} else if (value !== 'all') {
setDateRange(value);
}
}
@ -61,7 +61,7 @@ export function DateFilter({ websiteId, value, className }) {
value: '90day',
},
{ label: formatMessage(labels.thisYear), value: '1year' },
{
websiteId && {
label: formatMessage(labels.allTime),
value: 'all',
divider: true,
@ -71,7 +71,7 @@ export function DateFilter({ websiteId, value, className }) {
value: 'custom',
divider: true,
},
];
].filter(n => n);
const renderValue = value => {
return value === 'custom' ? (