diff --git a/src/realm-settings/user-profile/AttributesGroupTab.tsx b/src/realm-settings/user-profile/AttributesGroupTab.tsx index fe5ac62972..601b253039 100644 --- a/src/realm-settings/user-profile/AttributesGroupTab.tsx +++ b/src/realm-settings/user-profile/AttributesGroupTab.tsx @@ -1,4 +1,3 @@ -import type UserProfileConfig from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig"; import type { UserProfileGroup } from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig"; import { Button, @@ -12,17 +11,10 @@ import { Link, useHistory } from "react-router-dom"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState"; import { KeycloakDataTable } from "../../components/table-toolbar/KeycloakDataTable"; -import type { OnSaveCallback } from "./UserProfileTab"; +import { useUserProfile } from "./UserProfileContext"; -type AttributesGroupTabProps = { - config?: UserProfileConfig; - onSave: OnSaveCallback; -}; - -export const AttributesGroupTab = ({ - config, - onSave, -}: AttributesGroupTabProps) => { +export const AttributesGroupTab = () => { + const { config, save } = useUserProfile(); const { t } = useTranslation(); const history = useHistory(); const [key, setKey] = useState(0); @@ -50,7 +42,7 @@ export const AttributesGroupTab = ({ (group) => group !== groupToDelete ); - onSave( + save( { ...config, groups }, { successMessageKey: "attributes-group:deleteSuccess", diff --git a/src/realm-settings/user-profile/JsonEditorTab.tsx b/src/realm-settings/user-profile/JsonEditorTab.tsx index 18788d1e3d..d6896b6233 100644 --- a/src/realm-settings/user-profile/JsonEditorTab.tsx +++ b/src/realm-settings/user-profile/JsonEditorTab.tsx @@ -1,4 +1,3 @@ -import type UserProfileConfig from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig"; import { CodeEditor, Language } from "@patternfly/react-code-editor"; import { ActionGroup, Button, Form, PageSection } from "@patternfly/react-core"; import type { editor } from "monaco-editor"; @@ -6,19 +5,10 @@ import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useAlerts } from "../../components/alert/Alerts"; import { prettyPrintJSON } from "../../util"; -import type { OnSaveCallback } from "./UserProfileTab"; +import { useUserProfile } from "./UserProfileContext"; -type JsonEditorTabProps = { - config?: UserProfileConfig; - onSave: OnSaveCallback; - isSaving: boolean; -}; - -export const JsonEditorTab = ({ - config, - onSave, - isSaving, -}: JsonEditorTabProps) => { +export const JsonEditorTab = () => { + const { config, save, isSaving } = useUserProfile(); const { t } = useTranslation(); const { addError } = useAlerts(); const [editor, setEditor] = useState(); @@ -29,7 +19,7 @@ export const JsonEditorTab = ({ editor?.setValue(config ? prettyPrintJSON(config) : ""); } - function save() { + function handleSave() { const value = editor?.getValue(); if (!value) { @@ -37,7 +27,7 @@ export const JsonEditorTab = ({ } try { - onSave(JSON.parse(value)); + save(JSON.parse(value)); } catch (error) { addError("realm-settings:invalidJsonError", error); return; @@ -54,7 +44,7 @@ export const JsonEditorTab = ({ />
-