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

fix(console): should be able to edit password and email in profile

This commit is contained in:
Charles Zhao 2024-08-14 18:59:57 +08:00
parent a6002d5f19
commit a8d26a00d7
No known key found for this signature in database
GPG key ID: 3EBD576D8B273301
4 changed files with 64 additions and 39 deletions

View file

@ -1,5 +1,7 @@
import { Suspense } from 'react';
import { Route, Routes } from 'react-router-dom'; import { Route, Routes } from 'react-router-dom';
import DelayedSuspenseFallback from '@/components/DelayedSuspenseFallback';
import ProtectedRoutes from '@/containers/ProtectedRoutes'; import ProtectedRoutes from '@/containers/ProtectedRoutes';
import { GlobalAnonymousRoute, GlobalRoute } from '@/contexts/TenantsProvider'; import { GlobalAnonymousRoute, GlobalRoute } from '@/contexts/TenantsProvider';
import { OnboardingApp } from '@/onboarding'; import { OnboardingApp } from '@/onboarding';
@ -17,21 +19,26 @@ import SocialDemoCallback from './pages/SocialDemoCallback';
function AppRoutes() { function AppRoutes() {
return ( return (
<div className={styles.app}> <div className={styles.app}>
<Routes> <Suspense fallback={<DelayedSuspenseFallback />}>
<Route path={GlobalAnonymousRoute.Callback} element={<Callback />} /> <Routes>
<Route path={GlobalAnonymousRoute.SocialDemoCallback} element={<SocialDemoCallback />} /> <Route path={GlobalAnonymousRoute.Callback} element={<Callback />} />
<Route element={<ProtectedRoutes />}> <Route path={GlobalAnonymousRoute.SocialDemoCallback} element={<SocialDemoCallback />} />
<Route <Route element={<ProtectedRoutes />}>
path={`${GlobalRoute.AcceptInvitation}/:invitationId`} <Route
element={<AcceptInvitation />} path={`${GlobalRoute.AcceptInvitation}/:invitationId`}
/> element={<AcceptInvitation />}
<Route path={GlobalRoute.Profile + '/*'} element={<Profile />} /> />
<Route path={GlobalRoute.HandleSocial} element={<HandleSocialCallback />} /> <Route path={GlobalRoute.Profile + '/*'} element={<Profile />} />
<Route path={GlobalRoute.CheckoutSuccessCallback} element={<CheckoutSuccessCallback />} /> <Route path={GlobalRoute.HandleSocial} element={<HandleSocialCallback />} />
<Route path={GlobalRoute.Onboarding + '/*'} element={<OnboardingApp />} /> <Route
<Route index element={<Main />} /> path={GlobalRoute.CheckoutSuccessCallback}
</Route> element={<CheckoutSuccessCallback />}
</Routes> />
<Route path={GlobalRoute.Onboarding + '/*'} element={<OnboardingApp />} />
<Route index element={<Main />} />
</Route>
</Routes>
</Suspense>
</div> </div>
); );
} }

View file

@ -0,0 +1,6 @@
.daisy {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}

View file

@ -0,0 +1,33 @@
import { useState, useEffect } from 'react';
import { Daisy } from '@/ds-components/Spinner';
import styles from './index.module.scss';
const suspenseDisplayTimeout = 500; // Milliseconds
/**
* Displays a spinner after a short delay (500ms) to prevent flashing
* @returns {JSX.Element} The spinner
*/
function DelayedSuspenseFallback() {
const [showSpinner, setShowSpinner] = useState(false);
useEffect(() => {
const timeout = window.setTimeout(() => {
setShowSpinner(true);
}, suspenseDisplayTimeout);
return () => {
clearTimeout(timeout);
};
}, []);
if (showSpinner) {
return <Daisy className={styles.daisy} />;
}
return null;
}
export default DelayedSuspenseFallback;

View file

@ -1,10 +1,10 @@
import { Suspense, useEffect, useState } from 'react'; import { Suspense } from 'react';
import { useOutletContext, useRoutes } from 'react-router-dom'; import { useOutletContext, useRoutes } from 'react-router-dom';
import { safeLazy } from 'react-safe-lazy'; import { safeLazy } from 'react-safe-lazy';
import DelayedSuspenseFallback from '@/components/DelayedSuspenseFallback';
import { isDevFeaturesEnabled } from '@/consts/env'; import { isDevFeaturesEnabled } from '@/consts/env';
import OverlayScrollbar from '@/ds-components/OverlayScrollbar'; import OverlayScrollbar from '@/ds-components/OverlayScrollbar';
import { Daisy } from '@/ds-components/Spinner';
import Tag from '@/ds-components/Tag'; import Tag from '@/ds-components/Tag';
import { useConsoleRoutes } from '@/hooks/use-console-routes'; import { useConsoleRoutes } from '@/hooks/use-console-routes';
import { usePlausiblePageview } from '@/hooks/use-plausible-pageview'; import { usePlausiblePageview } from '@/hooks/use-plausible-pageview';
@ -15,29 +15,8 @@ import { Skeleton } from './Sidebar';
import useTenantScopeListener from './hooks'; import useTenantScopeListener from './hooks';
import styles from './index.module.scss'; import styles from './index.module.scss';
const suspenseDisplayTimeout = 500; // Milliseconds
const Sidebar = safeLazy(async () => import('./Sidebar')); const Sidebar = safeLazy(async () => import('./Sidebar'));
function SuspenseFallback() {
const [showSpinner, setShowSpinner] = useState(false);
useEffect(() => {
const timeout = window.setTimeout(() => {
setShowSpinner(true);
}, suspenseDisplayTimeout);
return () => {
clearTimeout(timeout);
};
}, []);
if (showSpinner) {
return <Daisy className={styles.daisy} />;
}
return null;
}
function ConsoleContent() { function ConsoleContent() {
const { scrollableContent } = useOutletContext<AppContentOutletContext>(); const { scrollableContent } = useOutletContext<AppContentOutletContext>();
const routeObjects = useConsoleRoutes(); const routeObjects = useConsoleRoutes();
@ -54,7 +33,7 @@ function ConsoleContent() {
</Suspense> </Suspense>
<OverlayScrollbar className={styles.overlayScrollbarWrapper}> <OverlayScrollbar className={styles.overlayScrollbarWrapper}>
<div ref={scrollableContent} className={styles.main}> <div ref={scrollableContent} className={styles.main}>
<Suspense fallback={<SuspenseFallback />}>{routes}</Suspense> <Suspense fallback={<DelayedSuspenseFallback />}>{routes}</Suspense>
</div> </div>
</OverlayScrollbar> </OverlayScrollbar>
{isDevFeaturesEnabled && ( {isDevFeaturesEnabled && (