import { Button, DataList, DataListAction, DataListCell, DataListItem, DataListItemCells, DataListItemRow, Dropdown, DropdownItem, KebabToggle, PageSection, Spinner, Split, SplitItem, Title, } from "@patternfly/react-core"; import { CSSProperties, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { ContinueCancelModal, useAlerts } from "ui-shared"; import { deleteCredentials, getCredentials } from "../api/methods"; import { CredentialContainer, CredentialMetadataRepresentation, CredentialRepresentation, } from "../api/representations"; import { EmptyRow } from "../components/datalist/EmptyRow"; import useFormatter from "../components/format/format-date"; import { Page } from "../components/page/Page"; import { TFuncKey } from "../i18n"; import { keycloak } from "../keycloak"; import { usePromise } from "../utils/usePromise"; type MobileLinkProps = { title: string; onClick: () => void; }; const MobileLink = ({ title, onClick }: MobileLinkProps) => { const [open, setOpen] = useState(false); return ( <> } className="pf-u-display-none-on-lg" isOpen={open} dropdownItems={[ {title} , ]} /> {title} > ); }; const SigningIn = () => { const { t } = useTranslation(); const { formatDate } = useFormatter(); const { addAlert, addError } = useAlerts(); const { login } = keycloak; const [credentials, setCredentials] = useState(); const [key, setKey] = useState(1); const refresh = () => setKey(key + 1); usePromise((signal) => getCredentials({ signal }), setCredentials, [key]); const credentialRowCells = ( credMetadata: CredentialMetadataRepresentation, ) => { const credential = credMetadata.credential; const maxWidth = { "--pf-u-max-width--MaxWidth": "300px" } as CSSProperties; const items = [ {credential.userLabel || t(credential.type as TFuncKey)} , ]; if (credential.createdDate) { items.push( {{ date: formatDate(new Date(credential.createdDate)) }} , ); } return items; }; const label = (credential: CredentialRepresentation) => credential.userLabel || t(credential.type as TFuncKey); if (!credentials) { return ; } return ( {credentials.map((container) => ( {t(container.category as TFuncKey)} {t(container.displayName as TFuncKey)} {t(container.helptext as TFuncKey)} {container.createAction && ( login({ action: container.createAction, }) } title={t("setUpNew", [ t(container.displayName as TFuncKey), ])} /> )} {container.userCredentialMetadatas.length === 0 && ( )} {container.userCredentialMetadatas.map((meta) => ( {container.removeable ? ( { try { await deleteCredentials(meta.credential); addAlert( t("successRemovedMessage", { userLabel: label(meta.credential), }), ); refresh(); } catch (error) { addError( t("errorRemovedMessage", { userLabel: label(meta.credential), error, }).toString(), ); } }} /> ) : ( { if (container.updateAction) login({ action: container.updateAction }); }} > {t("update")} )} , ]} /> ))} ))} ); }; export default SigningIn;