From b9bec022b279bf83bb82d06466111c5af6c836f3 Mon Sep 17 00:00:00 2001 From: brian Date: Sat, 18 Nov 2023 09:18:31 -0500 Subject: [PATCH] Small addons --- components/EditRoute.tsx | 0 components/Navbar.tsx | 5 -- components/RouteCards.tsx | 126 +------------------------------------- 3 files changed, 3 insertions(+), 128 deletions(-) delete mode 100644 components/EditRoute.tsx diff --git a/components/EditRoute.tsx b/components/EditRoute.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/components/Navbar.tsx b/components/Navbar.tsx index e71c2bc..7a5db3e 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -1,20 +1,15 @@ "use client" import * as React from "react" -import Link from "next/link" -import { cn } from "@/lib/utils" import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, - NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, - navigationMenuTriggerStyle, } from "@/components/ui/navigation-menu" import ListItem from "./ListItem" -import { Avatar, AvatarFallback } from "./ui/avatar" export function Navbar() { return ( diff --git a/components/RouteCards.tsx b/components/RouteCards.tsx index fe3eb50..f18d4bf 100644 --- a/components/RouteCards.tsx +++ b/components/RouteCards.tsx @@ -6,14 +6,8 @@ import { getHosts, getRouteUpstreams } from '@/lib/utils'; import { toast } from './ui/use-toast'; import React, { useState } from 'react'; import useSWRMutation from 'swr/mutation'; -import { deleteRoute, updateRoute } from '@/lib/clientActions'; -import { Dialog, DialogContent, DialogHeader } from './ui/dialog'; -import { DialogDescription, DialogTitle } from '@radix-ui/react-dialog'; -import { Form, FormControl, FormField, FormItem, FormLabel } from './ui/form'; -import { useFieldArray, useForm } from 'react-hook-form'; -import { Input } from './ui/input'; -import { get, set } from 'lodash'; -import { getRoutes } from '@/lib/serverActions'; +import { deleteRoute } from '@/lib/clientActions'; +import { RouteDialog } from './RouteDialog'; export default function RouteCards({ routes }: { routes: Route[] }) { @@ -43,7 +37,7 @@ export default function RouteCards({ routes }: { routes: Route[] }) { return ( <> - {route && } + {route && } { routes.map((route, index) => (
@@ -68,118 +62,4 @@ export default function RouteCards({ routes }: { routes: Route[] }) { ))} ) -} - -export function EditRouteDialog({ route }: { route: Route }) { - let index = getHosts(route).indexOf(route.match[0].host[0]); - - const [modifiedRoute, setRoute] = useState(route); - const { trigger: pushUpdate } = useSWRMutation(`/api/caddy/routes/${index}`, updateRoute, { - onError: () => { - return toast({ - title: "Error", - description: "There was an error updating the route", - variant: "destructive" - }); - }, - onSuccess: () => { - toast({ - title: "Success", - description: "Route updated successfully!", - variant: "success" - }); - } - }); - - let validHosts: any[] = getHosts(route); - let validUpstreams: any[] = getRouteUpstreams(route).map((upstream) => upstream.dial); - - const form = useForm({ - values: { - handler: route.handle[0].routes[0].handle[0].handler, - upstreams: validUpstreams, - hosts: validHosts, - } - }); - - const { fields: upstreams, append: appendUpstreams } = useFieldArray({ - control: form.control, - name: "upstreams", - }) - - const { fields: hosts, append: appendHosts } = useFieldArray({ - control: form.control, - name: "hosts", - }) - - let onSubmit = ((data: any) => { - pushUpdate(modifiedRoute); - }) - - - let handleChange = (value: any, path: any) => { - let updatedRoute = set(modifiedRoute, path, value.target.value); - setRoute(updatedRoute); - form.setValue(value.target.name, value.target.value) - } - - - return ( - - -
- - ( - - Handler - - handleChange(value, `handle[0].handler`)} /> - - - )} - - > - - {upstreams.map((upstream, index) => ( - ( - - Upstream {index + 1} - - handleChange(value, `handle[0].routes[0].handle[0].upstreams[${index}].dial`)} /> - - - )} - /> - ))} - - {hosts.map((host, index) => ( - ( - - Host {index + 1} - - handleChange(value, `match[0].host[${index}]`)} /> - - - )} - /> - ))} - - - - - -
-
- ) } \ No newline at end of file