UNPKG

@keycloakify/keycloak-admin-ui

Version:
91 lines 4.49 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { AlertVariant, ButtonVariant, Chip, ChipGroup, } from "@patternfly/react-core"; import { CubesIcon } from "@patternfly/react-icons"; import { cellWidth } from "@patternfly/react-table"; import { sortBy } from "lodash-es"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../admin-client"; import { useAlerts } from "../ui-shared"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { ListEmptyState } from "../ui-shared"; import { KeycloakDataTable } from "../ui-shared"; import { emptyFormatter } from "../util"; import useFormatDate from "../utils/useFormatDate"; import { useParams } from "../utils/useParams"; export const UserConsents = () => { const { adminClient } = useAdminClient(); const [selectedClient, setSelectedClient] = useState(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const formatDate = useFormatDate(); const [key, setKey] = useState(0); const { id } = useParams(); const alphabetize = (consentsList) => { return sortBy(consentsList, (client) => { var _a; return (_a = client.clientId) === null || _a === void 0 ? void 0 : _a.toUpperCase(); }); }; const refresh = () => setKey(new Date().getTime()); const loader = async () => { const getConsents = await adminClient.users.listConsents({ id }); return alphabetize(getConsents); }; const clientScopesRenderer = ({ grantedClientScopes, }) => { return (_jsx(ChipGroup, { className: "kc-consents-chip-group", children: grantedClientScopes.map((currentChip) => (_jsx(Chip, { isReadOnly: true, className: "kc-consents-chip", children: currentChip }, currentChip))) })); }; const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: "revokeClientScopesTitle", messageKey: t("revokeClientScopes", { clientId: selectedClient === null || selectedClient === void 0 ? void 0 : selectedClient.clientId, }), continueButtonLabel: "revoke", continueButtonVariant: ButtonVariant.danger, onConfirm: async () => { try { await adminClient.users.revokeConsent({ id, clientId: selectedClient.clientId, }); refresh(); addAlert(t("deleteGrantsSuccess"), AlertVariant.success); } catch (error) { addError("deleteGrantsError", error); } }, }); return (_jsxs(_Fragment, { children: [_jsx(DeleteConfirm, {}), _jsx(KeycloakDataTable, { loader: loader, ariaLabelKey: "roleList", searchPlaceholderKey: " ", columns: [ { name: "clientId", displayKey: "Client", cellFormatters: [emptyFormatter()], transforms: [cellWidth(20)], }, { name: "grantedClientScopes", displayKey: "grantedClientScopes", cellRenderer: clientScopesRenderer, transforms: [cellWidth(30)], }, { name: "createdDate", displayKey: "created", transforms: [cellWidth(20)], cellRenderer: ({ createdDate }) => createdDate ? formatDate(new Date(createdDate)) : "—", }, { name: "lastUpdatedDate", displayKey: "lastUpdated", transforms: [cellWidth(10)], cellRenderer: ({ lastUpdatedDate }) => lastUpdatedDate ? formatDate(new Date(lastUpdatedDate)) : "—", }, ], actions: [ { title: t("revoke"), onRowClick: (client) => { setSelectedClient(client); toggleDeleteDialog(); }, }, ], emptyState: _jsx(ListEmptyState, { hasIcon: true, icon: CubesIcon, message: t("noConsents"), instructions: t("noConsentsText") }) }, key)] })); }; //# sourceMappingURL=UserConsents.js.map