import { css } from '@emotion/css'; import { withI18n, withI18nProps } from '@lingui/react'; import React, { PureComponent } from 'react'; import { ConfirmButton, ConfirmModal, Button } from '@grafana/ui'; import { contextSrv } from 'app/core/core'; import { AccessControlAction, UserSession } from 'app/types'; interface Props extends withI18nProps { sessions: UserSession[]; onSessionRevoke: (id: number) => void; onAllSessionsRevoke: () => void; } interface State { showLogoutModal: boolean; } class BaseUserSessions extends PureComponent { forceAllLogoutButton = React.createRef(); state: State = { showLogoutModal: false, }; showLogoutConfirmationModal = () => { this.setState({ showLogoutModal: true }); }; dismissLogoutConfirmationModal = () => { this.setState({ showLogoutModal: false }, () => { this.forceAllLogoutButton.current?.focus(); }); }; onSessionRevoke = (id: number) => { return () => { this.props.onSessionRevoke(id); }; }; onAllSessionsRevoke = () => { this.setState({ showLogoutModal: false }); this.props.onAllSessionsRevoke(); }; render() { const { sessions, i18n } = this.props; const { showLogoutModal } = this.state; const logoutFromAllDevicesClass = css` margin-top: 0.8rem; `; const canLogout = contextSrv.hasPermission(AccessControlAction.UsersLogout); return ( <>

Sessions

{sessions && sessions.map((session, index) => ( ))}
Last seen Logged on IP address Browser and OS
{session.isActive ? 'Now' : session.seenAt} {i18n.date(session.createdAt, { dateStyle: 'long' })} {session.clientIp} {`${session.browser} on ${session.os} ${session.osVersion}`}
{canLogout && ( Force logout )}
{canLogout && sessions.length > 0 && ( )}
); } } export const UserSessions = withI18n()(BaseUserSessions);