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