2020-08-31 18:26:25 +00:00
|
|
|
import React, { useState, FormEvent, useContext } from "react";
|
|
|
|
import {
|
|
|
|
Text,
|
|
|
|
PageSection,
|
|
|
|
TextContent,
|
|
|
|
Divider,
|
|
|
|
Wizard,
|
|
|
|
AlertVariant,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { HttpClientContext } from "../../http-service/HttpClientContext";
|
|
|
|
import { Step1 } from "./Step1";
|
|
|
|
import { Step2 } from "./Step2";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { ClientRepresentation } from "../models/client-model";
|
2020-08-31 18:26:25 +00:00
|
|
|
import { useAlerts } from "../../components/alert/Alerts";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2020-09-17 11:37:30 +00:00
|
|
|
import { RealmContext } from "../../components/realm-context/RealmContext";
|
2020-08-31 18:26:25 +00:00
|
|
|
|
|
|
|
export const NewClientForm = () => {
|
2020-09-10 18:04:03 +00:00
|
|
|
const { t } = useTranslation("clients");
|
2020-08-31 18:26:25 +00:00
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
2020-09-17 11:37:30 +00:00
|
|
|
const { realm } = useContext(RealmContext);
|
|
|
|
|
2020-08-31 18:26:25 +00:00
|
|
|
const [client, setClient] = useState<ClientRepresentation>({
|
|
|
|
protocol: "",
|
|
|
|
clientId: "",
|
|
|
|
name: "",
|
|
|
|
description: "",
|
|
|
|
publicClient: false,
|
|
|
|
authorizationServicesEnabled: false,
|
|
|
|
});
|
2020-09-15 19:44:28 +00:00
|
|
|
const [add, Alerts] = useAlerts();
|
2020-08-31 18:26:25 +00:00
|
|
|
|
|
|
|
const save = async () => {
|
|
|
|
try {
|
2020-09-17 11:37:30 +00:00
|
|
|
await httpClient.doPost(`/admin/realms/${realm}/clients`, client);
|
2020-08-31 18:26:25 +00:00
|
|
|
add("Client created", AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
add(`Could not create client: '${error}'`, AlertVariant.danger);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleInputChange = (
|
|
|
|
value: string | boolean,
|
|
|
|
event: FormEvent<HTMLInputElement>
|
|
|
|
) => {
|
|
|
|
const target = event.target;
|
|
|
|
const name = (target as HTMLInputElement).name;
|
|
|
|
|
|
|
|
setClient({
|
|
|
|
...client,
|
|
|
|
[name]: value,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-16 14:56:23 +00:00
|
|
|
const title = t("createClient");
|
2020-08-31 18:26:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-09-15 19:44:28 +00:00
|
|
|
<Alerts />
|
2020-08-31 18:26:25 +00:00
|
|
|
<PageSection variant="light">
|
|
|
|
<TextContent>
|
|
|
|
<Text component="h1">{title}</Text>
|
|
|
|
</TextContent>
|
|
|
|
</PageSection>
|
|
|
|
<Divider />
|
|
|
|
<PageSection variant="light">
|
|
|
|
<Wizard
|
|
|
|
navAriaLabel={`${title} steps`}
|
|
|
|
mainAriaLabel={`${title} content`}
|
|
|
|
steps={[
|
|
|
|
{
|
2020-09-16 14:56:23 +00:00
|
|
|
name: t("generalSettings"),
|
2020-08-31 18:26:25 +00:00
|
|
|
component: <Step1 onChange={handleInputChange} client={client} />,
|
|
|
|
},
|
|
|
|
{
|
2020-09-16 14:56:23 +00:00
|
|
|
name: t("capabilityConfig"),
|
2020-08-31 18:26:25 +00:00
|
|
|
component: <Step2 onChange={handleInputChange} client={client} />,
|
2020-09-16 14:56:23 +00:00
|
|
|
nextButtonText: t("common:save"),
|
2020-08-31 18:26:25 +00:00
|
|
|
},
|
|
|
|
]}
|
2020-09-10 18:04:03 +00:00
|
|
|
onSave={() => save()}
|
2020-08-31 18:26:25 +00:00
|
|
|
/>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|