IDPs: go to edit form after save() (#1464)

* go to edit form on create

* tests passing locally
This commit is contained in:
Jenny 2021-11-04 02:24:47 -04:00 committed by GitHub
parent 3e591da25e
commit 1faec22b4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
import React, { useMemo, useState } from "react";
import { Link, useParams } from "react-router-dom";
import { Link, useHistory, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Controller, useFieldArray, useForm } from "react-hook-form";
import {
@ -30,7 +30,10 @@ import type { IdentityProviderAddMapperParams } from "../routes/AddMapper";
import { AssociatedRolesModal } from "../../realm-roles/AssociatedRolesModal";
import type { RoleRepresentation } from "../../model/role-model";
import { useAlerts } from "../../components/alert/Alerts";
import type { IdentityProviderEditMapperParams } from "../routes/EditMapper";
import {
IdentityProviderEditMapperParams,
toIdentityProviderEditMapper,
} from "../routes/EditMapper";
import { convertFormValuesToObject, convertToFormValues } from "../../util";
import { toIdentityProvider } from "../routes/IdentityProvider";
import type IdentityProviderMapperRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderMapperRepresentation";
@ -51,6 +54,7 @@ export default function AddMapper() {
const form = useForm<IdPMapperRepresentationWithAttributes>();
const { handleSubmit, control, register, errors } = form;
const { addAlert, addError } = useAlerts();
const history = useHistory();
const { realm } = useRealm();
const adminClient = useAdminClient();
@ -116,7 +120,7 @@ export default function AddMapper() {
}
} else {
try {
await adminClient.identityProviders.createMapper({
const createdMapper = await adminClient.identityProviders.createMapper({
identityProviderMapper: {
...idpMapper,
identityProviderAlias: alias,
@ -124,7 +128,16 @@ export default function AddMapper() {
},
alias: alias!,
});
addAlert(t("mapperCreateSuccess"), AlertVariant.success);
history.push(
toIdentityProviderEditMapper({
realm,
alias,
providerId: providerId,
id: createdMapper.id,
})
);
} catch (error) {
addError(t("mapperCreateError"), error);
}