From 2d1baed0e9a4158472d784954c88afcf7eb81873 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 7 Apr 2022 16:35:17 +0200 Subject: [PATCH] Remove picked validators from list (#2405) --- .../user-profile/attribute/AddValidatorDialog.tsx | 10 ++++++++-- .../attribute/AddValidatorRoleDialog.tsx | 12 ++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx b/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx index 3e63fd4f5d..e1681d3cf0 100644 --- a/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx +++ b/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx @@ -10,7 +10,7 @@ import { Tr, } from "@patternfly/react-table"; import { AddValidatorRoleDialog } from "./AddValidatorRoleDialog"; -import { Validator, validators } from "./Validators"; +import { Validator, validators as allValidator } from "./Validators"; import useToggle from "../../../utils/useToggle"; export type AddValidatorDialogProps = { @@ -24,13 +24,19 @@ export const AddValidatorDialog = ({ }: AddValidatorDialogProps) => { const { t } = useTranslation("realm-settings"); const [selectedValidator, setSelectedValidator] = useState(); + const [validators, setValidators] = useState(allValidator); const [addValidatorRoleModalOpen, toggleModal] = useToggle(); return ( <> {addValidatorRoleModalOpen && ( onConfirm(newValidator)} + onConfirm={(newValidator) => { + onConfirm(newValidator); + setValidators( + validators.filter(({ name }) => name !== newValidator.name) + ); + }} open={addValidatorRoleModalOpen} toggleDialog={toggleModal} selected={selectedValidator!} diff --git a/src/realm-settings/user-profile/attribute/AddValidatorRoleDialog.tsx b/src/realm-settings/user-profile/attribute/AddValidatorRoleDialog.tsx index 8a15da6a15..dbd72e1bc7 100644 --- a/src/realm-settings/user-profile/attribute/AddValidatorRoleDialog.tsx +++ b/src/realm-settings/user-profile/attribute/AddValidatorRoleDialog.tsx @@ -23,16 +23,8 @@ export const AddValidatorRoleDialog = ({ const { handleSubmit } = form; const selectedRoleValidator = selected; - const save = () => { - const formValues = form.getValues(); - formValues.name = selectedRoleValidator.name; - - const newValidator = { - name: formValues.name, - config: formValues.config ?? [], - }; - - onConfirm(newValidator); + const save = (newValidator: Validator) => { + onConfirm({ ...newValidator, name: selected.name }); toggleDialog(); };