Skip to content
Snippets Groups Projects
Commit 9f6ffa07 authored by Jakub Lachór's avatar Jakub Lachór
Browse files

Move addition of providers from dialog to bottom of HC

parent af5dfd92
No related branches found
No related tags found
No related merge requests found
Pipeline #120215 passed
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "./shad/dialog";
import { Input } from "./shad/input"; import { Input } from "./shad/input";
import { useState } from "react"; import { useState } from "react";
import { Button } from "./shad/button"; import { Button } from "./shad/button";
interface ProviderAdditionDialogProps { interface ProviderAdditionProps {
isOpened: boolean;
onDialogOpenChange: (isOpened: boolean) => void;
onProviderSubmit: (provider: string) => void; onProviderSubmit: (provider: string) => void;
} }
const ProviderAdditionDialog: React.FC<ProviderAdditionDialogProps> = ({ const ProviderAddition: React.FC<ProviderAdditionProps> = ({
isOpened,
onDialogOpenChange,
onProviderSubmit onProviderSubmit
}) => { }) => {
const [providerValue, setProviderValue] = useState<string>(""); const [providerValue, setProviderValue] = useState<string>("");
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter" && isOpened) {
onProviderSubmit(providerValue);
}
};
return ( return (
<Dialog open={isOpened} onOpenChange={onDialogOpenChange}> <div className="flex flex-col justify left">
<DialogContent> <div className="font-semibold">Add Custom Node::</div>
<DialogHeader><DialogTitle>Add new address of provider</DialogTitle></DialogHeader> <div className="text-sm mb-2">Enter a custom Hive node URL.</div>
<div className="flex w-ful">
<Input <Input
onKeyDown={handleKeyDown}
value={providerValue} value={providerValue}
autoFocus={true} autoFocus={true}
className="focus:bg-white dark:focus:bg-gray-700" className="focus:bg-white dark:focus:bg-gray-700"
...@@ -41,10 +27,11 @@ const ProviderAdditionDialog: React.FC<ProviderAdditionDialogProps> = ({ ...@@ -41,10 +27,11 @@ const ProviderAdditionDialog: React.FC<ProviderAdditionDialogProps> = ({
data-testid="api-address-input" data-testid="api-address-input"
onChange={(e) => setProviderValue(e.target.value)} onChange={(e) => setProviderValue(e.target.value)}
/> />
<Button onClick={() => {onProviderSubmit(providerValue)}}>Submit</Button> <Button onClick={() => {onProviderSubmit(providerValue)}}>Add</Button>
</DialogContent> </div>
</Dialog> </div>
) )
}; };
export default ProviderAdditionDialog; export default ProviderAddition;
import { cn } from "./utils.ts"; import { cn } from "./utils.ts";
import { TScoredEndpoint } from "@hiveio/wax/vite"; import { TScoredEndpoint } from "@hiveio/wax/vite";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Loader2, Plus } from "lucide-react"; import { Loader2 } from "lucide-react";
import { Button } from "./shad/button"; import { Button } from "./shad/button";
import { Card } from "./shad/card"; import { Card } from "./shad/card";
import { Badge } from "./shad/badge"; import { Badge } from "./shad/badge";
import ProviderCard from "./ProviderCard"; import ProviderCard from "./ProviderCard";
import ProviderAdditionDialog from "./ProviderAdditionDialog"; import ProviderAdditionDialog from "./ProviderAddition.tsx";
import ValidationErrorDialog from "./ValidationErrorDialog"; import ValidationErrorDialog from "./ValidationErrorDialog";
import { ValidationErrorDetails, ApiChecker } from "./index.ts"; import { ValidationErrorDetails, ApiChecker } from "./index.ts";
import { HealthCheckerService } from "./index.ts"; import { HealthCheckerService } from "./index.ts";
...@@ -40,13 +40,11 @@ const HealthCheckerComponent: React.FC<HealthCheckerComponentProps> = ({ ...@@ -40,13 +40,11 @@ const HealthCheckerComponent: React.FC<HealthCheckerComponentProps> = ({
const [providers, setProviders] = useState<string[] | undefined>(undefined); const [providers, setProviders] = useState<string[] | undefined>(undefined);
const [failedChecksByProvider, setFailedChecksByProvider] = useState<Map<string, ValidationErrorDetails[]>>(new Map()); const [failedChecksByProvider, setFailedChecksByProvider] = useState<Map<string, ValidationErrorDetails[]>>(new Map());
const [isProviderAdditionDialogOpened, setIsProviderAdditionDialogOpened] = useState<boolean>(false);
const [isValidationErrorDialogOpened, setIsValidationErrorDialogOpened] = useState<boolean>(false); const [isValidationErrorDialogOpened, setIsValidationErrorDialogOpened] = useState<boolean>(false);
const [selectedValidator, setSelectedValidator] = useState<ValidationErrorDetails | undefined>(undefined); const [selectedValidator, setSelectedValidator] = useState<ValidationErrorDetails | undefined>(undefined);
const handleAdditionOfProvider = (provider: string) => { const handleAdditionOfProvider = (provider: string) => {
addProvider(provider); addProvider(provider);
setIsProviderAdditionDialogOpened(false);
} }
const selectValidator = (providerName: string, checkTitle: string) => { const selectValidator = (providerName: string, checkTitle: string) => {
...@@ -137,10 +135,7 @@ const HealthCheckerComponent: React.FC<HealthCheckerComponentProps> = ({ ...@@ -137,10 +135,7 @@ const HealthCheckerComponent: React.FC<HealthCheckerComponentProps> = ({
<Button className="row-start-4 lg:row-start-2 row-span-1 col-span-full lg:col-span-1 lg:col-end-5" onClick={() => {resetProviders()}}>Restore default API server set</Button> <Button className="row-start-4 lg:row-start-2 row-span-1 col-span-full lg:col-span-1 lg:col-end-5" onClick={() => {resetProviders()}}>Restore default API server set</Button>
</Card> </Card>
{renderProviders()} {renderProviders()}
<Button onClick={() => {setIsProviderAdditionDialogOpened(true)}} className="w-full hover:bg-primary"><Plus /></Button>
<ProviderAdditionDialog <ProviderAdditionDialog
isOpened={isProviderAdditionDialogOpened}
onDialogOpenChange={setIsProviderAdditionDialogOpened}
onProviderSubmit={handleAdditionOfProvider} onProviderSubmit={handleAdditionOfProvider}
/> />
<ValidationErrorDialog <ValidationErrorDialog
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment