-
+
+
)
diff --git a/components/Error.tsx b/components/Error.tsx
index 620c6cc..5e748f8 100644
--- a/components/Error.tsx
+++ b/components/Error.tsx
@@ -11,15 +11,17 @@ export default function Error() {
return (
-
-
- Error
- There was an error fetching your data
-
-
-
-
-
+
+
+
+ Error
+ There was an error fetching your data
+
+
+
+
+
+
)
}
\ No newline at end of file
diff --git a/components/Header.tsx b/components/Header.tsx
new file mode 100644
index 0000000..5530ea9
--- /dev/null
+++ b/components/Header.tsx
@@ -0,0 +1,68 @@
+"use client"
+
+import { CardTitle, Card, CardDescription, CardHeader, CardContent, CardFooter } from '@/components/ui/card';
+import RouteCards from '@/components/RouteCards';
+import { Button } from '@/components/ui/button';
+import { useState } from 'react';
+import { useRoutes } from '@/lib/clientActions';
+import Error from './Error';
+import Loading from './Loading';
+import { RouteDialog } from './RouteDialog';
+
+export default function Header() {
+
+ const { data: routes, error, isLoading } = useRoutes();
+ let routesMap: Route[] = routes as Route[];
+
+ const [route, setRoute] = useState
();
+ const [open, setOpen] = useState(false);
+
+ return (
+ <>
+ {route && }
+
+
+
+
+ Active Routes
+ Amount of configured routes
+
+
+
+
+
+
+
+
+
+
+ >
+ )
+}
\ No newline at end of file
diff --git a/components/Loading.tsx b/components/Loading.tsx
index dce6e38..5a8c074 100644
--- a/components/Loading.tsx
+++ b/components/Loading.tsx
@@ -3,8 +3,10 @@ import Image from "next/image";
export default function Loading() {
return (
)
}
\ No newline at end of file
diff --git a/components/RouteCards.tsx b/components/RouteCards.tsx
index 18a04c8..b7f680c 100644
--- a/components/RouteCards.tsx
+++ b/components/RouteCards.tsx
@@ -2,18 +2,24 @@
import { Button } from '@/components/ui/button';
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "./ui/card";
-import { getHosts, getRouteUpstreams } from '@/lib/utils';
+import { getHandler, getHosts, getRouteUpstreams } from '@/lib/utils';
import { toast } from './ui/use-toast';
import React, { useState } from 'react';
import useSWRMutation from 'swr/mutation';
-import { deleteRoute } from '@/lib/clientActions';
+import { deleteRoute, useRoutes } from '@/lib/clientActions';
import { RouteDialog } from './RouteDialog';
+import Error from './Error';
+import Loading from './Loading';
-export default function RouteCards({ routes }: { routes: Route[] }) {
+export default function RouteCards() {
+
+ const { data: routes, error, isLoading } = useRoutes();
+ let routesMap: Route[] = routes as Route[];
const [route, setRoute] = useState();
const [open, setOpen] = useState(false);
+
const { trigger: handleDelete } = useSWRMutation("/api/caddy/routes", deleteRoute, {
onError: () => {
return toast({
@@ -36,29 +42,44 @@ export default function RouteCards({ routes }: { routes: Route[] }) {
setRoute(route);
}
+
+ if (error) return
+ if (isLoading) return
+
+
return (
<>
- {route && }
+ {route && }
{
- routes.map((route, index) => (
-
-
+ routesMap.map((route, index) => (
+
+
{getHosts(route)!.values().next().value}
{getHosts(route)!.map((route => {route} CardDescription>))}
-
- Tunneling to
-
- {getRouteUpstreams(route)?.map((upstream => upstream.dial))}
+
+
+
+ Type
+
+
{getHandler(route)}
+
+
+
+ Tunneling to
+
+
{getRouteUpstreams(route)?.map((upstream => upstream.dial))}
+
+
-
{ handleDelete(route) }}>Delete