index.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import type {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import ListLink from 'sentry/components/links/listLink';
  4. import LoadingError from 'sentry/components/loadingError';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import NavTabs from 'sentry/components/navTabs';
  7. import Panel from 'sentry/components/panels/panel';
  8. import PanelBody from 'sentry/components/panels/panelBody';
  9. import PanelHeader from 'sentry/components/panels/panelHeader';
  10. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  11. import {t} from 'sentry/locale';
  12. import type {InternetProtocol} from 'sentry/types/user';
  13. import {useApiQuery} from 'sentry/utils/queryClient';
  14. import recreateRoute from 'sentry/utils/recreateRoute';
  15. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  16. import SessionRow from './sessionRow';
  17. import {tableLayout} from './utils';
  18. type Props = RouteComponentProps<{}, {}>;
  19. type IpListType = Array<InternetProtocol> | null;
  20. function SessionHistory({routes, params, location}: Props) {
  21. const {
  22. data: ipList,
  23. isPending,
  24. isError,
  25. } = useApiQuery<IpListType>(['/users/me/ips/'], {staleTime: 0});
  26. if (isError) {
  27. return <LoadingError />;
  28. }
  29. if (isPending) {
  30. return <LoadingIndicator />;
  31. }
  32. if (!ipList) {
  33. return null;
  34. }
  35. const recreateRouteProps = {routes, params, location};
  36. return (
  37. <SentryDocumentTitle title={t('Session History')}>
  38. <SettingsPageHeader
  39. title={t('Security')}
  40. tabs={
  41. <NavTabs underlined>
  42. <ListLink to={recreateRoute('', {...recreateRouteProps, stepBack: -1})} index>
  43. {t('Settings')}
  44. </ListLink>
  45. <ListLink to={recreateRoute('', recreateRouteProps)}>
  46. {t('Session History')}
  47. </ListLink>
  48. </NavTabs>
  49. }
  50. />
  51. <Panel>
  52. <SessionPanelHeader>
  53. <div>{t('Sessions')}</div>
  54. <div>{t('First Seen')}</div>
  55. <div>{t('Last Seen')}</div>
  56. </SessionPanelHeader>
  57. <PanelBody>
  58. {ipList.map(({id, ...ipObj}) => (
  59. <SessionRow key={id} {...ipObj} />
  60. ))}
  61. </PanelBody>
  62. </Panel>
  63. </SentryDocumentTitle>
  64. );
  65. }
  66. export default SessionHistory;
  67. const SessionPanelHeader = styled(PanelHeader)`
  68. ${tableLayout}
  69. justify-content: initial;
  70. `;