2021-03-19 07:49:33 +00:00
|
|
|
import React, { useState } from "react";
|
2020-09-22 12:43:51 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
TextInput,
|
|
|
|
Form,
|
|
|
|
Switch,
|
|
|
|
TextArea,
|
2021-03-19 07:49:33 +00:00
|
|
|
Select,
|
|
|
|
SelectVariant,
|
|
|
|
SelectOption,
|
2020-09-22 12:43:51 +00:00
|
|
|
} from "@patternfly/react-core";
|
2021-02-28 20:02:31 +00:00
|
|
|
import { Controller, useFormContext } 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-11-02 20:15:09 +00:00
|
|
|
import { MultiLineInput } from "../components/multi-line-input/MultiLineInput";
|
2020-10-28 18:17:15 +00:00
|
|
|
import { FormAccess } from "../components/form-access/FormAccess";
|
2021-02-23 08:55:24 +00:00
|
|
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
2021-03-19 07:49:33 +00:00
|
|
|
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
|
|
|
|
import { SaveReset } from "./advanced/SaveReset";
|
2020-09-22 12:43:51 +00:00
|
|
|
|
2020-11-02 20:15:09 +00:00
|
|
|
type ClientSettingsProps = {
|
|
|
|
save: () => void;
|
2021-03-19 07:49:33 +00:00
|
|
|
reset: () => void;
|
2020-11-02 20:15:09 +00:00
|
|
|
};
|
2020-10-13 17:57:35 +00:00
|
|
|
|
2021-03-19 07:49:33 +00:00
|
|
|
export const ClientSettings = ({ save, reset }: ClientSettingsProps) => {
|
|
|
|
const { register, control, watch } = useFormContext();
|
2020-11-02 20:15:09 +00:00
|
|
|
const { t } = useTranslation("clients");
|
2020-09-25 17:42:32 +00:00
|
|
|
|
2021-03-19 07:49:33 +00:00
|
|
|
const [loginThemeOpen, setLoginThemeOpen] = useState(false);
|
|
|
|
const loginThemes = useServerInfo().themes!["login"];
|
|
|
|
const consentRequired: boolean = watch("consentRequired");
|
|
|
|
const displayOnConsentScreen: string = watch(
|
|
|
|
"attributes.display-on-consent-screen"
|
|
|
|
);
|
|
|
|
|
2020-09-22 12:43:51 +00:00
|
|
|
return (
|
2020-10-02 13:56:46 +00:00
|
|
|
<>
|
2020-11-02 20:15:09 +00:00
|
|
|
<ScrollForm
|
2021-04-20 19:46:07 +00:00
|
|
|
className="pf-u-px-lg"
|
2020-11-02 20:15:09 +00:00
|
|
|
sections={[
|
|
|
|
t("generalSettings"),
|
2021-08-09 14:35:31 +00:00
|
|
|
t("capabilityConfig"),
|
2020-11-02 20:15:09 +00:00
|
|
|
t("accessSettings"),
|
|
|
|
t("loginSettings"),
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<Form isHorizontal>
|
2021-02-28 20:02:31 +00:00
|
|
|
<ClientDescription />
|
2020-11-02 20:15:09 +00:00
|
|
|
</Form>
|
2021-08-09 14:35:31 +00:00
|
|
|
<CapabilityConfig />
|
2020-11-02 20:15:09 +00:00
|
|
|
<FormAccess isHorizontal role="manage-clients">
|
2021-03-19 07:49:33 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("rootUrl")}
|
|
|
|
fieldId="kc-root-url"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:rootUrl"
|
|
|
|
forLabel={t("rootUrl")}
|
|
|
|
forID="kc-root-url"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2020-11-02 20:15:09 +00:00
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-root-url"
|
|
|
|
name="rootUrl"
|
2021-02-28 20:02:31 +00:00
|
|
|
ref={register}
|
2020-11-02 20:15:09 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-03-19 07:49:33 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("validRedirectUri")}
|
|
|
|
fieldId="kc-redirect"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:validRedirectURIs"
|
|
|
|
forLabel={t("validRedirectUri")}
|
2021-07-09 16:15:21 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("validRedirectUri") })}
|
2021-03-19 07:49:33 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<MultiLineInput
|
|
|
|
name="redirectUris"
|
2021-07-09 16:15:21 +00:00
|
|
|
aria-label={t("validRedirectUri")}
|
2021-03-19 07:49:33 +00:00
|
|
|
addButtonLabel="clients:addRedirectUri"
|
|
|
|
/>
|
2020-11-02 20:15:09 +00:00
|
|
|
</FormGroup>
|
2021-03-19 07:49:33 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("homeURL")}
|
|
|
|
fieldId="kc-home-url"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:homeURL"
|
|
|
|
forLabel={t("homeURL")}
|
2021-07-09 16:15:21 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("homeURL") })}
|
2021-03-19 07:49:33 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2020-11-02 20:15:09 +00:00
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-home-url"
|
|
|
|
name="baseUrl"
|
2021-02-28 20:02:31 +00:00
|
|
|
ref={register}
|
2020-11-02 20:15:09 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-02-23 08:55:24 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("webOrigins")}
|
|
|
|
fieldId="kc-web-origins"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:webOrigins"
|
|
|
|
forLabel={t("webOrigins")}
|
2021-07-09 16:15:21 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("webOrigins") })}
|
2021-02-23 08:55:24 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2021-03-19 07:49:33 +00:00
|
|
|
<MultiLineInput
|
|
|
|
name="webOrigins"
|
2021-07-09 16:15:21 +00:00
|
|
|
aria-label={t("webOrigins")}
|
2021-03-19 07:49:33 +00:00
|
|
|
addButtonLabel="clients:addWebOrigins"
|
|
|
|
/>
|
2021-02-23 08:55:24 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("adminURL")}
|
|
|
|
fieldId="kc-admin-url"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:adminURL"
|
|
|
|
forLabel={t("adminURL")}
|
|
|
|
forID="kc-admin-url"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-admin-url"
|
|
|
|
name="adminUrl"
|
2021-02-28 20:02:31 +00:00
|
|
|
ref={register}
|
2021-02-23 08:55:24 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2020-11-02 20:15:09 +00:00
|
|
|
</FormAccess>
|
|
|
|
<FormAccess isHorizontal role="manage-clients">
|
2021-03-19 07:49:33 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("loginTheme")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:loginTheme"
|
|
|
|
forLabel={t("loginTheme")}
|
|
|
|
forID="loginTheme"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="loginTheme"
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="attributes.login_theme"
|
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="loginTheme"
|
|
|
|
onToggle={() => setLoginThemeOpen(!loginThemeOpen)}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setLoginThemeOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value || t("common:choose")}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("loginTheme")}
|
|
|
|
isOpen={loginThemeOpen}
|
|
|
|
>
|
|
|
|
<SelectOption key="empty" value="">
|
|
|
|
{t("common:choose")}
|
|
|
|
</SelectOption>
|
|
|
|
<>
|
2021-08-12 11:15:47 +00:00
|
|
|
{loginThemes?.map((theme) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={theme.name === value}
|
|
|
|
key={theme.name}
|
|
|
|
value={theme.name}
|
|
|
|
/>
|
|
|
|
))}
|
2021-03-19 07:49:33 +00:00
|
|
|
</>
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2020-11-02 20:15:09 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("consentRequired")}
|
|
|
|
fieldId="kc-consent"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="consentRequired"
|
|
|
|
defaultValue={false}
|
2021-02-28 20:02:31 +00:00
|
|
|
control={control}
|
2020-11-02 20:15:09 +00:00
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
2021-07-09 16:15:21 +00:00
|
|
|
id="kc-consent-switch"
|
2020-11-02 20:15:09 +00:00
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("displayOnClient")}
|
|
|
|
fieldId="kc-display-on-client"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
|
|
|
<Controller
|
2021-02-28 20:02:31 +00:00
|
|
|
name="attributes.display-on-consent-screen"
|
2020-11-02 20:15:09 +00:00
|
|
|
defaultValue={false}
|
2021-02-28 20:02:31 +00:00
|
|
|
control={control}
|
2020-11-02 20:15:09 +00:00
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
2021-07-09 16:15:21 +00:00
|
|
|
id="kc-display-on-client-switch"
|
2020-11-02 20:15:09 +00:00
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2021-02-28 20:02:31 +00:00
|
|
|
isChecked={value === "true"}
|
|
|
|
onChange={(value) => onChange("" + value)}
|
2021-03-19 07:49:33 +00:00
|
|
|
isDisabled={!consentRequired}
|
2020-11-02 20:15:09 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("consentScreenText")}
|
|
|
|
fieldId="kc-consent-screen-text"
|
|
|
|
>
|
|
|
|
<TextArea
|
|
|
|
id="kc-consent-screen-text"
|
2021-02-28 20:02:31 +00:00
|
|
|
name="attributes.consent-screen-text"
|
|
|
|
ref={register}
|
2021-03-19 07:49:33 +00:00
|
|
|
isDisabled={
|
|
|
|
!(consentRequired && displayOnConsentScreen === "true")
|
|
|
|
}
|
2020-11-02 20:15:09 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-04-06 17:19:15 +00:00
|
|
|
<SaveReset
|
|
|
|
className="keycloak__form_actions"
|
|
|
|
name="settings"
|
|
|
|
save={save}
|
|
|
|
reset={reset}
|
|
|
|
/>
|
2020-11-02 20:15:09 +00:00
|
|
|
</FormAccess>
|
|
|
|
</ScrollForm>
|
2020-10-02 13:56:46 +00:00
|
|
|
</>
|
2020-09-22 12:43:51 +00:00
|
|
|
);
|
|
|
|
};
|