From 6864207dacbb76c0f23319044c92d5eb8e05f53b Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 28 Jun 2021 08:02:35 +0200 Subject: [PATCH] updated admin client with new endpoints (#725) --- package.json | 2 +- src/realm-settings/EmailTab.tsx | 27 +++++++++----------------- src/realm-settings/LocalizationTab.tsx | 22 +++++---------------- yarn.lock | 8 ++++---- 4 files changed, 19 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 7df37da07c..539b29acba 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@patternfly/react-table": "4.27.24", "file-saver": "^2.0.5", "i18next": "^20.3.1", - "keycloak-admin": "1.14.17", + "keycloak-admin": "1.14.18", "lodash": "^4.17.20", "moment": "^2.29.1", "react": "^16.14.0", diff --git a/src/realm-settings/EmailTab.tsx b/src/realm-settings/EmailTab.tsx index 0bc5f2485c..50d48affed 100644 --- a/src/realm-settings/EmailTab.tsx +++ b/src/realm-settings/EmailTab.tsx @@ -20,7 +20,6 @@ import { emailRegexPattern } from "../util"; import { useAdminClient } from "../context/auth/AdminClient"; import { useAlerts } from "../components/alert/Alerts"; import { useRealm } from "../context/realm-context/RealmContext"; -import { getBaseUrl } from "../util"; import "./RealmSettingsSection.css"; import type UserRepresentation from "keycloak-admin/lib/defs/userRepresentation"; @@ -121,23 +120,15 @@ export const RealmSettingsEmailTab = ({ }; const testConnection = async () => { - const response = await fetch( - `${getBaseUrl(adminClient)}admin/realms/${ - realm.realm - }/testSMTPConnection`, - { - method: "POST", - headers: { - Authorization: `bearer ${await adminClient.getAccessToken()}`, - Accept: "application/json", - "Content-Type": "application/json", - }, - body: JSON.stringify(getValues()["smtpServer"] as BodyInit), - } - ); - response.ok - ? addAlert(t("testConnectionSuccess"), AlertVariant.success) - : addAlert(t("testConnectionError"), AlertVariant.danger); + try { + await adminClient.realms.testSMTPConnection( + { realm: realm.realm! }, + getValues()["smtpServer"] || {} + ); + addAlert(t("testConnectionSuccess"), AlertVariant.success); + } catch (error) { + addAlert(t("testConnectionError"), AlertVariant.danger); + } }; return ( diff --git a/src/realm-settings/LocalizationTab.tsx b/src/realm-settings/LocalizationTab.tsx index 9557855d79..ba646a375c 100644 --- a/src/realm-settings/LocalizationTab.tsx +++ b/src/realm-settings/LocalizationTab.tsx @@ -19,7 +19,6 @@ import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { FormPanel } from "../components/scroll-form/FormPanel"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { useAdminClient } from "../context/auth/AdminClient"; -import { getBaseUrl } from "../util"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; type LocalizationTabProps = { @@ -42,7 +41,6 @@ export const LocalizationTab = ({ const [defaultLocaleOpen, setDefaultLocaleOpen] = useState(false); const { getValues, control, handleSubmit } = useFormContext(); - // const [selectedLocale, setSelectedLocale] = useState("en"); const [valueSelected, setValueSelected] = useState(false); const themeTypes = useServerInfo().themes!; @@ -60,21 +58,11 @@ export const LocalizationTab = ({ const loader = async () => { if (realm) { - const response = await fetch( - `${getBaseUrl(adminClient)}admin/realms/${realm.realm}/localization/${ - getValues("defaultLocale") || "en" - }`, - { - method: "GET", - headers: { - Authorization: `bearer ${await adminClient.getAccessToken()}`, - }, - } - ); - - const result = await response.json(); - const resultTest = Object.keys(result).map((key) => [key, result[key]]); - return resultTest; + const result = await adminClient.realms.getRealmLocalizationTexts({ + realm: realm.realm!, + selectedLocale: getValues("defaultLocale") || "en", + }); + return Object.keys(result).map((key) => [key, result[key]]); } return [[]]; }; diff --git a/yarn.lock b/yarn.lock index 11f243f7bf..6a4e30f4c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12329,10 +12329,10 @@ junk@^3.1.0: resolved "https://registry.yarnpkg.com/junk/-/junk-3.1.0.tgz#31499098d902b7e98c5d9b9c80f43457a88abfa1" integrity sha512-pBxcB3LFc8QVgdggvZWyeys+hnrNWg4OcZIU/1X59k5jQdLBlCsYGRQaz234SqoRLTCgMH00fY0xRJH+F9METQ== -keycloak-admin@1.14.17: - version "1.14.17" - resolved "https://registry.yarnpkg.com/keycloak-admin/-/keycloak-admin-1.14.17.tgz#fbeba43ae3a2d7ee6876afd334549f5675e272d8" - integrity sha512-YbGq0wXOuK5StzKdmsO/2WwfJxQmVPUpRScYETkEj7HmiE0IwECzh1OjeSXZ9lXJPFwH+lCQ6q5pNEL6/6gv9Q== +keycloak-admin@1.14.18: + version "1.14.18" + resolved "https://registry.yarnpkg.com/keycloak-admin/-/keycloak-admin-1.14.18.tgz#f6be3942d733fd4a1759665d7ff002bdee364e75" + integrity sha512-Jtj8guOrXNwyWXog8Q+Zzxemcj2yh+QxtOGDf+A2Q90lMVRL8+yR6zsKMeFFaWnoa8Z9F5LlBrL6eJFROsTJJw== dependencies: axios "^0.21.0" camelize "^1.0.0"