![Erik Jan de Wit](/assets/img/avatar_default.png)
* refactor + use new composite role api * fixed types * Update src/realm-roles/AssociatedRolesModal.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/realm-roles/AssociatedRolesModal.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/realm-roles/RealmRoleTabs.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * code review comments * removed duplicate type * route * Update src/realm-roles/AssociatedRolesModal.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/realm-roles/routes/RealmRole.ts Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/realm-roles/AssociatedRolesModal.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * fix unused import * fixed test * fixed merge errors Co-authored-by: Jon Koops <jonkoops@gmail.com>
98 lines
2.6 KiB
TypeScript
98 lines
2.6 KiB
TypeScript
import React from "react";
|
|
import {
|
|
ActionGroup,
|
|
Button,
|
|
FormGroup,
|
|
PageSection,
|
|
TextArea,
|
|
TextInput,
|
|
ValidatedOptions,
|
|
} from "@patternfly/react-core";
|
|
import { useTranslation } from "react-i18next";
|
|
import type { UseFormMethods } from "react-hook-form";
|
|
import { FormAccess } from "../components/form-access/FormAccess";
|
|
import type { AttributeForm } from "../components/attribute-form/AttributeForm";
|
|
|
|
export type RealmRoleFormProps = {
|
|
form: UseFormMethods<AttributeForm>;
|
|
save: () => void;
|
|
editMode: boolean;
|
|
reset: () => void;
|
|
};
|
|
|
|
export const RealmRoleForm = ({
|
|
form: { handleSubmit, errors, register, getValues },
|
|
save,
|
|
editMode,
|
|
reset,
|
|
}: RealmRoleFormProps) => {
|
|
const { t } = useTranslation("roles");
|
|
|
|
return (
|
|
<PageSection variant="light">
|
|
<FormAccess
|
|
isHorizontal
|
|
onSubmit={handleSubmit(save)}
|
|
role="manage-realm"
|
|
className="pf-u-mt-lg"
|
|
>
|
|
<FormGroup
|
|
label={t("roleName")}
|
|
fieldId="kc-name"
|
|
isRequired
|
|
validated={errors.name ? "error" : "default"}
|
|
helperTextInvalid={t("common:required")}
|
|
>
|
|
<TextInput
|
|
ref={register({ required: !editMode })}
|
|
type="text"
|
|
id="kc-name"
|
|
name="name"
|
|
isReadOnly={editMode}
|
|
/>
|
|
</FormGroup>
|
|
<FormGroup
|
|
label={t("common:description")}
|
|
fieldId="kc-description"
|
|
validated={
|
|
errors.description
|
|
? ValidatedOptions.error
|
|
: ValidatedOptions.default
|
|
}
|
|
helperTextInvalid={errors.description?.message}
|
|
>
|
|
<TextArea
|
|
name="description"
|
|
aria-label="description"
|
|
isDisabled={getValues().name?.includes("default-roles")}
|
|
ref={register({
|
|
maxLength: {
|
|
value: 255,
|
|
message: t("common:maxLength", { length: 255 }),
|
|
},
|
|
})}
|
|
type="text"
|
|
validated={
|
|
errors.description
|
|
? ValidatedOptions.error
|
|
: ValidatedOptions.default
|
|
}
|
|
id="kc-role-description"
|
|
/>
|
|
</FormGroup>
|
|
<ActionGroup>
|
|
<Button
|
|
variant="primary"
|
|
onClick={save}
|
|
data-testid="realm-roles-save-button"
|
|
>
|
|
{t("common:save")}
|
|
</Button>
|
|
<Button onClick={() => reset()} variant="link">
|
|
{editMode ? t("common:revert") : t("common:cancel")}
|
|
</Button>
|
|
</ActionGroup>
|
|
</FormAccess>
|
|
</PageSection>
|
|
);
|
|
};
|