Skip to content

Commit

Permalink
feat: Add a text input for the user to enter the url
Browse files Browse the repository at this point in the history
  • Loading branch information
PintoGideon committed Jun 13, 2024
1 parent ad269bf commit 55d72fd
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/components/Store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -137,6 +139,7 @@ const Store = () => {

return data;
} catch (error) {
console.log("Error", error);
// biome-ignore lint/complexity/noUselessCatch: <explanation>
throw error;
}
Expand All @@ -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);
}
},
});

Expand Down Expand Up @@ -196,10 +201,12 @@ const Store = () => {
variant="small"
isOpen={enterAdminCred}
onClose={() => setEnterAdminCred(!enterAdminCred)}
aria-label="Enter admin credentials"
>
<Form isWidthLimited>
<FormGroup label="Enter a username" isRequired>
<TextInput
id="username"
isRequired
type="text"
value={username}
Expand All @@ -210,6 +217,7 @@ const Store = () => {
</FormGroup>
<FormGroup label="Enter a password" isRequired>
<TextInput
id="password"
isRequired
type="password"
value={password}
Expand All @@ -223,12 +231,28 @@ const Store = () => {
}}
/>
</FormGroup>

<FormGroup
label="Enter the url to your chris-admin dashboard"
isRequired
>
<TextInput
id="url"
isRequired
type="url"
value={url}
onChange={(_event, value: string) => {
setUrl(value);
}}
placeholder="eg: http://localhost:8000/chris-admin/api/v1/"
/>
</FormGroup>
<ActionGroup>
<Button
onClick={() => {
handleSave();
}}
isDisabled={!(username && password)}
isDisabled={!(username && password && url)}
variant="primary"
icon={handleInstallMutation.isPending && <Spin />}
>
Expand Down

0 comments on commit 55d72fd

Please sign in to comment.