UNPKG

@keycloakify/keycloak-admin-ui

Version:
66 lines 3.14 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { Button, Modal, ModalVariant, Label } from "@patternfly/react-core"; import { InfoCircleIcon } from "@patternfly/react-icons"; import { differenceBy } from "lodash-es"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../admin-client"; import { useAlerts } from "../ui-shared"; import { ListEmptyState } from "../ui-shared"; import { KeycloakDataTable } from "../ui-shared"; import { emptyFormatter } from "../util"; const UserDetail = (user) => { const { t } = useTranslation(); return (_jsxs(_Fragment, { children: [user.username, " ", !user.enabled && (_jsx(Label, { color: "red", icon: _jsx(InfoCircleIcon, {}), children: t("disabled") }))] })); }; export const MemberModal = ({ membersQuery, onAdd, onClose, }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { addError } = useAlerts(); const [selectedRows, setSelectedRows] = useState([]); const loader = async (first, max, search) => { const members = await membersQuery(first, max); const params = { first: first, max: max + members.length, search: search || "", }; try { const users = await adminClient.users.find({ ...params }); return differenceBy(users, members, "id").slice(0, max); } catch (error) { addError("noUsersFoundError", error); return []; } }; return (_jsx(Modal, { variant: ModalVariant.large, title: t("addMember"), isOpen: true, onClose: onClose, actions: [ _jsx(Button, { "data-testid": "add", variant: "primary", onClick: async () => { await onAdd(selectedRows); onClose(); }, children: t("add") }, "confirm"), _jsx(Button, { "data-testid": "cancel", variant: "link", onClick: onClose, children: t("cancel") }, "cancel"), ], children: _jsx(KeycloakDataTable, { loader: loader, isPaginated: true, ariaLabelKey: "titleUsers", searchPlaceholderKey: "searchForUser", canSelectAll: true, onSelect: (rows) => setSelectedRows([...rows]), emptyState: _jsx(ListEmptyState, { message: t("noUsersFound"), instructions: t("emptyInstructions") }), columns: [ { name: "username", displayKey: "username", cellRenderer: UserDetail, }, { name: "email", displayKey: "email", cellFormatters: [emptyFormatter()], }, { name: "lastName", displayKey: "lastName", cellFormatters: [emptyFormatter()], }, { name: "firstName", displayKey: "firstName", cellFormatters: [emptyFormatter()], }, ] }) })); }; //# sourceMappingURL=MembersModal.js.map