Remove picked validators from list (#2405)

This commit is contained in:
Erik Jan de Wit 2022-04-07 16:35:17 +02:00 committed by GitHub
parent 36cf7022f5
commit 2d1baed0e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View file

@ -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<Validator>();
const [validators, setValidators] = useState(allValidator);
const [addValidatorRoleModalOpen, toggleModal] = useToggle();
return (
<>
{addValidatorRoleModalOpen && (
<AddValidatorRoleDialog
onConfirm={(newValidator) => onConfirm(newValidator)}
onConfirm={(newValidator) => {
onConfirm(newValidator);
setValidators(
validators.filter(({ name }) => name !== newValidator.name)
);
}}
open={addValidatorRoleModalOpen}
toggleDialog={toggleModal}
selected={selectedValidator!}

View file

@ -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();
};