2020-09-17 13:51:40 +00:00
|
|
|
import React, { useState, useEffect, useContext } from "react";
|
2020-08-31 18:26:25 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Form,
|
|
|
|
Select,
|
|
|
|
SelectVariant,
|
|
|
|
SelectOption,
|
|
|
|
} from "@patternfly/react-core";
|
2020-09-17 13:51:40 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { Controller, UseFormMethods } from "react-hook-form";
|
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 { ClientDescription } from "../ClientDescription";
|
2020-08-31 18:26:25 +00:00
|
|
|
|
|
|
|
type Step1Props = {
|
2020-09-17 13:51:40 +00:00
|
|
|
form: UseFormMethods;
|
2020-08-31 18:26:25 +00:00
|
|
|
};
|
|
|
|
|
2020-09-17 13:51:40 +00:00
|
|
|
export const Step1 = ({ form }: Step1Props) => {
|
2020-08-31 18:26:25 +00:00
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
2020-09-17 13:51:40 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const { errors, control, register } = form;
|
2020-08-31 18:26:25 +00:00
|
|
|
|
|
|
|
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>
|
2020-09-17 13:51:40 +00:00
|
|
|
<FormGroup
|
|
|
|
label="Client Type"
|
|
|
|
fieldId="kc-type"
|
|
|
|
isRequired
|
|
|
|
helperTextInvalid={t("common:required")}
|
|
|
|
validated={errors.protocol ? "error" : "default"}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="protocol"
|
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
rules={{ required: true }}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
id="kc-type"
|
|
|
|
required
|
|
|
|
onToggle={() => isOpen(!open)}
|
|
|
|
onSelect={(_, value, isPlaceholder) => {
|
|
|
|
onChange(isPlaceholder ? "" : (value as string));
|
|
|
|
isOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label="Select Encryption type"
|
|
|
|
isOpen={open}
|
|
|
|
>
|
|
|
|
{providers.map((option) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={option === value}
|
|
|
|
key={option}
|
|
|
|
value={option === "" ? "Select an option" : option}
|
|
|
|
isPlaceholder={option === ""}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
2020-08-31 18:26:25 +00:00
|
|
|
</FormGroup>
|
2020-09-17 13:51:40 +00:00
|
|
|
<ClientDescription register={register} />
|
2020-08-31 18:26:25 +00:00
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|