diff --git a/src/pages/board/[slug].tsx b/src/pages/board/[slug].tsx index 2b9adeffc..40ff9f598 100644 --- a/src/pages/board/[slug].tsx +++ b/src/pages/board/[slug].tsx @@ -1,33 +1,33 @@ +import { TRPCError } from '@trpc/server'; import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; import { SSRConfig } from 'next-i18next'; import { z } from 'zod'; +import { BoardProvider } from '~/components/Board/context'; import { Board } from '~/components/Dashboard/Dashboard'; import { BoardLayout } from '~/components/layout/Templates/BoardLayout'; -import { useInitConfig } from '~/config/init'; import { env } from '~/env'; +import { createTrpcServersideHelpers } from '~/server/api/helper'; import { getServerAuthSession } from '~/server/auth'; -import { configExists } from '~/tools/config/configExists'; -import { getFrontendConfig } from '~/tools/config/getFrontendConfig'; import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations'; import { checkForSessionOrAskForLogin } from '~/tools/server/loginBuilder'; import { boardNamespaces } from '~/tools/server/translation-namespaces'; -import { ConfigType } from '~/types/config'; +import { RouterOutputs } from '~/utils/api'; export default function BoardPage({ - config: initialConfig, + board, dockerEnabled, }: InferGetServerSidePropsType) { - useInitConfig(initialConfig); - return ( - - - + + + + + ); } type BoardGetServerSideProps = { - config: ConfigType; + board: RouterOutputs['boards']['byName']; dockerEnabled: boolean; _nextI18Next?: SSRConfig['_nextI18Next']; }; @@ -44,14 +44,6 @@ export const getServerSideProps: GetServerSideProps = a }; } - const isPresent = configExists(routeParams.data.slug); - if (!isPresent) { - return { - notFound: true, - }; - } - - const config = await getFrontendConfig(routeParams.data.slug); const translations = await getServerSideTranslations( boardNamespaces, ctx.locale, @@ -59,12 +51,28 @@ export const getServerSideProps: GetServerSideProps = a ctx.res ); + const helpers = await createTrpcServersideHelpers(ctx); + const board = await helpers.boards.byName + .fetch({ boardName: routeParams.data.slug }) + .catch((err) => { + if (err instanceof TRPCError && err.code === 'NOT_FOUND') { + return null; + } + throw err; + }); + + if (!board) { + return { + notFound: true, + }; + } + const session = await getServerAuthSession({ req: ctx.req, res: ctx.res }); const result = checkForSessionOrAskForLogin( ctx, session, - () => config.settings.access.allowGuests || !session?.user + () => board.allowGuests || !!session?.user ); if (result) { return result; @@ -72,10 +80,10 @@ export const getServerSideProps: GetServerSideProps = a return { props: { - config, - primaryColor: config.settings.customization.colors.primary, - secondaryColor: config.settings.customization.colors.secondary, - primaryShade: config.settings.customization.colors.shade, + board, + primaryColor: board.primaryColor, + secondaryColor: board.secondaryColor, + primaryShade: board.primaryShade, dockerEnabled: !!env.DOCKER_HOST && !!env.DOCKER_PORT, ...translations, },