keycloak-scim/apps/admin-ui/src/clients/ClientDescription.tsx

116 lines
3.5 KiB
TypeScript
Raw Normal View History

import { FormGroup, Switch, ValidatedOptions } from "@patternfly/react-core";
import { Controller, useFormContext } from "react-hook-form-v7";
import { useTranslation } from "react-i18next";
import { FormAccess } from "../components/form-access/FormAccess";
import { HelpItem } from "../components/help-enabler/HelpItem";
import { KeycloakTextArea } from "../components/keycloak-text-area/KeycloakTextArea";
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";
import { FormFields } from "./ClientDetails";
type ClientDescriptionProps = {
protocol?: string;
2022-05-30 09:23:24 +00:00
hasConfigureAccess?: boolean;
};
2022-05-30 09:23:24 +00:00
export const ClientDescription = ({
hasConfigureAccess: configure,
}: ClientDescriptionProps) => {
const { t } = useTranslation("clients");
const {
register,
control,
formState: { errors },
} = useFormContext<FormFields>();
return (
2022-05-30 09:23:24 +00:00
<FormAccess role="manage-clients" fineGrainedAccess={configure} unWrap>
<FormGroup
labelIcon={
2021-12-14 14:56:36 +00:00
<HelpItem helpText="clients-help:clientId" fieldLabelId="clientId" />
}
2021-04-06 17:39:27 +00:00
label={t("common:clientId")}
fieldId="kc-client-id"
helperTextInvalid={t("common:required")}
validated={
errors.clientId ? ValidatedOptions.error : ValidatedOptions.default
}
isRequired
>
<KeycloakTextInput
{...register("clientId", { required: true })}
id="kc-client-id"
2022-10-03 11:00:26 +00:00
data-testid="kc-client-id"
validated={
errors.clientId ? ValidatedOptions.error : ValidatedOptions.default
}
/>
</FormGroup>
<FormGroup
labelIcon={
2021-12-14 14:56:36 +00:00
<HelpItem helpText="clients-help:clientName" fieldLabelId="name" />
}
label={t("common:name")}
fieldId="kc-name"
>
<KeycloakTextInput {...register("name")} id="kc-name" />
</FormGroup>
<FormGroup
labelIcon={
<HelpItem
helpText="clients-help:description"
2021-12-14 14:56:36 +00:00
fieldLabelId="description"
/>
}
label={t("common:description")}
fieldId="kc-description"
validated={
errors.description ? ValidatedOptions.error : ValidatedOptions.default
}
helperTextInvalid={errors.description?.message}
>
<KeycloakTextArea
{...register("description", {
maxLength: {
value: 255,
message: t("common:maxLength", { length: 255 }),
},
})}
id="kc-description"
validated={
errors.description
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
</FormGroup>
<FormGroup
label={t("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={({ field }) => (
<Switch
id="kc-always-display-in-console-switch"
label={t("common:on")}
labelOff={t("common:off")}
isChecked={field.value}
onChange={field.onChange}
aria-label={t("alwaysDisplayInConsole")}
/>
)}
/>
</FormGroup>
</FormAccess>
);
};