File size: 1,639 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import { InfoBox, Text } from '@adminjs/design-system'
import React, { FC, useMemo } from 'react'
import { Trans } from 'react-i18next'
import { useSelector } from 'react-redux'
import { useParams } from 'react-router'
import allowOverride from '../../hoc/allow-override.js'
import withNoSSR from '../../hoc/with-no-ssr.js'
import { useTranslation } from '../../hooks/index.js'
import { ReduxState } from '../../store/store.js'
import ErrorBoundary from '../app/error-boundary.js'
declare const AdminJS: {
UserComponents: Record<string, FC>;
}
type PageRouteProps = {
pageName: string;
}
const Page: FC = () => {
const pages = useSelector((state: ReduxState) => state.pages)
const params = useParams<PageRouteProps>()
const { pageName } = params
const { tm } = useTranslation()
const currentPage = useMemo(() => pages.find(({ name }) => name === pageName), [pages, pageName])
if (!currentPage) {
return (
<InfoBox title={tm('pageNotFound_title')} illustration="NotFound">
<Text mb="xxl">
<Trans i18nKey="messages.pageNotFound_subtitle" values={{ pageName }} components={{ strong: <strong /> }} />
</Text>
</InfoBox>
)
}
const Component = AdminJS.UserComponents[currentPage.component]
if (!Component) {
return (
<InfoBox title={tm('componentNotFound_title')} illustration="Beware">
<Text mb="xxl">
<Trans i18nKey="messages.componentNotFound_subtitle" />
</Text>
</InfoBox>
)
}
return (
<ErrorBoundary>
<Component />
</ErrorBoundary>
)
}
export default allowOverride(withNoSSR(Page), 'PageRoute')
|