Skip to content

V5 challenge management #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/apps/admin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src'
62 changes: 62 additions & 0 deletions src/apps/admin/src/AdminApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
FC,
JSXElementConstructor,
PropsWithChildren,
useContext,
useEffect,
useMemo,
} from 'react'
import { Outlet, Routes, useLocation } from 'react-router-dom'

import { routerContext, RouterContextData } from '~/libs/core'

import { NullLayout, SWRConfigProvider } from './lib'
import { adminRoutes, toolTitle } from './admin-app.routes'
import ChallengeManagement from './challenge-management/ChallengeManagement'
import './lib/styles/index.scss'

/**
* The admin app.
*/
const AdminApp: FC = () => {
const { getChildRoutes }: RouterContextData = useContext(routerContext)
// eslint-disable-next-line react-hooks/exhaustive-deps -- missing dependency: getChildRoutes
const childRoutes = useMemo(() => getChildRoutes(toolTitle), [])
const AppLayout = useAppLayout()

useEffect(() => {
document.body.classList.add('admin-app')
return () => {
document.body.classList.remove('admin-app')
}
}, [])

return (
<div>
<SWRConfigProvider>
<AppLayout>
<Outlet />
<Routes>{childRoutes}</Routes>
</AppLayout>
</SWRConfigProvider>
</div>
)
}

function useAppLayout(): JSXElementConstructor<PropsWithChildren> {
const challengeManagementPath = adminRoutes[0].children?.find(
r => r.id === 'challenge-management',
)?.route
const locationPath = useLocation().pathname

if (
challengeManagementPath
&& locationPath.includes(challengeManagementPath)
) {
return ChallengeManagement.Layout
}

return NullLayout
}

export default AdminApp
65 changes: 65 additions & 0 deletions src/apps/admin/src/admin-app.routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { AppSubdomain, EnvironmentConfig, ToolTitle } from '~/config'
import {
lazyLoad,
LazyLoadedComponent,
PlatformRoute,
Rewrite,
UserRole,
} from '~/libs/core'

const AdminApp: LazyLoadedComponent = lazyLoad(() => import('./AdminApp'))

const ChallengeManagement: LazyLoadedComponent = lazyLoad(
() => import('./challenge-management/ChallengeManagement'),
)
const ChallengeManagementPage: LazyLoadedComponent = lazyLoad(
() => import('./challenge-management/ChallengeManagementPage'),
'ChallengeManagementPage',
)
const ManageUserPage: LazyLoadedComponent = lazyLoad(
() => import('./challenge-management/ManageUserPage'),
'ManageUserPage',
)

export const toolTitle: string = ToolTitle.admin
export const rootRoute: string
= EnvironmentConfig.SUBDOMAIN === AppSubdomain.admin
? '/'
: `/${AppSubdomain.admin}`

export const adminRoutes: ReadonlyArray<PlatformRoute> = [
// Admin App Root
{
authRequired: true,
children: [
{
element: <Rewrite to='challenge-management' />,
route: '',
},
// Challenge Management Module
{
children: [
{
element: <ChallengeManagementPage />,
id: 'challenge-management-page',
route: '',
},
{
element: <ManageUserPage />,
id: 'manage-user',
route: ':challengeId/manage-user',
},
],
element: <ChallengeManagement />,
id: 'challenge-management',
route: 'challenge-management',
},
],
domain: AppSubdomain.admin,
element: <AdminApp />,
id: toolTitle,
rolesRequired: [UserRole.administrator],
route: rootRoute,
title: toolTitle,
},
]
46 changes: 46 additions & 0 deletions src/apps/admin/src/challenge-management/ChallengeManagement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FC, PropsWithChildren, useContext, useMemo } from 'react'
import { Outlet, Routes } from 'react-router-dom'

import { routerContext, RouterContextData } from '~/libs/core'

import { Layout } from '../lib/components'
import { ChallengeManagementContextProvider } from '../lib/contexts'
import { adminRoutes } from '../admin-app.routes'

/**
* The router outlet with layout.
*/
export const ChallengeManagement: FC & {
Layout: FC<PropsWithChildren>
} = () => {
const childRoutes = useChildRoutes()

return (
<ChallengeManagementContextProvider>
<Outlet />
<Routes>{childRoutes}</Routes>
</ChallengeManagementContextProvider>
)
}

function useChildRoutes(): Array<JSX.Element> | undefined {
const { getRouteElement }: RouterContextData = useContext(routerContext)
const childRoutes = useMemo(
() => adminRoutes[0].children
?.find(r => r.id === 'challenge-management')
?.children?.map(getRouteElement),
[], // eslint-disable-line react-hooks/exhaustive-deps -- missing dependency: getRouteElement
)
return childRoutes
}

/**
* The outlet layout.
*/
ChallengeManagement.Layout = function ChallengeManagementLayout(
props: PropsWithChildren,
) {
return <Layout>{props.children}</Layout>
}

export default ChallengeManagement
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.loadingSpinnerContainer {
position: relative;
height: 100px;
margin-top: -30px;

.spinner {
background: none;
}
}

.noRecordFound {
padding: 16px 16px 32px;
text-align: center;
}
Loading