Use realm id instead of realm name as parentId (#2836)

This commit is contained in:
Erik Jan de Wit 2022-06-22 10:50:47 +02:00 committed by GitHub
parent 60fc598a08
commit ea4f122a73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
import React from "react"; import React, { useState } from "react";
import { useHistory, useParams } from "react-router-dom"; import { Link, useHistory, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { FormProvider, useForm } from "react-hook-form"; import { FormProvider, useForm } from "react-hook-form";
import { import {
@ -41,7 +41,8 @@ export default function CustomProviderSettings() {
const adminClient = useAdminClient(); const adminClient = useAdminClient();
const { addAlert, addError } = useAlerts(); const { addAlert, addError } = useAlerts();
const { realm } = useRealm(); const { realm: realmName } = useRealm();
const [parentId, setParentId] = useState("");
useFetch( useFetch(
async () => { async () => {
@ -60,17 +61,26 @@ export default function CustomProviderSettings() {
[] []
); );
useFetch(
() =>
adminClient.realms.findOne({
realm: realmName,
}),
(realm) => setParentId(realm?.id!),
[]
);
const save = async (component: ComponentRepresentation) => { const save = async (component: ComponentRepresentation) => {
const saveComponent = { const saveComponent = {
...component, ...component,
providerId, providerId,
providerType: "org.keycloak.storage.UserStorageProvider", providerType: "org.keycloak.storage.UserStorageProvider",
parentId: realm, parentId,
}; };
try { try {
if (!id) { if (!id) {
await adminClient.components.create(saveComponent); await adminClient.components.create(saveComponent);
history.push(toUserFederation({ realm })); history.push(toUserFederation({ realm: realmName }));
} else { } else {
await adminClient.components.update({ id }, saveComponent); await adminClient.components.update({ id }, saveComponent);
} }
@ -128,7 +138,9 @@ export default function CustomProviderSettings() {
</Button> </Button>
<Button <Button
variant="link" variant="link"
onClick={() => history.push(toUserFederation({ realm }))} component={(props) => (
<Link {...props} to={toUserFederation({ realm: realmName })} />
)}
data-testid="custom-cancel" data-testid="custom-cancel"
> >
{t("common:cancel")} {t("common:cancel")}