UserSessions.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { PureComponent } from 'react';
  2. import { UserSession } from 'app/types';
  3. interface Props {
  4. sessions: UserSession[];
  5. onSessionRevoke: (id: number) => void;
  6. onAllSessionsRevoke: () => void;
  7. }
  8. export class UserSessions extends PureComponent<Props> {
  9. handleSessionRevoke = (id: number) => {
  10. return () => {
  11. this.props.onSessionRevoke(id);
  12. };
  13. };
  14. handleAllSessionsRevoke = () => {
  15. this.props.onAllSessionsRevoke();
  16. };
  17. render() {
  18. const { sessions } = this.props;
  19. return (
  20. <>
  21. <h3 className="page-heading">Sessions</h3>
  22. <div className="gf-form-group">
  23. <div className="gf-form">
  24. <table className="filter-table form-inline">
  25. <thead>
  26. <tr>
  27. <th>Last seen</th>
  28. <th>Logged on</th>
  29. <th>IP address</th>
  30. <th colSpan={2}>Browser &amp; OS</th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. {sessions &&
  35. sessions.map((session, index) => (
  36. <tr key={`${session.id}-${index}`}>
  37. <td>{session.isActive ? 'Now' : session.seenAt}</td>
  38. <td>{session.createdAt}</td>
  39. <td>{session.clientIp}</td>
  40. <td>{`${session.browser} on ${session.os} ${session.osVersion}`}</td>
  41. <td>
  42. <button className="btn btn-danger btn-small" onClick={this.handleSessionRevoke(session.id)}>
  43. <i className="fa fa-power-off" />
  44. </button>
  45. </td>
  46. </tr>
  47. ))}
  48. </tbody>
  49. </table>
  50. </div>
  51. <div className="gf-form-button-row">
  52. {sessions.length > 0 && (
  53. <button className="btn btn-danger" onClick={this.handleAllSessionsRevoke}>
  54. Logout user from all devices
  55. </button>
  56. )}
  57. </div>
  58. </div>
  59. </>
  60. );
  61. }
  62. }