import { ShowDockerLogs } from "@/components/dashboard/application/logs/show"; import { DockerMonitoring } from "@/components/dashboard/monitoring/docker/show"; import { ShowAdvancedPostgres } from "@/components/dashboard/postgres/advanced/show-postgres-advanced-settings"; import { ShowBackupPostgres } from "@/components/dashboard/postgres/backups/show-backup-postgres"; import { DeletePostgres } from "@/components/dashboard/postgres/delete-postgres"; import { ShowPostgresEnvironment } from "@/components/dashboard/postgres/environment/show-postgres-environment"; import { ShowExternalPostgresCredentials } from "@/components/dashboard/postgres/general/show-external-postgres-credentials"; import { ShowGeneralPostgres } from "@/components/dashboard/postgres/general/show-general-postgres"; import { ShowInternalPostgresCredentials } from "@/components/dashboard/postgres/general/show-internal-postgres-credentials"; import { UpdatePostgres } from "@/components/dashboard/postgres/update-postgres"; import { PostgresqlIcon } from "@/components/icons/data-tools-icons"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { ProjectLayout } from "@/components/layouts/project-layout"; import { StatusTooltip } from "@/components/shared/status-tooltip"; import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, } from "@/components/ui/breadcrumb"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { appRouter } from "@/server/api/root"; import { validateRequest } from "@/server/auth/auth"; import { api } from "@/utils/api"; import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext, InferGetServerSidePropsType, } from "next"; import Link from "next/link"; import { useRouter } from "next/router"; import React, { useState, type ReactElement } from "react"; import superjson from "superjson"; type TabState = "projects" | "monitoring" | "settings" | "backups" | "advanced"; const Postgresql = ( props: InferGetServerSidePropsType, ) => { const { postgresId, activeTab } = props; const router = useRouter(); const { projectId } = router.query; const [tab, setSab] = useState(activeTab); const { data } = api.postgres.one.useQuery({ postgresId }); const { data: auth } = api.auth.get.useQuery(); const { data: user } = api.user.byAuthId.useQuery( { authId: auth?.id || "", }, { enabled: !!auth?.id && auth?.rol === "user", }, ); return (
Projects {data?.project.name} {data?.name}

{data?.name}

{data?.appName}
{data?.description && (

{data?.description}

)}
{ setSab(e as TabState); const newPath = `/dashboard/project/${projectId}/services/postgres/${postgresId}?tab=${e}`; router.push(newPath, undefined, { shallow: true }); }} >
General Environment Monitoring Backups Logs Advanced
{(auth?.rol === "admin" || user?.canDeleteServices) && ( )}
); }; export default Postgresql; Postgresql.getLayout = (page: ReactElement) => { return {page}; }; export async function getServerSideProps( ctx: GetServerSidePropsContext<{ postgresId: string; activeTab: TabState }>, ) { const { query, params, req, res } = ctx; const activeTab = query.tab; const { user, session } = await validateRequest(req, res); if (!user) { return { redirect: { permanent: true, destination: "/", }, }; } // Fetch data from external API const helpers = createServerSideHelpers({ router: appRouter, ctx: { req: req as any, res: res as any, db: null as any, session: session, user: user, }, transformer: superjson, }); if (typeof params?.postgresId === "string") { try { await helpers.postgres.one.fetch({ postgresId: params?.postgresId, }); return { props: { trpcState: helpers.dehydrate(), postgresId: params?.postgresId, activeTab: (activeTab || "general") as TabState, }, }; } catch (error) { return { redirect: { permanent: false, destination: "/dashboard/projects", }, }; } } return { redirect: { permanent: false, destination: "/", }, }; }