import type CredentialRepresentation from "@keycloak/keycloak-admin-client/lib/defs/credentialRepresentation"; import { AlertVariant, Button, Form, FormGroup } from "@patternfly/react-core"; import { CheckIcon, PencilAltIcon, TimesIcon } from "@patternfly/react-icons"; import { useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { adminClient } from "../../admin-client"; import { useAlerts } from "../../components/alert/Alerts"; import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput"; type UserLabelForm = { userLabel: string; }; type InlineLabelEditProps = { userId: string; credential: CredentialRepresentation; isEditable: boolean; toggle: () => void; }; export const InlineLabelEdit = ({ userId, credential, isEditable, toggle, }: InlineLabelEditProps) => { const { t } = useTranslation("users"); const { register, handleSubmit } = useForm(); const { addAlert, addError } = useAlerts(); const saveUserLabel = async (userLabel: UserLabelForm) => { try { await adminClient.users.updateCredentialLabel( { id: userId, credentialId: credential.id!, }, userLabel.userLabel || "" ); addAlert(t("updateCredentialUserLabelSuccess"), AlertVariant.success); toggle(); } catch (error) { addError("users:updateCredentialUserLabelError", error); } }; return (
{isEditable ? ( <>
) : ( <> {credential.userLabel}
); };