mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(ui): some ui structure refactor (#1069)
some ui structure refactor
This commit is contained in:
parent
abf510eb8a
commit
dc7f9ccdb6
7 changed files with 18 additions and 13 deletions
|
@ -1,9 +1,7 @@
|
||||||
import { conditionalString } from '@silverhand/essentials';
|
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { Route, Routes, BrowserRouter, Navigate } from 'react-router-dom';
|
import { Route, Routes, BrowserRouter, Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import * as styles from './App.module.scss';
|
import AppContent from './containers/AppContent';
|
||||||
import AppContent from './components/AppContent';
|
|
||||||
import LoadingLayerProvider from './containers/LoadingLayerProvider';
|
import LoadingLayerProvider from './containers/LoadingLayerProvider';
|
||||||
import usePageContext from './hooks/use-page-context';
|
import usePageContext from './hooks/use-page-context';
|
||||||
import usePreview from './hooks/use-preview';
|
import usePreview from './hooks/use-preview';
|
||||||
|
@ -29,8 +27,6 @@ const App = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isPreview) {
|
if (isPreview) {
|
||||||
document.body.classList.add(conditionalString(styles.preview));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,17 +57,21 @@ const App = () => {
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route element={<LoadingLayerProvider />}>
|
<Route element={<LoadingLayerProvider />}>
|
||||||
{/* always keep route path with param as the last one */}
|
|
||||||
<Route path="/sign-in" element={<SignIn />} />
|
<Route path="/sign-in" element={<SignIn />} />
|
||||||
<Route path="/sign-in/:method" element={<SecondarySignIn />} />
|
<Route path="/sign-in/:method" element={<SecondarySignIn />} />
|
||||||
<Route path="/register" element={<Register />} />
|
<Route path="/register" element={<Register />} />
|
||||||
<Route path="/register/:method" element={<Register />} />
|
<Route path="/register/:method" element={<Register />} />
|
||||||
|
|
||||||
{/* social sign-in pages */}
|
{/* social sign-in pages */}
|
||||||
<Route path="/sign-in/callback/:connector" element={<SocialSignInCallback />} />
|
<Route
|
||||||
|
path="/social/sign-in-callback/:connector"
|
||||||
|
element={<SocialSignInCallback />}
|
||||||
|
/>
|
||||||
<Route path="/callback/:connector" element={<Callback />} />
|
<Route path="/callback/:connector" element={<Callback />} />
|
||||||
<Route path="/social/register/:connector" element={<SocialRegister />} />
|
<Route path="/social/register/:connector" element={<SocialRegister />} />
|
||||||
<Route path="/social/landing/:connector" element={<SocialLanding />} />
|
<Route path="/social/landing/:connector" element={<SocialLanding />} />
|
||||||
|
|
||||||
|
{/* always keep route path with param as the last one */}
|
||||||
<Route path="/:type/:method/passcode-validation" element={<Passcode />} />
|
<Route path="/:type/:method/passcode-validation" element={<Passcode />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { Language } from '@logto/phrases';
|
import { Language } from '@logto/phrases';
|
||||||
import { AppearanceMode } from '@logto/schemas';
|
import { AppearanceMode } from '@logto/schemas';
|
||||||
|
import { conditionalString } from '@silverhand/essentials';
|
||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import * as styles from '@/App.module.scss';
|
||||||
import { Context } from '@/hooks/use-page-context';
|
import { Context } from '@/hooks/use-page-context';
|
||||||
import initI18n from '@/i18n/init';
|
import initI18n from '@/i18n/init';
|
||||||
import { SignInExperienceSettingsResponse, Platform } from '@/types';
|
import { SignInExperienceSettingsResponse, Platform } from '@/types';
|
||||||
|
@ -32,6 +34,9 @@ const usePreview = (context: Context): [boolean, PreviewConfig?] => {
|
||||||
// Init i18n
|
// Init i18n
|
||||||
void initI18n();
|
void initI18n();
|
||||||
|
|
||||||
|
// Block pointer event
|
||||||
|
document.body.classList.add(conditionalString(styles.preview));
|
||||||
|
|
||||||
const previewMessageHandler = (event: MessageEvent) => {
|
const previewMessageHandler = (event: MessageEvent) => {
|
||||||
if (event.origin !== window.location.origin) {
|
if (event.origin !== window.location.origin) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -47,7 +47,7 @@ const useSocialCallbackHandler = () => {
|
||||||
// Web flow
|
// Web flow
|
||||||
navigate(
|
navigate(
|
||||||
{
|
{
|
||||||
pathname: `/sign-in/callback/${connectorId}`,
|
pathname: `/social/sign-in-callback/${connectorId}`,
|
||||||
search: data,
|
search: data,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ const useSocial = () => {
|
||||||
: redirectTo;
|
: redirectTo;
|
||||||
|
|
||||||
getLogtoNativeSdk()?.getPostMessage()({
|
getLogtoNativeSdk()?.getPostMessage()({
|
||||||
callbackUri: `${window.location.origin}/sign-in/callback/${connectorId}`,
|
callbackUri: `${window.location.origin}/social/sign-in-callback/${connectorId}`,
|
||||||
redirectTo: redirectUri,
|
redirectTo: redirectUri,
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
|
@ -24,9 +24,9 @@ describe('SocialCallbackPage with code', () => {
|
||||||
Object.defineProperty(window, 'location', {
|
Object.defineProperty(window, 'location', {
|
||||||
value: {
|
value: {
|
||||||
origin,
|
origin,
|
||||||
href: `/sign-in/callback?state=${state}&code=foo`,
|
href: `/social/sign-in-callback?state=${state}&code=foo`,
|
||||||
search: `?state=${state}&code=foo`,
|
search: `?state=${state}&code=foo`,
|
||||||
pathname: '/sign-in/callback',
|
pathname: '/social/sign-in-callback',
|
||||||
replace: jest.fn(),
|
replace: jest.fn(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -34,9 +34,9 @@ describe('SocialCallbackPage with code', () => {
|
||||||
|
|
||||||
renderWithPageContext(
|
renderWithPageContext(
|
||||||
<SettingsProvider>
|
<SettingsProvider>
|
||||||
<MemoryRouter initialEntries={['/sign-in/callback/github']}>
|
<MemoryRouter initialEntries={['/social/sign-in-callback/github']}>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/sign-in/callback/:connector" element={<SocialCallback />} />
|
<Route path="/social/sign-in-callback/:connector" element={<SocialCallback />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
</SettingsProvider>
|
</SettingsProvider>
|
||||||
|
|
Loading…
Reference in a new issue