Skip to content

Commit

Permalink
refactor(console): add retry button on error (#6158)
Browse files Browse the repository at this point in the history
  • Loading branch information
gao-sun authored Jul 2, 2024
1 parent 15a3d1d commit b52ef32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/console/src/components/AppError/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
display: inline-flex;
align-items: center;
margin-left: _.unit(2);
margin-top: _.unit(2);
color: var(--color-primary);
cursor: pointer;
}
Expand Down
16 changes: 14 additions & 2 deletions packages/console/src/components/AppError/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useLogto } from '@logto/react';
import { Theme } from '@logto/schemas';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -6,6 +7,7 @@ import KeyboardArrowDown from '@/assets/icons/keyboard-arrow-down.svg';
import KeyboardArrowUp from '@/assets/icons/keyboard-arrow-up.svg';
import ErrorDark from '@/assets/images/error-dark.svg';
import Error from '@/assets/images/error.svg';
import Button from '@/ds-components/Button';
import useTheme from '@/hooks/use-theme';
import { onKeyDownHandler } from '@/utils/a11y';

Expand All @@ -23,18 +25,27 @@ function AppError({ title, errorCode, errorMessage, callStack, children }: Props
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const [isDetailsOpen, setIsDetailsOpen] = useState(false);
const theme = useTheme();
const { clearAllTokens } = useLogto();

return (
<div className={styles.container}>
{theme === Theme.Light ? <Error /> : <ErrorDark />}
<label>{title ?? t('errors.something_went_wrong')}</label>
<Button
title="general.retry"
size="large"
onClick={async () => {
await clearAllTokens();
window.location.reload();
}}
/>
<div className={styles.summary}>
<span>
{errorCode}
{errorCode && errorMessage && ': '}
{errorMessage}
{callStack && (
<span
<div
role="button"
tabIndex={0}
className={styles.expander}
Expand All @@ -47,10 +58,11 @@ function AppError({ title, errorCode, errorMessage, callStack, children }: Props
>
{t('errors.more_details')}
{isDetailsOpen ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
</span>
</div>
)}
</span>
</div>

{callStack && isDetailsOpen && <div className={styles.details}>{callStack}</div>}
{children}
</div>
Expand Down

0 comments on commit b52ef32

Please sign in to comment.