diff --git a/js/apps/admin-ui/cypress/support/pages/admin-ui/CreateRealmPage.ts b/js/apps/admin-ui/cypress/support/pages/admin-ui/CreateRealmPage.ts index bac776cbfc..6f2b3618fa 100644 --- a/js/apps/admin-ui/cypress/support/pages/admin-ui/CreateRealmPage.ts +++ b/js/apps/admin-ui/cypress/support/pages/admin-ui/CreateRealmPage.ts @@ -1,14 +1,14 @@ export default class CreateRealmPage { #clearBtn = ".pf-c-file-upload__file-select button:last-child"; #modalClearBtn = "clear-button"; - #realmNameInput = "#kc-realm-name"; + #realmNameInput = "realm"; #enabledSwitch = ".pf-c-toolbar .pf-c-switch__toggle"; #createBtn = '.pf-c-form__group:last-child button[type="submit"]'; #cancelBtn = '.pf-c-form__group:last-child button[type="button"]'; #codeEditor = ".pf-c-code-editor__code"; fillRealmName(realmName: string) { - cy.get(this.#realmNameInput).clear().type(realmName); + cy.findByTestId(this.#realmNameInput).clear().type(realmName); return this; } @@ -45,7 +45,7 @@ export default class CreateRealmPage { } verifyRealmNameFieldInvalid() { - cy.get(this.#realmNameInput) + cy.findByTestId(this.#realmNameInput) .next("div") .contains("Required field") .should("have.class", "pf-m-error"); diff --git a/js/apps/admin-ui/src/components/SwitchControl.tsx b/js/apps/admin-ui/src/components/SwitchControl.tsx index dc326ba447..8c2af8eb47 100644 --- a/js/apps/admin-ui/src/components/SwitchControl.tsx +++ b/js/apps/admin-ui/src/components/SwitchControl.tsx @@ -1,18 +1,12 @@ -import { SwitchProps } from "@patternfly/react-core"; -import { FieldPath, FieldValues, UseControllerProps } from "react-hook-form"; +import { FieldPath, FieldValues } from "react-hook-form"; import { useTranslation } from "react-i18next"; +import type { SwitchControlProps } from "ui-shared"; import { SwitchControl } from "ui-shared"; -type DefaultSwitchControlProps< +export type DefaultSwitchControlProps< T extends FieldValues, P extends FieldPath = FieldPath, -> = SwitchProps & - UseControllerProps & { - name: string; - label?: string; - labelIcon?: string; - stringify?: boolean; - }; +> = Omit, "labelOn" | "labelOff">; export const DefaultSwitchControl = < T extends FieldValues, diff --git a/js/apps/admin-ui/src/realm/add/NewRealmForm.tsx b/js/apps/admin-ui/src/realm/add/NewRealmForm.tsx index 04da0832c1..42e2a58c95 100644 --- a/js/apps/admin-ui/src/realm/add/NewRealmForm.tsx +++ b/js/apps/admin-ui/src/realm/add/NewRealmForm.tsx @@ -1,21 +1,16 @@ import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; -import { - ActionGroup, - Button, - FormGroup, - PageSection, - Switch, -} from "@patternfly/react-core"; +import { ActionGroup, Button, PageSection } from "@patternfly/react-core"; import { useState } from "react"; -import { Controller, useForm } from "react-hook-form"; +import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; +import { TextControl } from "ui-shared"; import { adminClient } from "../../admin-client"; +import { DefaultSwitchControl } from "../../components/SwitchControl"; import { useAlerts } from "../../components/alert/Alerts"; import { FormAccess } from "../../components/form/FormAccess"; import { JsonFileUpload } from "../../components/json-file-upload/JsonFileUpload"; -import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput"; import { ViewHeader } from "../../components/view-header/ViewHeader"; import { useRealms } from "../../context/RealmsContext"; import { useWhoAmI } from "../../context/whoami/WhoAmI"; @@ -30,13 +25,11 @@ export default function NewRealmForm() { const { addAlert, addError } = useAlerts(); const [realm, setRealm] = useState(); - const { - register, - handleSubmit, - control, - setValue, - formState: { errors }, - } = useForm({ mode: "onChange" }); + const form = useForm({ + mode: "onChange", + }); + + const { handleSubmit, setValue } = form; const handleFileChange = (obj?: object) => { const defaultRealm = { id: "", realm: "", enabled: true }; @@ -64,60 +57,38 @@ export default function NewRealmForm() { <> - - - + - - - - + ( - - )} /> - - - - - - + + + + + + ); diff --git a/js/libs/ui-shared/src/controls/SwitchControl.tsx b/js/libs/ui-shared/src/controls/SwitchControl.tsx index 12f0290cc1..42fccb4f03 100644 --- a/js/libs/ui-shared/src/controls/SwitchControl.tsx +++ b/js/libs/ui-shared/src/controls/SwitchControl.tsx @@ -12,7 +12,7 @@ import { FormLabel } from "./FormLabel"; export type SwitchControlProps< T extends FieldValues, P extends FieldPath = FieldPath, -> = Omit & +> = Omit & UseControllerProps & { name: string; label?: string; diff --git a/js/libs/ui-shared/src/main.ts b/js/libs/ui-shared/src/main.ts index 89025a5a8c..731fba5c13 100644 --- a/js/libs/ui-shared/src/main.ts +++ b/js/libs/ui-shared/src/main.ts @@ -1,7 +1,10 @@ export { ContinueCancelModal } from "./continue-cancel/ContinueCancelModal"; export { SelectControl } from "./controls/SelectControl"; export type { SelectControlOption } from "./controls/SelectControl"; -export { SwitchControl } from "./controls/SwitchControl"; +export { + SwitchControl, + type SwitchControlProps, +} from "./controls/SwitchControl"; export { TextControl } from "./controls/TextControl"; export { TextAreaControl } from "./controls/TextAreaControl"; export { NumberControl } from "./controls/NumberControl";