Use route functions for navigation in identity-providers (#1475)

This commit is contained in:
Jon Koops 2021-11-04 07:23:31 +01:00 committed by GitHub
parent f4068debb8
commit 3e591da25e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 9 deletions

View file

@ -1,5 +1,5 @@
import React from "react";
import { useHistory, useParams } from "react-router-dom";
import { Link, useHistory, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { FormProvider, useForm } from "react-hook-form";
import {
@ -19,6 +19,7 @@ import { useAlerts } from "../../components/alert/Alerts";
import { GeneralSettings } from "./GeneralSettings";
import { toIdentityProvider } from "../routes/IdentityProvider";
import type { IdentityProviderCreateParams } from "../routes/IdentityProviderCreate";
import { toIdentityProviders } from "../routes/IdentityProviders";
export default function AddIdentityProvider() {
const { t } = useTranslation("identity-providers");
@ -83,7 +84,9 @@ export default function AddIdentityProvider() {
<Button
variant="link"
data-testid="cancel"
onClick={() => history.push(`/${realm}/identity-providers`)}
component={(props) => (
<Link {...props} to={toIdentityProviders({ realm })} />
)}
>
{t("common:cancel")}
</Button>

View file

@ -1,5 +1,5 @@
import React from "react";
import { useHistory, useRouteMatch } from "react-router-dom";
import { Link, useHistory, useRouteMatch } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { FormProvider, useForm } from "react-hook-form";
import {
@ -18,6 +18,8 @@ import { OpenIdConnectSettings } from "./OpenIdConnectSettings";
import { useRealm } from "../../context/realm-context/RealmContext";
import { OIDCAuthentication } from "./OIDCAuthentication";
import { useAlerts } from "../../components/alert/Alerts";
import { toIdentityProvider } from "../routes/IdentityProvider";
import { toIdentityProviders } from "../routes/IdentityProviders";
type DiscoveryIdentity = IdentityProviderRepresentation & {
discoveryEndpoint?: string;
@ -51,7 +53,12 @@ export default function AddOpenIdConnect() {
});
addAlert(t("createSuccess"), AlertVariant.success);
history.push(
`/${realm}/identity-providers/${id}/${provider.alias}/settings`
toIdentityProvider({
realm,
providerId: id,
alias: provider.alias!,
tab: "settings",
})
);
} catch (error) {
addError("identity-providers:createError", error);
@ -87,7 +94,9 @@ export default function AddOpenIdConnect() {
<Button
variant="link"
data-testid="cancel"
onClick={() => history.push(`/${realm}/identity-providers`)}
component={(props) => (
<Link {...props} to={toIdentityProviders({ realm })} />
)}
>
{t("common:cancel")}
</Button>

View file

@ -1,5 +1,5 @@
import React from "react";
import { useHistory } from "react-router-dom";
import { Link, useHistory } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { FormProvider, useForm } from "react-hook-form";
import {
@ -17,6 +17,8 @@ import { SamlGeneralSettings } from "./SamlGeneralSettings";
import { SamlConnectSettings } from "./SamlConnectSettings";
import { useRealm } from "../../context/realm-context/RealmContext";
import { useAlerts } from "../../components/alert/Alerts";
import { toIdentityProvider } from "../routes/IdentityProvider";
import { toIdentityProviders } from "../routes/IdentityProviders";
type DiscoveryIdentityProvider = IdentityProviderRepresentation & {
discoveryEndpoint?: string;
@ -48,7 +50,12 @@ export default function AddSamlConnect() {
});
addAlert(t("createSuccess"), AlertVariant.success);
history.push(
`/${realm}/identity-providers/${id}/${provider.alias}/settings`
toIdentityProvider({
realm,
providerId: id,
alias: provider.alias!,
tab: "settings",
})
);
} catch (error: any) {
addAlert(
@ -84,7 +91,9 @@ export default function AddSamlConnect() {
<Button
variant="link"
data-testid="cancel"
onClick={() => history.push(`/${realm}/identity-providers`)}
component={(props) => (
<Link {...props} to={toIdentityProviders({ realm })} />
)}
>
{t("common:cancel")}
</Button>

View file

@ -40,6 +40,7 @@ import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState
import type IdentityProviderMapperRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderMapperRepresentation";
import { toIdentityProviderAddMapper } from "../routes/AddMapper";
import { toIdentityProviderEditMapper } from "../routes/EditMapper";
import { toIdentityProviders } from "../routes/IdentityProviders";
import { toUpperCase } from "../../util";
import {
@ -166,7 +167,7 @@ export default function DetailSettings() {
try {
await adminClient.identityProviders.del({ alias: alias });
addAlert(t("deletedSuccess"), AlertVariant.success);
history.push(`/${realm}/identity-providers`);
history.push(toIdentityProviders({ realm }));
} catch (error) {
addError("identity-providers:deleteErrorError", error);
}