Skip to content

Commit

Permalink
Merge pull request #1773 from ajnart/docker-onboarding-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnart committed Dec 31, 2023
2 parents a394843 + 745adb3 commit eba4dd3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
47 changes: 30 additions & 17 deletions src/pages/board/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import { GetServerSideProps, InferGetServerSidePropsType } from 'next';
import { SSRConfig } from 'next-i18next';
import { GetServerSidePropsContext, InferGetServerSidePropsType } from 'next';
import { z } from 'zod';
import { Dashboard } from '~/components/Dashboard/Dashboard';
import { BoardLayout } from '~/components/layout/Templates/BoardLayout';
import { useInitConfig } from '~/config/init';
import { env } from '~/env';
import { dockerRouter } from '~/server/api/routers/docker/router';
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 { api } from '~/utils/api';

export default function BoardPage({
config: initialConfig,
isDockerEnabled,
initialContainers,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
useInitConfig(initialConfig);
const { data } = api.docker.containers.useQuery(undefined, {
initialData: initialContainers ?? undefined,
enabled: isDockerEnabled,
cacheTime: 60 * 1000 * 5,
staleTime: 60 * 1000 * 1,
});

return (
<BoardLayout>
<BoardLayout isDockerEnabled={isDockerEnabled}>
<Dashboard />
</BoardLayout>
);
}

type BoardGetServerSideProps = {
config: ConfigType;
_nextI18Next?: SSRConfig['_nextI18Next'];
};

const routeParamsSchema = z.object({
slug: z.string(),
});

export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = async (ctx) => {
const routeParams = routeParamsSchema.safeParse(ctx.params);
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const routeParams = routeParamsSchema.safeParse(context.params);
if (!routeParams.success) {
return {
notFound: true,
Expand All @@ -52,28 +54,39 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
const config = await getFrontendConfig(routeParams.data.slug);
const translations = await getServerSideTranslations(
boardNamespaces,
ctx.locale,
ctx.req,
ctx.res
context.locale,
context.req,
context.res
);

const session = await getServerAuthSession({ req: ctx.req, res: ctx.res });
const session = await getServerAuthSession({ req: context.req, res: context.res });

const result = checkForSessionOrAskForLogin(
ctx,
context,
session,
() => config.settings.access.allowGuests || session?.user != undefined
);
if (result) {
return result;
}
const caller = dockerRouter.createCaller({
session: session,
cookies: context.req.cookies,
});
let containers = undefined;
// Fetch containers if user is admin, otherwise we don't need them
try {
if (session?.user.isAdmin == true) containers = await caller.containers();
} catch (error) {}

return {
props: {
config,
primaryColor: config.settings.customization.colors.primary,
secondaryColor: config.settings.customization.colors.secondary,
primaryShade: config.settings.customization.colors.shade,
isDockerEnabled: containers != undefined,
initialContainers: containers ?? null,
...translations,
},
};
Expand Down
5 changes: 0 additions & 5 deletions src/pages/board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export default function BoardPage({
);
}

type BoardGetServerSideProps = {
config: ConfigType;
_nextI18Next?: SSRConfig['_nextI18Next'];
};

export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const session = await getServerAuthSession(context);
const boardName = await getDefaultBoardAsync(session?.user?.id, 'default');
Expand Down

0 comments on commit eba4dd3

Please sign in to comment.