From 55d72fdc4d18bf9dfba3144e8504f4b391cee55a Mon Sep 17 00:00:00 2001 From: PintoGideon Date: Thu, 13 Jun 2024 15:55:10 -0400 Subject: [PATCH] feat: Add a text input for the user to enter the url --- src/components/Store/index.tsx | 38 +++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/components/Store/index.tsx b/src/components/Store/index.tsx index b1bd6822..83a7383b 100644 --- a/src/components/Store/index.tsx +++ b/src/components/Store/index.tsx @@ -48,6 +48,7 @@ const Store = () => { const [enterAdminCred, setEnterAdminCred] = useState(false); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); + const [url, setUrl] = useState(""); useEffect(() => { document.title = "Store Catalog"; @@ -109,9 +110,10 @@ const Store = () => { }); const handleInstall = async (selectedPlugin: Plugin) => { - const url = "http://localhost:8000/chris-admin/api/v1/"; - const credentials = btoa(`${username}:${password}`); // Base64 encoding for Basic Auth - + if (!url) { + throw new Error("Please provide a link to your chris-admin url"); + } + const credentials = btoa(`${username.trim()}:${password.trim()}`); // Base64 encoding for Basic Auth const pluginData = { compute_names: "host", name: selectedPlugin.data.name, @@ -137,6 +139,7 @@ const Store = () => { return data; } catch (error) { + console.log("Error", error); // biome-ignore lint/complexity/noUselessCatch: throw error; } @@ -145,9 +148,11 @@ const Store = () => { const handleInstallMutation = useMutation({ mutationFn: async (selectedPlugin: Plugin) => await handleInstall(selectedPlugin), - onSettled: () => { - setInstallingPlugin(undefined); - setEnterAdminCred(false); + onSettled: (error) => { + if (!isEmpty(error)) { + setInstallingPlugin(undefined); + setEnterAdminCred(false); + } }, }); @@ -196,10 +201,12 @@ const Store = () => { variant="small" isOpen={enterAdminCred} onClose={() => setEnterAdminCred(!enterAdminCred)} + aria-label="Enter admin credentials" >
{ { }} /> + + + { + setUrl(value); + }} + placeholder="eg: http://localhost:8000/chris-admin/api/v1/" + /> +