UNPKG

@keycloakify/keycloak-admin-ui

Version:
29 lines 1.68 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { FormErrorText, HelpItem, useFetch, } from "../../ui-shared"; import { FormGroup } from "@patternfly/react-core"; import { useState } from "react"; import { useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../../admin-client"; import { KeySelect } from "../../components/key-value-form/KeySelect"; import { convertToName } from "../../components/dynamic/DynamicComponents"; export const UserProfileAttributeListComponent = ({ name, label, helpText, required = false, }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { formState: { errors }, } = useFormContext(); const [config, setConfig] = useState(); const convertedName = convertToName(name); useFetch(() => adminClient.users.getProfile(), (cfg) => setConfig(cfg), []); const convert = (config) => { if (!(config === null || config === void 0 ? void 0 : config.attributes)) return []; return config.attributes.map((option) => ({ key: option.name, label: option.name, })); }; if (!config) return null; return (_jsxs(FormGroup, { label: t(label), isRequired: required, labelIcon: _jsx(HelpItem, { helpText: t(helpText), fieldLabelId: label }), fieldId: convertedName, children: [_jsx(KeySelect, { name: convertedName, rules: required ? { required: true } : {}, selectItems: convert(config) }), errors[convertedName] && _jsx(FormErrorText, { message: t("required") })] })); }; //# sourceMappingURL=UserProfileAttributeListComponent.js.map