refactor: clean up code formatting and improve readability in swarm dashboard

This commit is contained in:
djknaeckebrot
2024-12-17 12:06:08 +01:00
parent 5716954665
commit 813da8f811

View File

@@ -1,4 +1,3 @@
import { ShowSwarm } from "@/components/dashboard/swarm/show/node-list";
import ShowSwarmNodes from "@/components/dashboard/swarm/show/show-nodes"; import ShowSwarmNodes from "@/components/dashboard/swarm/show/show-nodes";
import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { DashboardLayout } from "@/components/layouts/dashboard-layout";
import { appRouter } from "@/server/api/root"; import { appRouter } from "@/server/api/root";
@@ -9,73 +8,73 @@ import React, { type ReactElement } from "react";
import superjson from "superjson"; import superjson from "superjson";
const Dashboard = () => { const Dashboard = () => {
return <ShowSwarmNodes />; return <ShowSwarmNodes />;
}; };
export default Dashboard; export default Dashboard;
Dashboard.getLayout = (page: ReactElement) => { Dashboard.getLayout = (page: ReactElement) => {
return <DashboardLayout tab={"swarm"}>{page}</DashboardLayout>; return <DashboardLayout tab={"swarm"}>{page}</DashboardLayout>;
}; };
export async function getServerSideProps( export async function getServerSideProps(
ctx: GetServerSidePropsContext<{ serviceId: string }> ctx: GetServerSidePropsContext<{ serviceId: string }>,
) { ) {
if (IS_CLOUD) { if (IS_CLOUD) {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,
destination: "/dashboard/projects", destination: "/dashboard/projects",
}, },
}; };
} }
const { user, session } = await validateRequest(ctx.req, ctx.res); const { user, session } = await validateRequest(ctx.req, ctx.res);
if (!user) { if (!user) {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,
destination: "/", destination: "/",
}, },
}; };
} }
const { req, res } = ctx; const { req, res } = ctx;
const helpers = createServerSideHelpers({ const helpers = createServerSideHelpers({
router: appRouter, router: appRouter,
ctx: { ctx: {
req: req as any, req: req as any,
res: res as any, res: res as any,
db: null as any, db: null as any,
session: session, session: session,
user: user, user: user,
}, },
transformer: superjson, transformer: superjson,
}); });
try { try {
await helpers.project.all.prefetch(); await helpers.project.all.prefetch();
const auth = await helpers.auth.get.fetch(); const auth = await helpers.auth.get.fetch();
if (auth.rol === "user") { if (auth.rol === "user") {
const user = await helpers.user.byAuthId.fetch({ const user = await helpers.user.byAuthId.fetch({
authId: auth.id, authId: auth.id,
}); });
if (!user.canAccessToDocker) { if (!user.canAccessToDocker) {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,
destination: "/", destination: "/",
}, },
}; };
} }
} }
return { return {
props: { props: {
trpcState: helpers.dehydrate(), trpcState: helpers.dehydrate(),
}, },
}; };
} catch (error) { } catch (error) {
return { return {
props: {}, props: {},
}; };
} }
} }