0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-04-07 23:01:25 -05:00

refactor(experience): improve go back logic handling in one-time token pages (#7228)

This commit is contained in:
Charles Zhao 2025-04-03 10:38:10 +08:00 committed by GitHub
parent a2a14b083c
commit 3c7f9a14f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 14 deletions

View file

@ -17,16 +17,22 @@ type Props = {
readonly title?: TFuncKey;
readonly message?: TFuncKey;
readonly rawMessage?: string;
readonly isNavbarHidden?: boolean;
};
const ErrorPage = ({ title = 'description.not_found', message, rawMessage }: Props) => {
const ErrorPage = ({
title = 'description.not_found',
message,
rawMessage,
isNavbarHidden,
}: Props) => {
const { theme } = useContext(PageContext);
const errorMessage = Boolean(rawMessage ?? message);
return (
<StaticPageLayout>
<PageMeta titleKey={title} />
{history.length > 1 && <NavBar />}
{history.length > 1 && <NavBar isHidden={isNavbarHidden} />}
<div className={styles.container}>
{theme === Theme.Light ? <EmptyState /> : <EmptyStateDark />}
<div className={styles.title}>

View file

@ -136,6 +136,7 @@ const OneTimeToken = () => {
if (oneTimeTokenError) {
return (
<ErrorPage
isNavbarHidden
title="error.invalid_link"
message="error.invalid_link_description"
rawMessage={condString(typeof oneTimeTokenError !== 'boolean' && oneTimeTokenError.message)}

View file

@ -4,7 +4,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
import StaticPageLayout from '@/Layout/StaticPageLayout';
import PageContext from '@/Providers/PageContextProvider/PageContext';
import { consent, getConsentInfo } from '@/apis/consent';
import { getConsentInfo } from '@/apis/consent';
import Button from '@/components/Button';
import DynamicT from '@/components/DynamicT';
import LoadingLayer from '@/components/LoadingLayer';
@ -12,7 +12,6 @@ import PageMeta from '@/components/PageMeta';
import TextLink from '@/components/TextLink';
import useApi from '@/hooks/use-api';
import useErrorHandler from '@/hooks/use-error-handler';
import useGlobalRedirectTo from '@/hooks/use-global-redirect-to';
import UserProfile from '@/pages/Consent/UserProfile';
import ErrorPage from '@/pages/ErrorPage';
import { getBrandingLogoUrl } from '@/utils/logo';
@ -26,12 +25,10 @@ import styles from './index.module.scss';
const SwitchAccount = () => {
const { experienceSettings, theme } = useContext(PageContext);
const navigate = useNavigate();
const redirectTo = useGlobalRedirectTo();
const handleError = useErrorHandler();
const [consentData, setConsentData] = useState<ConsentInfoResponse>();
const asyncGetConsentInfo = useApi(getConsentInfo);
const asyncConsent = useApi(consent);
const [params] = useSearchParams();
const loginHint = params.get('login_hint');
@ -94,14 +91,7 @@ const SwitchAccount = () => {
<TextLink
text="action.back_to_current_account"
onClick={async () => {
const [error, result] = await asyncConsent();
if (error) {
await handleError(error);
return;
}
if (result?.redirectTo) {
await redirectTo(result.redirectTo);
}
history.back();
}}
/>
</div>