Add slug board page

This commit is contained in:
Meier Lukas
2023-07-30 20:17:35 +02:00
parent 96529ae6bc
commit 5008b5e7a4
8 changed files with 75 additions and 27 deletions

View File

@@ -1,16 +0,0 @@
import { GetServerSideProps } from 'next';
export default function BoardPage() {
return (
<div>
<h1>BoardPage</h1>
</div>
);
}
export const getServerSideProps: GetServerSideProps = async () => {
console.log('getServerSideProps');
return {
props: {},
};
};

View File

@@ -0,0 +1,65 @@
import { GetServerSideProps, InferGetServerSidePropsType } from 'next';
import { SSRConfig } from 'next-i18next';
import { z } from 'zod';
import { Dashboard } from '~/components/Dashboard/Dashboard';
import { MainLayout } from '~/components/layout/main';
import { useInitConfig } from '~/config/init';
import { configExists } from '~/tools/config/configExists';
import { getFrontendConfig } from '~/tools/config/getFrontendConfig';
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
import { dashboardNamespaces } from '~/tools/server/translation-namespaces';
import { ConfigType } from '~/types/config';
import { HeaderActions } from '.';
export default function BoardPage({
config: initialConfig,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
useInitConfig(initialConfig);
return (
<MainLayout headerActions={<HeaderActions />}>
<Dashboard />
</MainLayout>
);
}
type BoardGetServerSideProps = {
config: ConfigType;
_nextI18Next?: SSRConfig['_nextI18Next'];
};
const routeParamsSchema = z.object({
slug: z.string(),
});
export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = async ({
params,
locale,
req,
res,
}) => {
const routeParams = routeParamsSchema.safeParse(params);
if (!routeParams.success) {
return {
notFound: true,
};
}
const isPresent = configExists(routeParams.data.slug);
if (!isPresent) {
return {
notFound: true,
};
}
const config = await getFrontendConfig(routeParams.data.slug);
const translations = await getServerSideTranslations(dashboardNamespaces, locale, req, res);
return {
props: {
config,
...translations,
},
};
};

View File

@@ -55,7 +55,7 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
ctx.res
);
const boardName = currentUserSettings?.defaultBoard ?? 'default';
const config = await getFrontendConfig(boardName as string);
const config = await getFrontendConfig(boardName);
return {
props: {
@@ -65,7 +65,7 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
};
};
const HeaderActions = () => {
export const HeaderActions = () => {
const { data: sessionData } = useSession();
if (!sessionData?.user?.isAdmin) return null;