2022-05-11 09:46:14 +00:00
|
|
|
import { FormGroup, Switch, ValidatedOptions } from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-03-07 09:29:40 +00:00
|
|
|
import { HelpItem } from "ui-shared";
|
2021-03-09 13:59:41 +00:00
|
|
|
|
2021-02-28 20:02:31 +00:00
|
|
|
import { FormAccess } from "../components/form-access/FormAccess";
|
2022-05-11 09:46:14 +00:00
|
|
|
import { KeycloakTextArea } from "../components/keycloak-text-area/KeycloakTextArea";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";
|
|
|
|
import { FormFields } from "./ClientDetails";
|
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 },
|
2022-12-02 14:54:30 +00:00
|
|
|
} = useFormContext<FormFields>();
|
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
|
2022-12-02 14:54:30 +00:00
|
|
|
{...register("clientId", { required: true })}
|
2020-09-03 19:25:05 +00:00
|
|
|
id="kc-client-id"
|
2022-10-03 11:00:26 +00:00
|
|
|
data-testid="kc-client-id"
|
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={
|
2023-03-07 09:29:40 +00:00
|
|
|
<HelpItem
|
|
|
|
helpText={t("clients-help:clientName")}
|
|
|
|
fieldLabelId="name"
|
|
|
|
/>
|
2021-03-09 13:59:41 +00:00
|
|
|
}
|
|
|
|
label={t("common:name")}
|
|
|
|
fieldId="kc-name"
|
|
|
|
>
|
2022-12-02 14:54:30 +00:00
|
|
|
<KeycloakTextInput {...register("name")} id="kc-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
|
2023-03-07 09:29:40 +00:00
|
|
|
helpText={t("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
|
2022-12-02 14:54:30 +00:00
|
|
|
{...register("description", {
|
2021-02-16 19:18:09 +00:00
|
|
|
maxLength: {
|
|
|
|
value: 255,
|
|
|
|
message: t("common:maxLength", { length: 255 }),
|
|
|
|
},
|
|
|
|
})}
|
2020-09-03 19:25:05 +00:00
|
|
|
id="kc-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
|
2022-12-07 15:28:28 +00:00
|
|
|
label={t("alwaysDisplayInUI")}
|
2022-06-24 11:31:02 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-03-07 09:29:40 +00:00
|
|
|
helpText={t("clients-help:alwaysDisplayInUI")}
|
2022-12-07 15:28:28 +00:00
|
|
|
fieldLabelId="clients:alwaysDisplayInUI"
|
2022-06-24 11:31:02 +00:00
|
|
|
/>
|
|
|
|
}
|
2022-12-07 15:28:28 +00:00
|
|
|
fieldId="kc-always-display-in-ui"
|
2022-06-24 11:31:02 +00:00
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="alwaysDisplayInConsole"
|
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2022-06-24 11:31:02 +00:00
|
|
|
<Switch
|
2022-12-07 15:28:28 +00:00
|
|
|
id="kc-always-display-in-ui-switch"
|
2022-06-24 11:31:02 +00:00
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2022-12-02 14:54:30 +00:00
|
|
|
isChecked={field.value}
|
|
|
|
onChange={field.onChange}
|
2022-12-07 15:28:28 +00:00
|
|
|
aria-label={t("alwaysDisplayInUI")}
|
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
|
|
|
);
|
|
|
|
};
|