mirror of
https://github.com/gromlab-ru/slm-design.git
synced 2026-08-22 07:30:16 +03:00
chore: demo app
This commit is contained in:
46
examples/react-vite/src/app/app.tsx
Normal file
46
examples/react-vite/src/app/app.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Navigate, Route, Routes } from 'react-router-dom'
|
||||
|
||||
import { SignInScreen } from 'compositions/screens/sign-in'
|
||||
import { StorefrontScreen } from 'compositions/screens/storefront'
|
||||
import { OrdersProvider } from 'domains/orders'
|
||||
import { useSessionState } from 'domains/session'
|
||||
import styles from './styles/app.module.css'
|
||||
|
||||
/**
|
||||
* Browser entry, выбирающий экран по session lifecycle.
|
||||
*
|
||||
* Используется для:
|
||||
* - защиты storefront route пользовательской сессией
|
||||
* - завершения bootstrap до первого route render
|
||||
*/
|
||||
export const App = () => {
|
||||
const { status } = useSessionState()
|
||||
|
||||
if (status === 'restoring') {
|
||||
return (
|
||||
<main className={styles.loader} aria-live="polite">
|
||||
<span className={styles.loaderMark}>S</span>
|
||||
<strong>Восстанавливаем сессию</strong>
|
||||
<small>Simple API · JWT rotation</small>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
const isAuthenticated = status === 'authenticated'
|
||||
const signInElement = isAuthenticated ? <Navigate to="/" replace /> : <SignInScreen />
|
||||
const storefrontElement = isAuthenticated ? (
|
||||
<OrdersProvider>
|
||||
<StorefrontScreen />
|
||||
</OrdersProvider>
|
||||
) : (
|
||||
<Navigate to="/login" replace />
|
||||
)
|
||||
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={signInElement} />
|
||||
<Route path="/" element={storefrontElement} />
|
||||
<Route path="*" element={<Navigate to={isAuthenticated ? '/' : '/login'} replace />} />
|
||||
</Routes>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user