2020-09-25 17:42:32 +00:00
|
|
|
import React, { useContext, useEffect } from "react";
|
2020-09-22 12:43:51 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
TextInput,
|
|
|
|
Form,
|
|
|
|
Switch,
|
|
|
|
TextArea,
|
|
|
|
PageSection,
|
2020-09-25 17:42:32 +00:00
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
AlertVariant,
|
2020-09-22 12:43:51 +00:00
|
|
|
} from "@patternfly/react-core";
|
2020-09-25 17:42:32 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2020-09-22 12:43:51 +00:00
|
|
|
|
|
|
|
import { ScrollForm } from "../components/scroll-form/ScrollForm";
|
|
|
|
import { ClientDescription } from "./ClientDescription";
|
|
|
|
import { CapabilityConfig } from "./add/CapabilityConfig";
|
2020-09-25 17:42:32 +00:00
|
|
|
import { RealmContext } from "../components/realm-context/RealmContext";
|
|
|
|
import { HttpClientContext } from "../http-service/HttpClientContext";
|
|
|
|
import { ClientRepresentation } from "../realm/models/Realm";
|
|
|
|
import {
|
|
|
|
convertToMultiline,
|
|
|
|
MultiLineInput,
|
|
|
|
toValue,
|
|
|
|
} from "../components/multi-line-input/MultiLineInput";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
2020-09-22 12:43:51 +00:00
|
|
|
|
2020-09-25 17:42:32 +00:00
|
|
|
export const ClientSettings = () => {
|
2020-09-22 12:43:51 +00:00
|
|
|
const { t } = useTranslation("clients");
|
2020-09-25 17:42:32 +00:00
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
const { realm } = useContext(RealmContext);
|
|
|
|
const [addAlert, Alerts] = useAlerts();
|
|
|
|
|
|
|
|
const { id } = useParams<{ id: string }>();
|
2020-09-22 12:43:51 +00:00
|
|
|
const form = useForm();
|
2020-09-25 17:42:32 +00:00
|
|
|
const url = `/admin/realms/${realm}/clients/${id}`;
|
2020-09-22 12:43:51 +00:00
|
|
|
|
2020-09-25 17:42:32 +00:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
const fetchedClient = await httpClient.doGet<ClientRepresentation>(url);
|
|
|
|
if (fetchedClient.data) {
|
|
|
|
Object.entries(fetchedClient.data).map((entry) => {
|
|
|
|
if (entry[0] !== "redirectUris") {
|
|
|
|
form.setValue(entry[0], entry[1]);
|
|
|
|
} else if (entry[1] && entry[1].length > 0) {
|
|
|
|
form.setValue(entry[0], convertToMultiline(entry[1]));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const save = async () => {
|
|
|
|
if (await form.trigger()) {
|
|
|
|
const redirectUris = toValue(form.getValues()["redirectUris"]);
|
|
|
|
try {
|
|
|
|
httpClient.doPut(url, { ...form.getValues(), redirectUris });
|
|
|
|
addAlert(t("clientSaveSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
addAlert(`${t("clientSaveError")} '${error}'`, AlertVariant.danger);
|
|
|
|
}
|
|
|
|
}
|
2020-09-22 12:43:51 +00:00
|
|
|
};
|
2020-09-25 17:42:32 +00:00
|
|
|
|
2020-09-22 12:43:51 +00:00
|
|
|
return (
|
|
|
|
<PageSection>
|
2020-09-25 17:42:32 +00:00
|
|
|
<Alerts />
|
2020-09-22 12:43:51 +00:00
|
|
|
<ScrollForm
|
|
|
|
sections={[
|
|
|
|
t("capabilityConfig"),
|
|
|
|
t("generalSettings"),
|
|
|
|
t("accessSettings"),
|
|
|
|
t("loginSettings"),
|
|
|
|
]}
|
|
|
|
>
|
2020-09-25 17:42:32 +00:00
|
|
|
<CapabilityConfig form={form} />
|
2020-09-22 12:43:51 +00:00
|
|
|
<Form isHorizontal>
|
2020-09-23 19:19:02 +00:00
|
|
|
<ClientDescription form={form} />
|
2020-09-22 12:43:51 +00:00
|
|
|
</Form>
|
|
|
|
<Form isHorizontal>
|
|
|
|
<FormGroup label={t("rootUrl")} fieldId="kc-root-url">
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-root-url"
|
|
|
|
name="rootUrl"
|
2020-09-25 17:42:32 +00:00
|
|
|
ref={form.register}
|
2020-09-22 12:43:51 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup label={t("validRedirectUri")} fieldId="kc-redirect">
|
2020-09-25 17:42:32 +00:00
|
|
|
<MultiLineInput form={form} name="redirectUris" />
|
2020-09-22 12:43:51 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup label={t("homeURL")} fieldId="kc-home-url">
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-home-url"
|
|
|
|
name="baseUrl"
|
2020-09-25 17:42:32 +00:00
|
|
|
ref={form.register}
|
2020-09-22 12:43:51 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
|
|
|
<Form isHorizontal>
|
|
|
|
<FormGroup label={t("consentRequired")} fieldId="kc-consent">
|
2020-09-25 17:42:32 +00:00
|
|
|
<Controller
|
2020-09-22 12:43:51 +00:00
|
|
|
name="consentRequired"
|
2020-09-25 17:42:32 +00:00
|
|
|
defaultValue={false}
|
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="kc-consent"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
2020-09-22 12:43:51 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("displayOnClient")}
|
|
|
|
fieldId="kc-display-on-client"
|
|
|
|
>
|
2020-09-25 17:42:32 +00:00
|
|
|
<Controller
|
2020-09-22 12:43:51 +00:00
|
|
|
name="alwaysDisplayInConsole"
|
2020-09-25 17:42:32 +00:00
|
|
|
defaultValue={false}
|
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="kc-display-on-client"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
2020-09-22 12:43:51 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("consentScreenText")}
|
|
|
|
fieldId="kc-consent-screen-text"
|
|
|
|
>
|
|
|
|
<TextArea
|
|
|
|
id="kc-consent-screen-text"
|
|
|
|
name="consentText"
|
2020-09-25 17:42:32 +00:00
|
|
|
ref={form.register}
|
2020-09-22 12:43:51 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2020-09-25 17:42:32 +00:00
|
|
|
<ActionGroup>
|
|
|
|
<Button variant="primary" onClick={() => save()}>
|
|
|
|
{t("common:save")}
|
|
|
|
</Button>
|
|
|
|
<Button variant="link">{t("common:cancel")}</Button>
|
|
|
|
</ActionGroup>
|
2020-09-22 12:43:51 +00:00
|
|
|
</Form>
|
|
|
|
</ScrollForm>
|
|
|
|
</PageSection>
|
|
|
|
);
|
|
|
|
};
|