Add error boundary to the project dashboard list
GitOrigin-RevId: 0f4cc3b4db62efe25ceeff202f305d08ddd73968
This commit is contained in:
@@ -25,6 +25,8 @@ import LoadMore from './load-more'
|
||||
import { useEffect } from 'react'
|
||||
import getMeta from '../../../utils/meta'
|
||||
import WelcomeMessageNew from './welcome-message-new'
|
||||
import withErrorBoundary from '../../../infrastructure/error-boundary'
|
||||
import { GenericErrorBoundaryFallback } from '../../../shared/components/generic-error-boundary-fallback'
|
||||
|
||||
function ProjectListRoot() {
|
||||
const { isReady } = useWaitForI18n()
|
||||
@@ -191,4 +193,4 @@ function DashApiError() {
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectListRoot
|
||||
export default withErrorBoundary(ProjectListRoot, GenericErrorBoundaryFallback)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type DefaultMessageProps = {
|
||||
className?: string
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
export function DefaultMessage({ className, style }: DefaultMessageProps) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<>
|
||||
<span style={style}>{`${t('generic_something_went_wrong')}. `}</span>
|
||||
<span className={className}>{`${t('please_refresh')}`}</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { FC, ReactNode } from 'react'
|
||||
import { Alert } from 'react-bootstrap'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { DefaultMessage } from './default-message'
|
||||
|
||||
export const ErrorBoundaryFallback: FC<{ modal?: ReactNode }> = ({
|
||||
children,
|
||||
@@ -8,14 +8,8 @@ export const ErrorBoundaryFallback: FC<{ modal?: ReactNode }> = ({
|
||||
}) => {
|
||||
return (
|
||||
<div className="error-boundary-alert">
|
||||
<Alert bsStyle="danger">{children || <DefaultContent />}</Alert>
|
||||
<Alert bsStyle="danger">{children || <DefaultMessage />}</Alert>
|
||||
{modal}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const DefaultContent = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return <p>{`${t('generic_something_went_wrong')}. ${t('please_refresh')}`}</p>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Icon from './icon'
|
||||
import { Button } from 'react-bootstrap'
|
||||
import { useLocation } from '../hooks/use-location'
|
||||
import { DefaultMessage } from './default-message'
|
||||
|
||||
export const GenericErrorBoundaryFallback: FC = ({ children }) => {
|
||||
const { t } = useTranslation()
|
||||
const { reload: handleClick } = useLocation()
|
||||
|
||||
return (
|
||||
<div className="error-boundary-container">
|
||||
<div className="icon-error-boundary-container">
|
||||
<Icon
|
||||
accessibilityLabel={`${t('generic_something_went_wrong')} ${t(
|
||||
'please_refresh'
|
||||
)}`}
|
||||
type="exclamation-triangle fa-2x"
|
||||
fw
|
||||
/>
|
||||
</div>
|
||||
{children || (
|
||||
<div className="error-message-container">
|
||||
<DefaultMessage className="small" style={{ fontWeight: 'bold' }} />
|
||||
</div>
|
||||
)}
|
||||
<Button bsStyle="primary" onClick={handleClick}>
|
||||
{t('refresh')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user