2020-08-31 18:26:25 +00:00
|
|
|
import React, { useState, FormEvent, useEffect, useContext } from "react";
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Form,
|
|
|
|
Select,
|
|
|
|
SelectVariant,
|
|
|
|
SelectOption,
|
|
|
|
} from "@patternfly/react-core";
|
2020-09-03 19:25:05 +00:00
|
|
|
|
2020-08-31 18:26:25 +00:00
|
|
|
import { HttpClientContext } from "../../http-service/HttpClientContext";
|
|
|
|
import { sortProvider } from "../../util";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { ServerInfoRepresentation } from "../models/server-info";
|
|
|
|
import { ClientRepresentation } from "../models/client-model";
|
|
|
|
import { ClientDescription } from "../ClientDescription";
|
2020-08-31 18:26:25 +00:00
|
|
|
|
|
|
|
type Step1Props = {
|
|
|
|
onChange: (value: string, event: FormEvent<HTMLInputElement>) => void;
|
|
|
|
client: ClientRepresentation;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Step1 = ({ client, onChange }: Step1Props) => {
|
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
|
|
|
|
const [providers, setProviders] = useState<string[]>([]);
|
|
|
|
const [open, isOpen] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
const response = await httpClient.doGet<ServerInfoRepresentation>(
|
|
|
|
"/admin/serverinfo"
|
|
|
|
);
|
|
|
|
const providers = Object.entries(
|
|
|
|
response.data!.providers["login-protocol"].providers
|
|
|
|
);
|
|
|
|
setProviders(["", ...new Map(providers.sort(sortProvider)).keys()]);
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form isHorizontal>
|
|
|
|
<FormGroup label="Client Type" fieldId="kc-type" isRequired>
|
|
|
|
<Select
|
|
|
|
id="kc-type"
|
|
|
|
required
|
|
|
|
onToggle={() => isOpen(!open)}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(
|
|
|
|
value as string,
|
|
|
|
({
|
|
|
|
target: {
|
|
|
|
name: "protocol",
|
|
|
|
},
|
|
|
|
} as unknown) as FormEvent<HTMLInputElement>
|
|
|
|
);
|
|
|
|
isOpen(false);
|
|
|
|
}}
|
|
|
|
selections={client.protocol}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label="Select Encryption type"
|
|
|
|
isOpen={open}
|
|
|
|
>
|
|
|
|
{providers.map((option) => (
|
|
|
|
<SelectOption
|
|
|
|
key={option}
|
|
|
|
value={option || "Select an option"}
|
|
|
|
isPlaceholder={option === ""}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
</FormGroup>
|
2020-09-03 19:25:05 +00:00
|
|
|
<ClientDescription onChange={onChange} client={client} />
|
2020-08-31 18:26:25 +00:00
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|