Skip to content

Commit

Permalink
replaced KeycloakTextInput with TextControl (keycloak#27711)
Browse files Browse the repository at this point in the history
Signed-off-by: Agnieszka Gancarczyk <agancarc@redhat.com>
Co-authored-by: Agnieszka Gancarczyk <agancarc@redhat.com>
  • Loading branch information
agagancarczyk and agagancarczyk authored Mar 8, 2024
1 parent 299118c commit 7695532
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ModalUtils from "../../../../util/ModalUtils";

export default class GroupModal extends ModalUtils {
#createGroupModalTitle = "Create a group";
#groupNameInput = "groupNameInput";
#groupNameInput = "name";
#createGroupBnt = "createGroup";
#renameButton = "renameGroup";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class GroupDetailPage extends GroupPage {
#actionDrpDwnItemRenameGroup = "renameGroupAction";
#actionDrpDwnItemDeleteGroup = "deleteGroup";
#headerGroupName = ".pf-l-level.pf-m-gutter";
#renameGroupModalGroupNameInput = "groupNameInput";
#renameGroupModalGroupNameInput = "name";
#renameGroupModalRenameBtn = "renameGroup";
#permissionSwitch = "permissionSwitch";

Expand Down
43 changes: 13 additions & 30 deletions js/apps/admin-ui/src/groups/GroupsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
Button,
ButtonVariant,
Form,
FormGroup,
Modal,
ModalVariant,
ValidatedOptions,
} from "@patternfly/react-core";
import { useForm } from "react-hook-form";
import { FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";

import { TextControl } from "ui-shared";
import { adminClient } from "../admin-client";
import { useAlerts } from "../components/alert/Alerts";
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";

type GroupsModalProps = {
id?: string;
Expand All @@ -31,13 +28,11 @@ export const GroupsModal = ({
}: GroupsModalProps) => {
const { t } = useTranslation();
const { addAlert, addError } = useAlerts();
const {
register,
handleSubmit,
formState: { errors },
} = useForm({

const form = useForm({
defaultValues: { name: rename?.name },
});
const { handleSubmit } = form;

const submitForm = async (group: GroupRepresentation) => {
group.name = group.name?.trim();
Expand Down Expand Up @@ -96,28 +91,16 @@ export const GroupsModal = ({
</Button>,
]}
>
<Form id="group-form" isHorizontal onSubmit={handleSubmit(submitForm)}>
<FormGroup
name="create-modal-group"
label={t("name")}
fieldId="create-group-name"
helperTextInvalid={t("required")}
validated={
errors.name ? ValidatedOptions.error : ValidatedOptions.default
}
isRequired
>
<KeycloakTextInput
data-testid="groupNameInput"
<FormProvider {...form}>
<Form id="group-form" isHorizontal onSubmit={handleSubmit(submitForm)}>
<TextControl
name="name"
label={t("name")}
rules={{ required: t("required") }}
autoFocus
id="create-group-name"
validated={
errors.name ? ValidatedOptions.error : ValidatedOptions.default
}
{...register("name", { required: true })}
/>
</FormGroup>
</Form>
</Form>
</FormProvider>
</Modal>
);
};

0 comments on commit 7695532

Please sign in to comment.