feat: protect wallpaper page for unsubscribed user
This commit is contained in:
parent
9255c79dc6
commit
8229ab3292
@ -1,9 +1,11 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Routes, Route, Navigate, Outlet, useLocation } from 'react-router-dom'
|
import {
|
||||||
|
Routes, Route, Navigate, Outlet, useLocation
|
||||||
|
} from 'react-router-dom'
|
||||||
import { useAuth } from '../../auth'
|
import { useAuth } from '../../auth'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { selectors } from '../../store'
|
import { selectors } from '../../store'
|
||||||
import routes, { hasNavigation } from '../../routes'
|
import routes, { hasNavigation, getRouteBy } from '../../routes'
|
||||||
import BirthdayPage from '../BirthdayPage'
|
import BirthdayPage from '../BirthdayPage'
|
||||||
import BirthtimePage from '../BirthtimePage'
|
import BirthtimePage from '../BirthtimePage'
|
||||||
import CreateProfilePage from '../CreateProfilePage'
|
import CreateProfilePage from '../CreateProfilePage'
|
||||||
@ -31,7 +33,7 @@ function App(): JSX.Element {
|
|||||||
<Route element={<PrivateOutlet />}>
|
<Route element={<PrivateOutlet />}>
|
||||||
<Route path={routes.client.subscription()} element={<SubscriptionPage />} />
|
<Route path={routes.client.subscription()} element={<SubscriptionPage />} />
|
||||||
<Route path={routes.client.paymentMethod()} element={<PaymentPage />} />
|
<Route path={routes.client.paymentMethod()} element={<PaymentPage />} />
|
||||||
<Route path={routes.client.wallpaper()} element={<WallpaperPage />} />
|
<Route path={routes.client.wallpaper()} element={<ProtectWallpaperPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="*" element={<NotFoundPage />} />
|
<Route path="*" element={<NotFoundPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
@ -65,13 +67,12 @@ function SkipStep(): JSX.Element {
|
|||||||
|
|
||||||
function MainPage(): JSX.Element {
|
function MainPage(): JSX.Element {
|
||||||
const status = useSelector(selectors.selectStatus)
|
const status = useSelector(selectors.selectStatus)
|
||||||
const pageMapper = {
|
return <Navigate to={getRouteBy(status)} replace={true} />
|
||||||
'lead': routes.client.birthday(),
|
}
|
||||||
'registred': routes.client.subscription(),
|
|
||||||
'subscribed': routes.client.wallpaper(),
|
function ProtectWallpaperPage(): JSX.Element {
|
||||||
'unsubscribed': routes.client.subscription(),
|
const status = useSelector(selectors.selectStatus)
|
||||||
}
|
return status === 'subscribed' ? <WallpaperPage /> : <Navigate to={getRouteBy(status)} replace={true} />
|
||||||
return <Navigate to={pageMapper[status]} replace={true} />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App
|
export default App
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import type { UserStatus } from "./types"
|
||||||
|
|
||||||
const host = ''
|
const host = ''
|
||||||
const apiHost = 'https://aura.wit.life'
|
const apiHost = 'https://aura.wit.life'
|
||||||
const prefix = 'api/v1'
|
const prefix = 'api/v1'
|
||||||
@ -45,4 +47,18 @@ export const withNavigationRoutes = [routes.client.wallpaper()]
|
|||||||
export const hasNavigation = (path: string) => withNavigationRoutes.includes(path)
|
export const hasNavigation = (path: string) => withNavigationRoutes.includes(path)
|
||||||
export const hasNoNavigation = (path: string) => !hasNavigation(path)
|
export const hasNoNavigation = (path: string) => !hasNavigation(path)
|
||||||
|
|
||||||
|
export const getRouteBy = (status: UserStatus): string => {
|
||||||
|
switch (status) {
|
||||||
|
case 'lead':
|
||||||
|
return routes.client.birthday()
|
||||||
|
case 'registred':
|
||||||
|
case 'unsubscribed':
|
||||||
|
return routes.client.subscription()
|
||||||
|
case 'subscribed':
|
||||||
|
return routes.client.wallpaper()
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown user status, received status is "${status}"`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default routes
|
export default routes
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { createSlice, createSelector } from '@reduxjs/toolkit'
|
import { createSlice, createSelector } from '@reduxjs/toolkit'
|
||||||
import type { PayloadAction } from '@reduxjs/toolkit'
|
import type { PayloadAction } from '@reduxjs/toolkit'
|
||||||
|
import type { UserStatus } from '../types'
|
||||||
type UserStatus = 'lead' | 'registred' | 'subscribed' | 'unsubscribed'
|
|
||||||
|
|
||||||
const initialState = 'lead' as UserStatus
|
const initialState = 'lead' as UserStatus
|
||||||
|
|
||||||
|
|||||||
@ -23,3 +23,4 @@ export interface SignupForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type AppConfig = typeof config
|
export type AppConfig = typeof config
|
||||||
|
export type UserStatus = 'lead' | 'registred' | 'subscribed' | 'unsubscribed'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user