import { Button, DataList, DataListCell, DataListContent, DataListItem, DataListItemCells, DataListItemRow, DataListToggle, DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm, Grid, GridItem, Spinner, } from "@patternfly/react-core"; import { CheckIcon, ExternalLinkAltIcon, InfoAltIcon, } from "@patternfly/react-icons"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { ContinueCancelModal, useAlerts } from "ui-shared"; import { deleteConsent, getApplications } from "../api/methods"; import { ClientRepresentation } from "../api/representations"; import { Page } from "../components/page/Page"; import { TFuncKey } from "../i18n"; import { usePromise } from "../utils/usePromise"; type Application = ClientRepresentation & { open: boolean; }; const Applications = () => { const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const [applications, setApplications] = useState(); const [key, setKey] = useState(1); const refresh = () => setKey(key + 1); usePromise( (signal) => getApplications({ signal }), (clients) => setApplications(clients.map((c) => ({ ...c, open: false }))), [key] ); const toggleOpen = (clientId: string) => { setApplications([ ...applications!.map((a) => a.clientId === clientId ? { ...a, open: !a.open } : a ), ]); }; const removeConsent = async (id: string) => { try { await deleteConsent(id); refresh(); addAlert(t("removeConsentSuccess")); } catch (error) { addError(t("removeConsentError", { error }).toString()); } }; if (!applications) { return ; } return ( {t("name")} , {t("applicationType")} , {t("status")} , ]} /> {applications.map((application) => ( toggleOpen(application.clientId)} isExpanded={application.open} id={`toggle-${application.clientId}`} /> , {application.userConsentRequired ? t("thirdPartyApp") : t("internalApp")} {application.offlineAccess ? ", " + t("offlineAccess") : ""} , {application.inUse ? t("inUse") : t("notInUse")} , ]} /> {t("client")} {application.clientId} {application.description && ( {t("description")} {application.description} )} {application.effectiveUrl && ( URL {application.effectiveUrl.split('"')} )} {application.consent && ( <> {t("hasAccessTo")} {application.consent.grantedScopes.map((scope) => ( {t(scope.name as TFuncKey)} ))} {application.tosUri && ( {t("termsOfService")} {application.tosUri} )} {application.policyUri && ( {t("privacyPolicy")} {application.policyUri} )} {application.logoUri && ( {t("logo")} )} {t("accessGrantedOn") + ": "} {new Intl.DateTimeFormat("en", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric", }).format(application.consent.createdDate)} )} {(application.consent || application.offlineAccess) && (
removeConsent(application.clientId)} // required /> {t("infoMessage")}
)}
))}
); }; export default Applications;