adminUsers.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {Location} from 'history';
  2. import moment from 'moment';
  3. import Link from 'sentry/components/links/link';
  4. import ResultGrid from 'sentry/components/resultGrid';
  5. import {t} from 'sentry/locale';
  6. import AsyncView from 'sentry/views/asyncView';
  7. export const prettyDate = function (x) {
  8. return moment(x).format('ll');
  9. };
  10. type Row = {
  11. dateJoined: string;
  12. email: string;
  13. id: string;
  14. lastLogin: string;
  15. username: string;
  16. };
  17. type Props = {
  18. location: Location;
  19. } & AsyncView['props'];
  20. export default class AdminUsers extends AsyncView<Props> {
  21. getRow = (row: Row) => [
  22. <td key="username">
  23. <strong>
  24. <Link to={`/manage/users/${row.id}/`}>{row.username}</Link>
  25. </strong>
  26. <br />
  27. {row.email !== row.username && <small>{row.email}</small>}
  28. </td>,
  29. <td key="dateJoined" style={{textAlign: 'center'}}>
  30. {prettyDate(row.dateJoined)}
  31. </td>,
  32. <td key="lastLogin" style={{textAlign: 'center'}}>
  33. {prettyDate(row.lastLogin)}
  34. </td>,
  35. ];
  36. render() {
  37. const columns = [
  38. <th key="username">User</th>,
  39. <th key="dateJoined" style={{textAlign: 'center', width: 150}}>
  40. Joined
  41. </th>,
  42. <th key="lastLogin" style={{textAlign: 'center', width: 150}}>
  43. Last Login
  44. </th>,
  45. ];
  46. return (
  47. <div>
  48. <h3>{t('Users')}</h3>
  49. <ResultGrid
  50. path="/manage/users/"
  51. endpoint="/users/"
  52. method="GET"
  53. columns={columns}
  54. columnsForRow={this.getRow}
  55. hasSearch
  56. filters={{
  57. status: {
  58. name: 'Status',
  59. options: [
  60. ['active', 'Active'],
  61. ['disabled', 'Disabled'],
  62. ],
  63. },
  64. }}
  65. sortOptions={[['date', 'Date Joined']]}
  66. defaultSort="date"
  67. {...this.props}
  68. />
  69. </div>
  70. );
  71. }
  72. }