2020-09-17 13:51:40 +00:00
|
|
|
import React from "react";
|
2022-03-02 16:08:01 +00:00
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-05-11 09:46:14 +00:00
|
|
|
import { FormGroup, Switch, ValidatedOptions } from "@patternfly/react-core";
|
2021-03-09 13:59:41 +00:00
|
|
|
|
2022-03-09 16:42:23 +00:00
|
|
|
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
2021-03-09 13:59:41 +00:00
|
|
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
2021-02-28 20:02:31 +00:00
|
|
|
import { FormAccess } from "../components/form-access/FormAccess";
|
2022-04-21 15:03:26 +00:00
|
|
|
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";
|
2022-05-11 09:46:14 +00:00
|
|
|
import { KeycloakTextArea } from "../components/keycloak-text-area/KeycloakTextArea";
|
2020-09-03 19:25:05 +00:00
|
|
|
|
2022-03-02 16:08:01 +00:00
|
|
|
type ClientDescriptionProps = {
|
|
|
|
protocol?: string;
|
2022-05-30 09:23:24 +00:00
|
|
|
hasConfigureAccess?: boolean;
|
2022-03-02 16:08:01 +00:00
|
|
|
};
|
|
|
|
|
2022-05-30 09:23:24 +00:00
|
|
|
export const ClientDescription = ({
|
|
|
|
hasConfigureAccess: configure,
|
|
|
|
}: ClientDescriptionProps) => {
|
2020-09-10 18:04:03 +00:00
|
|
|
const { t } = useTranslation("clients");
|
2022-04-08 12:37:31 +00:00
|
|
|
const {
|
|
|
|
register,
|
|
|
|
control,
|
|
|
|
formState: { errors },
|
|
|
|
} = useFormContext<ClientRepresentation>();
|
2020-09-03 19:25:05 +00:00
|
|
|
return (
|
2022-05-30 09:23:24 +00:00
|
|
|
<FormAccess role="manage-clients" fineGrainedAccess={configure} unWrap>
|
2020-09-23 19:19:02 +00:00
|
|
|
<FormGroup
|
2021-03-09 13:59:41 +00:00
|
|
|
labelIcon={
|
2021-12-14 14:56:36 +00:00
|
|
|
<HelpItem helpText="clients-help:clientId" fieldLabelId="clientId" />
|
2021-03-09 13:59:41 +00:00
|
|
|
}
|
2021-04-06 17:39:27 +00:00
|
|
|
label={t("common:clientId")}
|
2020-09-23 19:19:02 +00:00
|
|
|
fieldId="kc-client-id"
|
|
|
|
helperTextInvalid={t("common:required")}
|
2020-11-09 19:49:32 +00:00
|
|
|
validated={
|
|
|
|
errors.clientId ? ValidatedOptions.error : ValidatedOptions.default
|
|
|
|
}
|
2020-09-23 19:19:02 +00:00
|
|
|
isRequired
|
|
|
|
>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2020-09-23 19:19:02 +00:00
|
|
|
ref={register({ required: true })}
|
2020-09-03 19:25:05 +00:00
|
|
|
type="text"
|
|
|
|
id="kc-client-id"
|
|
|
|
name="clientId"
|
2020-11-09 19:49:32 +00:00
|
|
|
validated={
|
|
|
|
errors.clientId ? ValidatedOptions.error : ValidatedOptions.default
|
|
|
|
}
|
2020-09-03 19:25:05 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-03-09 13:59:41 +00:00
|
|
|
<FormGroup
|
|
|
|
labelIcon={
|
2021-12-14 14:56:36 +00:00
|
|
|
<HelpItem helpText="clients-help:clientName" fieldLabelId="name" />
|
2021-03-09 13:59:41 +00:00
|
|
|
}
|
|
|
|
label={t("common:name")}
|
|
|
|
fieldId="kc-name"
|
|
|
|
>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
|
|
|
ref={register()}
|
|
|
|
type="text"
|
|
|
|
id="kc-name"
|
|
|
|
name="name"
|
|
|
|
/>
|
2020-09-03 19:25:05 +00:00
|
|
|
</FormGroup>
|
2021-02-16 19:18:09 +00:00
|
|
|
<FormGroup
|
2021-03-09 13:59:41 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:description"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="description"
|
2021-03-09 13:59:41 +00:00
|
|
|
/>
|
|
|
|
}
|
2021-02-16 19:18:09 +00:00
|
|
|
label={t("common:description")}
|
|
|
|
fieldId="kc-description"
|
|
|
|
validated={
|
|
|
|
errors.description ? ValidatedOptions.error : ValidatedOptions.default
|
|
|
|
}
|
|
|
|
helperTextInvalid={errors.description?.message}
|
|
|
|
>
|
2022-05-11 09:46:14 +00:00
|
|
|
<KeycloakTextArea
|
2021-02-16 19:18:09 +00:00
|
|
|
ref={register({
|
|
|
|
maxLength: {
|
|
|
|
value: 255,
|
|
|
|
message: t("common:maxLength", { length: 255 }),
|
|
|
|
},
|
|
|
|
})}
|
2020-09-03 19:25:05 +00:00
|
|
|
type="text"
|
|
|
|
id="kc-description"
|
|
|
|
name="description"
|
2021-02-16 19:18:09 +00:00
|
|
|
validated={
|
|
|
|
errors.description
|
|
|
|
? ValidatedOptions.error
|
|
|
|
: ValidatedOptions.default
|
|
|
|
}
|
2020-09-03 19:25:05 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2022-06-24 11:31:02 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("clients:alwaysDisplayInConsole")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:alwaysDisplayInConsole"
|
|
|
|
fieldLabelId="clients:alwaysDisplayInConsole"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-always-display-in-console"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="alwaysDisplayInConsole"
|
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="kc-always-display-in-console-switch"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
2022-03-02 16:08:01 +00:00
|
|
|
/>
|
2022-06-24 11:31:02 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2020-10-28 18:17:15 +00:00
|
|
|
</FormAccess>
|
2020-09-03 19:25:05 +00:00
|
|
|
);
|
|
|
|
};
|