Skip to content

Commit 7b11843

Browse files
committed
MP-2 init accounts app
1 parent b151d73 commit 7b11843

26 files changed

+255
-0
lines changed

src/apps/accounts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Accounts App

src/apps/accounts/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { FC, useContext } from 'react'
2+
import { Outlet, Routes } from 'react-router-dom'
3+
4+
import { routerContext, RouterContextData } from '~/libs/core'
5+
6+
import { toolTitle } from './accounts.routes'
7+
import { AccountsSwr } from './lib'
8+
9+
const AccountsApp: FC<{}> = () => {
10+
const { getChildRoutes }: RouterContextData = useContext(routerContext)
11+
12+
return (
13+
<AccountsSwr>
14+
<Outlet />
15+
<Routes>
16+
{getChildRoutes(toolTitle)}
17+
</Routes>
18+
</AccountsSwr>
19+
)
20+
}
21+
22+
export default AccountsApp
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { lazyLoad, LazyLoadedComponent, PlatformRoute } from '~/libs/core'
2+
import { AppSubdomain, EnvironmentConfig, ToolTitle } from '~/config'
3+
4+
const AccountsApp: LazyLoadedComponent = lazyLoad(() => import('./AccountsApp'))
5+
const AccountSettingsPage: LazyLoadedComponent = lazyLoad(() => import('./settings'), 'AccountSettingsPage')
6+
7+
export const rootRoute: string = (
8+
EnvironmentConfig.SUBDOMAIN === AppSubdomain.accounts ? '' : `/${AppSubdomain.accounts}`
9+
)
10+
11+
export const toolTitle: string = ToolTitle.accounts
12+
export const absoluteRootRoute: string = `${window.location.origin}${rootRoute}`
13+
14+
export const accountsRoutes: ReadonlyArray<PlatformRoute> = [
15+
{
16+
authRequired: true,
17+
children: [
18+
{
19+
children: [],
20+
element: <AccountSettingsPage />,
21+
id: 'Account Settings',
22+
route: '',
23+
},
24+
],
25+
domain: AppSubdomain.accounts,
26+
element: <AccountsApp />,
27+
id: toolTitle,
28+
route: rootRoute,
29+
},
30+
]

src/apps/accounts/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export {
2+
accountsRoutes,
3+
rootRoute as accountsRootRoute,
4+
} from './accounts.routes'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { FC, ReactNode } from 'react'
2+
import { SWRConfig } from 'swr'
3+
4+
import { xhrGetAsync } from '~/libs/core'
5+
6+
interface AccountsSwrProps {
7+
children: ReactNode
8+
}
9+
10+
const AccountsSwr: FC<AccountsSwrProps> = (props: AccountsSwrProps) => (
11+
<SWRConfig
12+
value={{
13+
fetcher: resource => xhrGetAsync(resource),
14+
refreshInterval: 0,
15+
revalidateOnFocus: false,
16+
revalidateOnMount: true,
17+
}}
18+
>
19+
{props.children}
20+
</SWRConfig>
21+
)
22+
23+
export default AccountsSwr
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as AccountsSwr } from './AccountsSwr'

src/apps/accounts/src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './accounts-swr'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { FC, useContext } from 'react'
2+
3+
import { profileContext, ProfileContextData } from '~/libs/core'
4+
import { LoadingSpinner } from '~/libs/ui'
5+
6+
import { AccountSettingsLayout } from './page-layout'
7+
8+
const AccountSettingsPage: FC<{}> = () => {
9+
const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext)
10+
11+
return (
12+
<>
13+
<LoadingSpinner hide={profileReady} />
14+
15+
{profileReady && profile && (
16+
<AccountSettingsLayout
17+
profile={profile}
18+
/>
19+
)}
20+
</>
21+
)
22+
}
23+
24+
export default AccountSettingsPage
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as AccountSettingsPage } from './AccountSettingsPage'

0 commit comments

Comments
 (0)