|
1 | | -import { validateRequest } from "@dokploy/server/lib/auth"; |
2 | | -import { hasPermission } from "@dokploy/server/services/permission"; |
3 | | -import { Rocket } from "lucide-react"; |
4 | 1 | import type { GetServerSidePropsContext } from "next"; |
5 | | -import { useRouter } from "next/router"; |
6 | | -import type { ReactElement } from "react"; |
7 | | -import { ShowDeploymentsTable } from "@/components/dashboard/deployments/show-deployments-table"; |
8 | | -import { ShowQueueTable } from "@/components/dashboard/deployments/show-queue-table"; |
9 | | -import { DashboardLayout } from "@/components/layouts/dashboard-layout"; |
10 | | -import { |
11 | | - Card, |
12 | | - CardDescription, |
13 | | - CardHeader, |
14 | | - CardTitle, |
15 | | -} from "@/components/ui/card"; |
16 | | -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
17 | 2 |
|
18 | | -const TAB_VALUES = ["deployments", "queue"] as const; |
19 | | -type TabValue = (typeof TAB_VALUES)[number]; |
20 | | - |
21 | | -function isValidTab(t: string): t is TabValue { |
22 | | - return TAB_VALUES.includes(t as TabValue); |
23 | | -} |
24 | | - |
25 | | -function DeploymentsPage() { |
26 | | - const router = useRouter(); |
27 | | - const tab = |
28 | | - router.query.tab && isValidTab(router.query.tab as string) |
29 | | - ? (router.query.tab as TabValue) |
30 | | - : "deployments"; |
31 | | - |
32 | | - const setTab = (value: string) => { |
33 | | - if (!isValidTab(value)) return; |
34 | | - router.replace( |
35 | | - { pathname: "/dashboard/deployments", query: { tab: value } }, |
36 | | - undefined, |
37 | | - { shallow: true }, |
38 | | - ); |
39 | | - }; |
40 | | - |
41 | | - return ( |
42 | | - <div className="w-full"> |
43 | | - <Card className="h-full bg-sidebar p-2.5 rounded-xl min-h-[45vh]"> |
44 | | - <div className="rounded-xl bg-background shadow-md h-full"> |
45 | | - <CardHeader> |
46 | | - <div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between"> |
47 | | - <div> |
48 | | - <CardTitle className="text-xl font-bold flex items-center gap-2"> |
49 | | - <Rocket className="size-5" /> |
50 | | - Deployments |
51 | | - </CardTitle> |
52 | | - <CardDescription> |
53 | | - All application and compose deployments in one place. |
54 | | - </CardDescription> |
55 | | - </div> |
56 | | - </div> |
57 | | - <Tabs value={tab} onValueChange={setTab} className="w-full min-w-0"> |
58 | | - <TabsList className="mt-2"> |
59 | | - <TabsTrigger value="deployments">Deployments</TabsTrigger> |
60 | | - <TabsTrigger value="queue">Queue</TabsTrigger> |
61 | | - </TabsList> |
62 | | - <TabsContent value="deployments" className="mt-0 min-w-0 pt-4"> |
63 | | - <ShowDeploymentsTable /> |
64 | | - </TabsContent> |
65 | | - <TabsContent value="queue" className="mt-0 pt-4"> |
66 | | - <ShowQueueTable /> |
67 | | - </TabsContent> |
68 | | - </Tabs> |
69 | | - </CardHeader> |
70 | | - </div> |
71 | | - </Card> |
72 | | - </div> |
73 | | - ); |
| 3 | +export default function DeploymentsRedirect() { |
| 4 | + return null; |
74 | 5 | } |
75 | 6 |
|
76 | | -export default DeploymentsPage; |
77 | | - |
78 | | -DeploymentsPage.getLayout = (page: ReactElement) => { |
79 | | - return <DashboardLayout>{page}</DashboardLayout>; |
80 | | -}; |
81 | | - |
82 | 7 | export async function getServerSideProps(ctx: GetServerSidePropsContext) { |
83 | | - const { user, session } = await validateRequest(ctx.req); |
84 | | - if (!user) { |
85 | | - return { |
86 | | - redirect: { |
87 | | - permanent: false, |
88 | | - destination: "/", |
89 | | - }, |
90 | | - }; |
91 | | - } |
92 | | - |
93 | | - const canView = await hasPermission( |
94 | | - { |
95 | | - user: { id: user.id }, |
96 | | - session: { activeOrganizationId: session?.activeOrganizationId || "" }, |
97 | | - }, |
98 | | - { deployment: ["read"] }, |
99 | | - ); |
100 | | - |
101 | | - if (!canView) { |
102 | | - return { |
103 | | - redirect: { |
104 | | - permanent: false, |
105 | | - destination: "/dashboard/home", |
106 | | - }, |
107 | | - }; |
108 | | - } |
| 8 | + const destination = |
| 9 | + ctx.query.tab === "queue" |
| 10 | + ? "/dashboard/overview?tab=deployments&subtab=queue" |
| 11 | + : "/dashboard/overview?tab=deployments"; |
109 | 12 |
|
110 | 13 | return { |
111 | | - props: {}, |
| 14 | + redirect: { |
| 15 | + permanent: false, |
| 16 | + destination, |
| 17 | + }, |
112 | 18 | }; |
113 | 19 | } |
0 commit comments