0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

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

This commit is contained in:
Gao Sun 2024-07-02 09:42:51 +08:00 committed by GitHub
parent 15a3d1d184
commit b52ef323cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -37,6 +37,7 @@
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
margin-left: _.unit(2); margin-left: _.unit(2);
margin-top: _.unit(2);
color: var(--color-primary); color: var(--color-primary);
cursor: pointer; cursor: pointer;
} }

View file

@ -1,3 +1,4 @@
import { useLogto } from '@logto/react';
import { Theme } from '@logto/schemas'; import { Theme } from '@logto/schemas';
import { useState } from 'react'; import { useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -6,6 +7,7 @@ import KeyboardArrowDown from '@/assets/icons/keyboard-arrow-down.svg';
import KeyboardArrowUp from '@/assets/icons/keyboard-arrow-up.svg'; import KeyboardArrowUp from '@/assets/icons/keyboard-arrow-up.svg';
import ErrorDark from '@/assets/images/error-dark.svg'; import ErrorDark from '@/assets/images/error-dark.svg';
import Error from '@/assets/images/error.svg'; import Error from '@/assets/images/error.svg';
import Button from '@/ds-components/Button';
import useTheme from '@/hooks/use-theme'; import useTheme from '@/hooks/use-theme';
import { onKeyDownHandler } from '@/utils/a11y'; import { onKeyDownHandler } from '@/utils/a11y';
@ -23,18 +25,27 @@ function AppError({ title, errorCode, errorMessage, callStack, children }: Props
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const [isDetailsOpen, setIsDetailsOpen] = useState(false); const [isDetailsOpen, setIsDetailsOpen] = useState(false);
const theme = useTheme(); const theme = useTheme();
const { clearAllTokens } = useLogto();
return ( return (
<div className={styles.container}> <div className={styles.container}>
{theme === Theme.Light ? <Error /> : <ErrorDark />} {theme === Theme.Light ? <Error /> : <ErrorDark />}
<label>{title ?? t('errors.something_went_wrong')}</label> <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}> <div className={styles.summary}>
<span> <span>
{errorCode} {errorCode}
{errorCode && errorMessage && ': '} {errorCode && errorMessage && ': '}
{errorMessage} {errorMessage}
{callStack && ( {callStack && (
<span <div
role="button" role="button"
tabIndex={0} tabIndex={0}
className={styles.expander} className={styles.expander}
@ -47,10 +58,11 @@ function AppError({ title, errorCode, errorMessage, callStack, children }: Props
> >
{t('errors.more_details')} {t('errors.more_details')}
{isDetailsOpen ? <KeyboardArrowUp /> : <KeyboardArrowDown />} {isDetailsOpen ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
</span> </div>
)} )}
</span> </span>
</div> </div>
{callStack && isDetailsOpen && <div className={styles.details}>{callStack}</div>} {callStack && isDetailsOpen && <div className={styles.details}>{callStack}</div>}
{children} {children}
</div> </div>