From 2d73c8630632ff4c51322617908365cbd6f353ae Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 22 Mar 2024 11:47:06 +0100 Subject: [PATCH] changed to use ui-shared (#27996) Signed-off-by: Erik Jan de Wit --- .../clients/tabs/InitialAccessTokenTab.ts | 10 +- .../CreateInitialAccessToken.tsx | 100 ++++++------------ 2 files changed, 36 insertions(+), 74 deletions(-) diff --git a/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/tabs/InitialAccessTokenTab.ts b/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/tabs/InitialAccessTokenTab.ts index 3109ce0702..c726035d5d 100644 --- a/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/tabs/InitialAccessTokenTab.ts +++ b/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/tabs/InitialAccessTokenTab.ts @@ -6,10 +6,9 @@ export default class InitialAccessTokenTab extends CommonPage { #emptyAction = "no-initial-access-tokens-empty-action"; #expirationNumberInput = "expiration"; - #expirationInput = 'input[name="count"]'; #expirationText = "#expiration-helper"; - #countInput = '[data-testid="count"] input'; - #countPlusBtn = '[data-testid="count"] [aria-label="Plus"]'; + #countInput = "#count input"; + #countPlusBtn = '#count [aria-label="Plus"]'; #saveBtn = "save"; goToInitialAccessTokenTab() { @@ -42,7 +41,8 @@ export default class InitialAccessTokenTab extends CommonPage { } fillNewTokenData(expiration: number, count: number) { - cy.findByTestId(this.#expirationNumberInput).clear().type(`${expiration}`); + cy.findByTestId(this.#expirationNumberInput).clear(); + cy.findByTestId(this.#expirationNumberInput).type(`${expiration}`); cy.get(this.#countInput).clear(); for (let i = 0; i < count; i++) { @@ -66,7 +66,7 @@ export default class InitialAccessTokenTab extends CommonPage { } checkCountValue(value: number) { - cy.get(this.#expirationInput).should("have.value", value); + cy.get(this.#countInput).should("have.value", value); return this; } diff --git a/js/apps/admin-ui/src/clients/initial-access/CreateInitialAccessToken.tsx b/js/apps/admin-ui/src/clients/initial-access/CreateInitialAccessToken.tsx index ee013a8692..f64c5ac090 100644 --- a/js/apps/admin-ui/src/clients/initial-access/CreateInitialAccessToken.tsx +++ b/js/apps/admin-ui/src/clients/initial-access/CreateInitialAccessToken.tsx @@ -3,32 +3,29 @@ import { ActionGroup, AlertVariant, Button, - FormGroup, - NumberInput, 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 { FormAccess } from "../../components/form/FormAccess"; -import { ViewHeader } from "../../components/view-header/ViewHeader"; -import { HelpItem } from "ui-shared"; -import { TimeSelector } from "../../components/time-selector/TimeSelector"; import { Link, useNavigate } from "react-router-dom"; +import { NumberControl } from "ui-shared"; import { adminClient } from "../../admin-client"; import { useAlerts } from "../../components/alert/Alerts"; +import { FormAccess } from "../../components/form/FormAccess"; +import { TimeSelectorControl } from "../../components/time-selector/TimeSelectorControl"; +import { ViewHeader } from "../../components/view-header/ViewHeader"; import { useRealm } from "../../context/realm-context/RealmContext"; import { toClients } from "../routes/Clients"; import { AccessTokenDialog } from "./AccessTokenDialog"; export default function CreateInitialAccessToken() { const { t } = useTranslation(); + const form = useForm({ mode: "onChange" }); const { handleSubmit, - control, - formState: { isValid, errors }, - } = useForm({ mode: "onChange" }); + formState: { isValid }, + } = form; const { realm } = useRealm(); const { addAlert, addError } = useAlerts(); @@ -49,7 +46,7 @@ export default function CreateInitialAccessToken() { }; return ( - <> + {token && ( - - } - helperTextInvalid={t("expirationValueNotValid")} - validated={errors.expiration ? "error" : "default"} - > - ( - - )} - /> - - + - } - > - ( - field.onChange(field.value + 1)} - onMinus={() => field.onChange(field.value - 1)} - onChange={(event) => { - const value = Number( - (event.target as HTMLInputElement).value, - ); - field.onChange(value < 1 ? 1 : value); - }} - /> - )} - /> - + labelIcon={t("countHelp")} + controller={{ + defaultValue: 1, + }} + min={1} + />