diff --git a/components/RouteCards.tsx b/components/RouteCards.tsx index d9f083a..d59f3df 100644 --- a/components/RouteCards.tsx +++ b/components/RouteCards.tsx @@ -69,31 +69,69 @@ export default function RouteCards({ routes }: { routes: Route[] }) { } export function EditRouteDialog({ route }: { route?: Route }) { - const form = useForm(); + const form = useForm({ + defaultValues: { + handler: route?.handle[0].handler, + upstreams: route?.handle[0].upstreams, + //hosts: route?.match[0].host, + } + }); + + let test: RouteHandle = { + handle: [ + { + handler: 'subroutes', + routes: [ + { + handle: [ + { + handler: 'reverse_proxy', + upstreams: [ + { + dial: 'localhost:8080' + } + ] + } + ] + } + ] + } + ], + + match: [ + { + host: [ + 'example.com' + ] + } + ] + } let onSubmit = ((data: any) => { - console.log(JSON.stringify(data)) + console.log('Original Route', JSON.stringify(route)) + console.log(data) }) - let targetRoute: Route = route as Route; return ( - +
( Handler - + )} + > - {route ? getRouteUpstreams(targetRoute)?.map((upstream, index) => ( + + {route ? getRouteUpstreams(route)?.map((upstream, index) => ( Upstream {index + 1} - + )} @@ -110,14 +148,14 @@ export function EditRouteDialog({ route }: { route?: Route }) { )) : <>} - {route ? getHosts(targetRoute)?.map((host, index) => ( + {route ? getHosts(route)?.map((host, index) => ( ( - Upstream {index + 1} + Host {index + 1} diff --git a/lib/types.ts b/lib/types.ts index 1549326..a00510d 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -4,8 +4,9 @@ interface Server { } interface Route { - match: Match[]; handle: Handle[]; + match: Match[]; + terminal?: boolean; } interface Match {