Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(console): add retry button on error #6158

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading