import { Badge, Button, Chip, Modal, ModalVariant, Text, } from "@patternfly/react-core"; import { UserCheckIcon } from "@patternfly/react-icons"; import { TableComposable, Tbody, Td, Th, Thead, Tr, } from "@patternfly/react-table"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAlerts } from "ui-shared"; import { fetchPermission, updateRequest } from "../api"; import { Permission, Resource } from "../api/representations"; type PermissionRequestProps = { resource: Resource; refresh: () => void; }; export const PermissionRequest = ({ resource, refresh, }: PermissionRequestProps) => { const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const [open, setOpen] = useState(false); const toggle = () => setOpen(!open); const approveDeny = async ( shareRequest: Permission, approve: boolean = false ) => { try { const permissions = await fetchPermission({}, resource._id); const { scopes, username } = permissions.find( (p) => p.username === shareRequest.username )!; await updateRequest( resource._id, username, approve ? [...(scopes as string[]), ...(shareRequest.scopes as string[])] : scopes ); addAlert("shareSuccess"); toggle(); refresh(); } catch (error) { addError("shareError", error); } }; return ( <> {t("close")} , ]} > {t("requestor")} {t("permissionRequests")} {resource.shareRequests.map((shareRequest) => ( {shareRequest.firstName} {shareRequest.lastName}{" "} {shareRequest.lastName ? "" : shareRequest.username}
{shareRequest.email} {shareRequest.scopes.map((scope) => ( {scope} ))} ))}
); };