UNPKG

@keycloakify/keycloak-account-ui

Version:

<p align="center"> <img src="https://github.com/user-attachments/assets/e31c4910-7205-441c-9a35-e134b806b3a8"> </p> <p align="center"> <i>Repackaged Keycloak Account UI</i> <br> <br> <a href="https://github.com/keycloakify/keycloak-a

39 lines 3.29 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { Badge, Button, Chip, Icon, Modal, ModalVariant, Text, } from "@patternfly/react-core"; import { UserCheckIcon } from "@patternfly/react-icons"; import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAlerts, useEnvironment } from "../ui-shared"; import { fetchPermission, updateRequest } from "../api"; export const PermissionRequest = ({ resource, refresh, }) => { var _a, _b; const { t } = useTranslation(); const context = useEnvironment(); const { addAlert, addError } = useAlerts(); const [open, setOpen] = useState(false); const toggle = () => setOpen(!open); const approveDeny = async (shareRequest, approve = false) => { try { const permissions = await fetchPermission({ context }, resource._id); const { scopes, username } = permissions.find((p) => p.username === shareRequest.username) || { scopes: [], username: shareRequest.username }; await updateRequest(context, resource._id, username, approve ? [...scopes, ...shareRequest.scopes] : scopes); addAlert(t("shareSuccess")); toggle(); refresh(); } catch (error) { addError(t("shareError", { error }).toString()); } }; return (_jsxs(_Fragment, { children: [_jsxs(Button, { variant: "link", onClick: toggle, children: [_jsx(Icon, { size: "lg", children: _jsx(UserCheckIcon, {}) }), _jsx(Badge, { children: (_a = resource.shareRequests) === null || _a === void 0 ? void 0 : _a.length })] }), _jsx(Modal, { title: t("permissionRequest", { name: resource.name }), variant: ModalVariant.large, isOpen: open, onClose: toggle, actions: [ _jsx(Button, { variant: "link", onClick: toggle, children: t("close") }, "close"), ], children: _jsxs(Table, { "aria-label": t("resources"), children: [_jsx(Thead, { children: _jsxs(Tr, { children: [_jsx(Th, { children: t("requestor") }), _jsx(Th, { children: t("permissionRequests") }), _jsx(Th, { "aria-hidden": "true" })] }) }), _jsx(Tbody, { children: (_b = resource.shareRequests) === null || _b === void 0 ? void 0 : _b.map((shareRequest) => (_jsxs(Tr, { children: [_jsxs(Td, { children: [shareRequest.firstName, " ", shareRequest.lastName, " ", shareRequest.lastName ? "" : shareRequest.username, _jsx("br", {}), _jsx(Text, { component: "small", children: shareRequest.email })] }), _jsx(Td, { children: shareRequest.scopes.map((scope) => (_jsx(Chip, { isReadOnly: true, children: scope }, scope.toString()))) }), _jsxs(Td, { children: [_jsx(Button, { onClick: () => { approveDeny(shareRequest, true); }, children: t("accept") }), _jsx(Button, { onClick: () => { approveDeny(shareRequest); }, className: "pf-v5-u-ml-sm", variant: "danger", children: t("deny") })] })] }, shareRequest.username))) })] }) })] })); }; //# sourceMappingURL=PermissionRequest.js.map