diff --git a/src/app/configuration/layout.tsx b/src/app/[orgId]/layout.tsx similarity index 100% rename from src/app/configuration/layout.tsx rename to src/app/[orgId]/layout.tsx diff --git a/src/app/configuration/page.tsx b/src/app/[orgId]/page.tsx similarity index 100% rename from src/app/configuration/page.tsx rename to src/app/[orgId]/page.tsx diff --git a/src/app/configuration/resources/[resourceId]/account/page.tsx b/src/app/[orgId]/resources/[resourceId]/account/page.tsx similarity index 100% rename from src/app/configuration/resources/[resourceId]/account/page.tsx rename to src/app/[orgId]/resources/[resourceId]/account/page.tsx diff --git a/src/app/configuration/resources/[resourceId]/appearance/page.tsx b/src/app/[orgId]/resources/[resourceId]/appearance/page.tsx similarity index 100% rename from src/app/configuration/resources/[resourceId]/appearance/page.tsx rename to src/app/[orgId]/resources/[resourceId]/appearance/page.tsx diff --git a/src/app/configuration/resources/[resourceId]/display/page.tsx b/src/app/[orgId]/resources/[resourceId]/display/page.tsx similarity index 100% rename from src/app/configuration/resources/[resourceId]/display/page.tsx rename to src/app/[orgId]/resources/[resourceId]/display/page.tsx diff --git a/src/app/configuration/resources/[resourceId]/layout.tsx b/src/app/[orgId]/resources/[resourceId]/layout.tsx similarity index 100% rename from src/app/configuration/resources/[resourceId]/layout.tsx rename to src/app/[orgId]/resources/[resourceId]/layout.tsx diff --git a/src/app/configuration/resources/[resourceId]/notifications/page.tsx b/src/app/[orgId]/resources/[resourceId]/notifications/page.tsx similarity index 100% rename from src/app/configuration/resources/[resourceId]/notifications/page.tsx rename to src/app/[orgId]/resources/[resourceId]/notifications/page.tsx diff --git a/src/app/configuration/resources/[resourceId]/page.tsx b/src/app/[orgId]/resources/[resourceId]/page.tsx similarity index 100% rename from src/app/configuration/resources/[resourceId]/page.tsx rename to src/app/[orgId]/resources/[resourceId]/page.tsx diff --git a/src/app/configuration/resources/page.tsx b/src/app/[orgId]/resources/page.tsx similarity index 100% rename from src/app/configuration/resources/page.tsx rename to src/app/[orgId]/resources/page.tsx diff --git a/src/app/configuration/sites/[siteId]/appearance/page.tsx b/src/app/[orgId]/sites/[siteId]/appearance/page.tsx similarity index 100% rename from src/app/configuration/sites/[siteId]/appearance/page.tsx rename to src/app/[orgId]/sites/[siteId]/appearance/page.tsx diff --git a/src/app/configuration/sites/[siteId]/components/create-site.tsx b/src/app/[orgId]/sites/[siteId]/components/create-site.tsx similarity index 81% rename from src/app/configuration/sites/[siteId]/components/create-site.tsx rename to src/app/[orgId]/sites/[siteId]/components/create-site.tsx index 3b9efc62..435aa405 100644 --- a/src/app/configuration/sites/[siteId]/components/create-site.tsx +++ b/src/app/[orgId]/sites/[siteId]/components/create-site.tsx @@ -32,8 +32,9 @@ import { PopoverTrigger, } from "@/components/ui/popover" import { generateKeypair } from "./wireguard-config"; -import { NewtConfig } from "./newt-config"; -import { useState } from "react" +import React, { useState, useEffect } from "react"; +import { api } from "@/api"; +import { AxiosResponse } from "axios" const method = [ { label: "Wireguard", value: "wg" }, @@ -63,13 +64,23 @@ const defaultValues: Partial = { export function CreateSiteForm() { const [methodValue, setMethodValue] = useState("wg"); + const [keypair, setKeypair] = useState<{ publicKey: string; privateKey: string } | null>(null); + const [isLoading, setIsLoading] = useState(true); const form = useForm({ resolver: zodResolver(accountFormSchema), defaultValues, }); - function onSubmit(data: AccountFormValues) { + useEffect(() => { + if (typeof window !== "undefined") { + const generatedKeypair = generateKeypair(); + setKeypair(generatedKeypair); + setIsLoading(false); + } + }, []); + + async function onSubmit(data: AccountFormValues) { toast({ title: "You submitted the following values:", description: ( @@ -78,11 +89,23 @@ export function CreateSiteForm() { ), }); + // const res = await api + // .post>(`/org/:orgId/site/:siteId/resource`, { + // email, + // password, + // }) + // .catch((e) => { + // console.error(e); + // setError( + // e.response?.data?.message || + // "An error occurred while logging in", + // ); + // }); + } - const keypair = generateKeypair(); - - const config = `[Interface] + const wgConfig = keypair + ? `[Interface] Address = 10.0.0.2/24 ListenPort = 51820 PrivateKey = ${keypair.privateKey} @@ -91,8 +114,11 @@ export function CreateSiteForm() { PublicKey = ${keypair.publicKey} AllowedIPs = 0.0.0.0/0, ::/0 Endpoint = myserver.dyndns.org:51820 - PersistentKeepalive = 5`; + PersistentKeepalive = 5` + : ""; + const newtConfig = `curl -fsSL https://get.docker.com -o get-docker.sh +sh get-docker.sh`; return ( <> @@ -178,12 +204,20 @@ export function CreateSiteForm() { )} /> + {methodValue === "wg" && !isLoading ? ( +
+                    {wgConfig}
+                
+ ) : methodValue === "wg" && isLoading ? ( +

Loading WireGuard configuration...

+ ) : ( +
+                {newtConfig}
+              
+ )} - {methodValue === "wg" ?
-                {config}
-            
: } ); } diff --git a/src/app/configuration/sites/[siteId]/components/newt-config.tsx b/src/app/[orgId]/sites/[siteId]/components/newt-config.tsx similarity index 100% rename from src/app/configuration/sites/[siteId]/components/newt-config.tsx rename to src/app/[orgId]/sites/[siteId]/components/newt-config.tsx diff --git a/src/app/configuration/sites/[siteId]/components/wireguard-config.ts b/src/app/[orgId]/sites/[siteId]/components/wireguard-config.ts similarity index 100% rename from src/app/configuration/sites/[siteId]/components/wireguard-config.ts rename to src/app/[orgId]/sites/[siteId]/components/wireguard-config.ts diff --git a/src/app/configuration/sites/[siteId]/display/page.tsx b/src/app/[orgId]/sites/[siteId]/display/page.tsx similarity index 100% rename from src/app/configuration/sites/[siteId]/display/page.tsx rename to src/app/[orgId]/sites/[siteId]/display/page.tsx diff --git a/src/app/configuration/sites/[siteId]/layout.tsx b/src/app/[orgId]/sites/[siteId]/layout.tsx similarity index 100% rename from src/app/configuration/sites/[siteId]/layout.tsx rename to src/app/[orgId]/sites/[siteId]/layout.tsx diff --git a/src/app/configuration/sites/[siteId]/notifications/page.tsx b/src/app/[orgId]/sites/[siteId]/notifications/page.tsx similarity index 100% rename from src/app/configuration/sites/[siteId]/notifications/page.tsx rename to src/app/[orgId]/sites/[siteId]/notifications/page.tsx diff --git a/src/app/configuration/sites/[siteId]/page.tsx b/src/app/[orgId]/sites/[siteId]/page.tsx similarity index 100% rename from src/app/configuration/sites/[siteId]/page.tsx rename to src/app/[orgId]/sites/[siteId]/page.tsx diff --git a/src/app/configuration/sites/page.tsx b/src/app/[orgId]/sites/page.tsx similarity index 100% rename from src/app/configuration/sites/page.tsx rename to src/app/[orgId]/sites/page.tsx