From ba3834b95ffa3e365deb92c6d8ca5f6805157177 Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Fri, 28 Feb 2025 10:50:02 +0100 Subject: [PATCH] fix(cloud): Improve cloud URL configuration and adoption flow - Update error handling in cloud URL configuration RPC method - Modify cloud adoption route to support dynamic cloud URLs - Remove hardcoded default cloud URLs in device access settings - Refactor cloud adoption click handler to be more flexible --- jsonrpc.go | 2 +- ui/src/main.tsx | 2 +- .../devices.$id.settings.access._index.tsx | 50 ++++++++++--------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/jsonrpc.go b/jsonrpc.go index 86db0ad..4928454 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -758,7 +758,7 @@ func rpcSetCloudUrl(apiUrl string, appUrl string) (bool, error) { config.CloudAppURL = appUrl if err := SaveConfig(); err != nil { - return false, err + return false, fmt.Errorf("failed to save config: %w", err) } return true, nil diff --git a/ui/src/main.tsx b/ui/src/main.tsx index 09a7172..d20f018 100644 --- a/ui/src/main.tsx +++ b/ui/src/main.tsx @@ -180,8 +180,8 @@ if (isOnDevice) { { path: "/adopt", element: , - errorElement: , loader: AdoptRoute.loader, + errorElement: , }, ]); } else { diff --git a/ui/src/routes/devices.$id.settings.access._index.tsx b/ui/src/routes/devices.$id.settings.access._index.tsx index 5074273..0f75526 100644 --- a/ui/src/routes/devices.$id.settings.access._index.tsx +++ b/ui/src/routes/devices.$id.settings.access._index.tsx @@ -53,8 +53,8 @@ export default function SettingsAccessIndexRoute() { const [isAdopted, setAdopted] = useState(false); const [deviceId, setDeviceId] = useState(null); - const [cloudApiUrl, setCloudApiUrl] = useState("https://api.jetkvm.com"); - const [cloudAppUrl, setCloudAppUrl] = useState("https://app.jetkvm.com"); + const [cloudApiUrl, setCloudApiUrl] = useState(""); + const [cloudAppUrl, setCloudAppUrl] = useState(""); // Use a simple string identifier for the selected provider const [selectedProvider, setSelectedProvider] = useState("jetkvm"); @@ -95,30 +95,34 @@ export default function SettingsAccessIndexRoute() { }); }; - const onCloudAdoptClick = useCallback(() => { - if (!deviceId) { - notifications.error("No device ID available"); - return; - } - - send("setCloudUrl", { apiUrl: cloudApiUrl, appUrl: cloudAppUrl }, resp => { - if ("error" in resp) { - notifications.error( - `Failed to update cloud URL: ${resp.error.data || "Unknown error"}`, - ); + const onCloudAdoptClick = useCallback( + (cloudApiUrl: string, cloudAppUrl: string) => { + if (!deviceId) { + notifications.error("No device ID available"); return; } - getCloudState(); + send("setCloudUrl", { apiUrl: cloudApiUrl, appUrl: cloudAppUrl }, resp => { + if ("error" in resp) { + notifications.error( + `Failed to update cloud URL: ${resp.error.data || "Unknown error"}`, + ); + return; + } - const returnTo = new URL(window.location.href); - returnTo.pathname = "/adopt"; - returnTo.search = ""; - returnTo.hash = ""; - window.location.href = - cloudAppUrl + "/signup?deviceId=" + deviceId + `&returnTo=${returnTo.toString()}`; - }); - }, [deviceId, getCloudState, send, cloudApiUrl, cloudAppUrl]); + const returnTo = new URL(window.location.href); + returnTo.pathname = "/adopt"; + returnTo.search = ""; + returnTo.hash = ""; + window.location.href = + cloudAppUrl + + "/signup?deviceId=" + + deviceId + + `&returnTo=${returnTo.toString()}`; + }); + }, + [deviceId, send], + ); // Handle provider selection change const handleProviderChange = (value: string) => { @@ -297,7 +301,7 @@ export default function SettingsAccessIndexRoute() { {!isAdopted ? (