From e3b20268d520502e4d9c28e690401ff340114e31 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:56:33 -0600 Subject: [PATCH] refactor(dokploy): add ssr for settings to show instantly the sidebar --- .../pages/dashboard/settings/appearance.tsx | 7 ++++++ .../pages/dashboard/settings/billing.tsx | 2 ++ .../pages/dashboard/settings/certificates.tsx | 2 +- .../pages/dashboard/settings/cluster.tsx | 20 +++++++++++++++- .../pages/dashboard/settings/destinations.tsx | 2 +- .../dashboard/settings/git-providers.tsx | 2 +- .../dashboard/settings/notifications.tsx | 2 +- .../pages/dashboard/settings/profile.tsx | 7 ++++++ .../pages/dashboard/settings/registry.tsx | 2 +- .../pages/dashboard/settings/server.tsx | 23 +++++++++++++++++-- .../pages/dashboard/settings/servers.tsx | 2 +- .../pages/dashboard/settings/ssh-keys.tsx | 1 - .../pages/dashboard/settings/users.tsx | 2 +- 13 files changed, 63 insertions(+), 11 deletions(-) diff --git a/apps/dokploy/pages/dashboard/settings/appearance.tsx b/apps/dokploy/pages/dashboard/settings/appearance.tsx index 69ab7109..af317b0a 100644 --- a/apps/dokploy/pages/dashboard/settings/appearance.tsx +++ b/apps/dokploy/pages/dashboard/settings/appearance.tsx @@ -45,6 +45,13 @@ export async function getServerSideProps( await helpers.settings.isCloud.prefetch(); + await helpers.auth.get.prefetch(); + if (user?.rol === "user") { + await helpers.user.byAuthId.prefetch({ + authId: user.authId, + }); + } + if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/settings/billing.tsx b/apps/dokploy/pages/dashboard/settings/billing.tsx index 7e27af39..4aa7682c 100644 --- a/apps/dokploy/pages/dashboard/settings/billing.tsx +++ b/apps/dokploy/pages/dashboard/settings/billing.tsx @@ -55,6 +55,8 @@ export async function getServerSideProps( transformer: superjson, }); + await helpers.auth.get.prefetch(); + await helpers.settings.isCloud.prefetch(); return { diff --git a/apps/dokploy/pages/dashboard/settings/certificates.tsx b/apps/dokploy/pages/dashboard/settings/certificates.tsx index 488eb733..e64db687 100644 --- a/apps/dokploy/pages/dashboard/settings/certificates.tsx +++ b/apps/dokploy/pages/dashboard/settings/certificates.tsx @@ -49,7 +49,7 @@ export async function getServerSideProps( }, transformer: superjson, }); - + await helpers.auth.get.prefetch(); await helpers.settings.isCloud.prefetch(); return { diff --git a/apps/dokploy/pages/dashboard/settings/cluster.tsx b/apps/dokploy/pages/dashboard/settings/cluster.tsx index b7c7ed87..3320a9c3 100644 --- a/apps/dokploy/pages/dashboard/settings/cluster.tsx +++ b/apps/dokploy/pages/dashboard/settings/cluster.tsx @@ -1,9 +1,12 @@ import { ShowNodes } from "@/components/dashboard/settings/cluster/nodes/show-nodes"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { SettingsLayout } from "@/components/layouts/settings-layout"; +import { appRouter } from "@/server/api/root"; import { IS_CLOUD, validateRequest } from "@dokploy/server"; +import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext } from "next"; import React, { type ReactElement } from "react"; +import superjson from "superjson"; const Page = () => { return ( @@ -25,6 +28,7 @@ Page.getLayout = (page: ReactElement) => { export async function getServerSideProps( ctx: GetServerSidePropsContext<{ serviceId: string }>, ) { + const { req, res } = ctx; if (IS_CLOUD) { return { redirect: { @@ -42,8 +46,22 @@ export async function getServerSideProps( }, }; } + const helpers = createServerSideHelpers({ + router: appRouter, + ctx: { + req: req as any, + res: res as any, + db: null as any, + session: session, + user: user, + }, + transformer: superjson, + }); + await helpers.auth.get.prefetch(); return { - props: {}, + props: { + trpcState: helpers.dehydrate(), + }, }; } diff --git a/apps/dokploy/pages/dashboard/settings/destinations.tsx b/apps/dokploy/pages/dashboard/settings/destinations.tsx index 5e5c9c13..fdf91ca1 100644 --- a/apps/dokploy/pages/dashboard/settings/destinations.tsx +++ b/apps/dokploy/pages/dashboard/settings/destinations.tsx @@ -50,7 +50,7 @@ export async function getServerSideProps( }, transformer: superjson, }); - + await helpers.auth.get.prefetch(); await helpers.settings.isCloud.prefetch(); return { diff --git a/apps/dokploy/pages/dashboard/settings/git-providers.tsx b/apps/dokploy/pages/dashboard/settings/git-providers.tsx index 37144b56..b5862eb9 100644 --- a/apps/dokploy/pages/dashboard/settings/git-providers.tsx +++ b/apps/dokploy/pages/dashboard/settings/git-providers.tsx @@ -49,7 +49,7 @@ export async function getServerSideProps( }, transformer: superjson, }); - + await helpers.auth.get.prefetch(); try { await helpers.project.all.prefetch(); await helpers.settings.isCloud.prefetch(); diff --git a/apps/dokploy/pages/dashboard/settings/notifications.tsx b/apps/dokploy/pages/dashboard/settings/notifications.tsx index 2e3cf044..d783355e 100644 --- a/apps/dokploy/pages/dashboard/settings/notifications.tsx +++ b/apps/dokploy/pages/dashboard/settings/notifications.tsx @@ -50,7 +50,7 @@ export async function getServerSideProps( }, transformer: superjson, }); - + await helpers.auth.get.prefetch(); await helpers.settings.isCloud.prefetch(); return { diff --git a/apps/dokploy/pages/dashboard/settings/profile.tsx b/apps/dokploy/pages/dashboard/settings/profile.tsx index 140deeb6..afaf59a6 100644 --- a/apps/dokploy/pages/dashboard/settings/profile.tsx +++ b/apps/dokploy/pages/dashboard/settings/profile.tsx @@ -56,6 +56,13 @@ export async function getServerSideProps( }); await helpers.settings.isCloud.prefetch(); + await helpers.auth.get.prefetch(); + if (user?.rol === "user") { + await helpers.user.byAuthId.prefetch({ + authId: user.authId, + }); + } + if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/settings/registry.tsx b/apps/dokploy/pages/dashboard/settings/registry.tsx index 0e434b4e..16fded94 100644 --- a/apps/dokploy/pages/dashboard/settings/registry.tsx +++ b/apps/dokploy/pages/dashboard/settings/registry.tsx @@ -49,7 +49,7 @@ export async function getServerSideProps( }, transformer: superjson, }); - + await helpers.auth.get.prefetch(); await helpers.settings.isCloud.prefetch(); return { diff --git a/apps/dokploy/pages/dashboard/settings/server.tsx b/apps/dokploy/pages/dashboard/settings/server.tsx index f4c34974..4763114e 100644 --- a/apps/dokploy/pages/dashboard/settings/server.tsx +++ b/apps/dokploy/pages/dashboard/settings/server.tsx @@ -2,9 +2,12 @@ import { WebDomain } from "@/components/dashboard/settings/web-domain"; import { WebServer } from "@/components/dashboard/settings/web-server"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { SettingsLayout } from "@/components/layouts/settings-layout"; +import { appRouter } from "@/server/api/root"; import { IS_CLOUD, validateRequest } from "@dokploy/server"; +import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext } from "next"; import React, { type ReactElement } from "react"; +import superjson from "superjson"; const Page = () => { return ( @@ -27,6 +30,7 @@ Page.getLayout = (page: ReactElement) => { export async function getServerSideProps( ctx: GetServerSidePropsContext<{ serviceId: string }>, ) { + const { req, res } = ctx; if (IS_CLOUD) { return { redirect: { @@ -35,7 +39,7 @@ export async function getServerSideProps( }, }; } - const { user } = await validateRequest(ctx.req, ctx.res); + const { user, session } = await validateRequest(ctx.req, ctx.res); if (!user) { return { redirect: { @@ -53,7 +57,22 @@ export async function getServerSideProps( }; } + const helpers = createServerSideHelpers({ + router: appRouter, + ctx: { + req: req as any, + res: res as any, + db: null as any, + session: session, + user: user, + }, + transformer: superjson, + }); + await helpers.auth.get.prefetch(); + return { - props: {}, + props: { + trpcState: helpers.dehydrate(), + }, }; } diff --git a/apps/dokploy/pages/dashboard/settings/servers.tsx b/apps/dokploy/pages/dashboard/settings/servers.tsx index 58a90b79..a7c104a1 100644 --- a/apps/dokploy/pages/dashboard/settings/servers.tsx +++ b/apps/dokploy/pages/dashboard/settings/servers.tsx @@ -58,7 +58,7 @@ export async function getServerSideProps( }, transformer: superjson, }); - + await helpers.auth.get.prefetch(); await helpers.settings.isCloud.prefetch(); return { diff --git a/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx b/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx index 6a1ab1d9..55b97976 100644 --- a/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx +++ b/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx @@ -52,7 +52,6 @@ export async function getServerSideProps( try { await helpers.project.all.prefetch(); - const auth = await helpers.auth.get.fetch(); await helpers.settings.isCloud.prefetch(); diff --git a/apps/dokploy/pages/dashboard/settings/users.tsx b/apps/dokploy/pages/dashboard/settings/users.tsx index aa29e2a5..f8628459 100644 --- a/apps/dokploy/pages/dashboard/settings/users.tsx +++ b/apps/dokploy/pages/dashboard/settings/users.tsx @@ -50,7 +50,7 @@ export async function getServerSideProps( }, transformer: superjson, }); - + await helpers.auth.get.prefetch(); await helpers.settings.isCloud.prefetch(); return {