import { Button, DataList, DataListAction, DataListCell, DataListItem, DataListItemCells, DataListItemRow, Dropdown, DropdownItem, KebabToggle, PageSection, Spinner, Split, SplitItem, Title, } from "@patternfly/react-core"; import { TFuncKey } from "i18next"; 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 { 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} , ]} /> ); }; 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)} <span className="cred-title pf-u-display-block"> {t(container.displayName as TFuncKey)} </span> {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("successRemovedMessage"); refresh(); } catch (error) { addError("errorRemovedMessage", error); } }} /> ) : ( )} , ]} /> ))}
))}
); }; export default SigningIn;