index.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import styled from '@emotion/styled';
  2. import ListLink from 'sentry/components/links/listLink';
  3. import LoadingError from 'sentry/components/loadingError';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import NavTabs from 'sentry/components/navTabs';
  6. import Panel from 'sentry/components/panels/panel';
  7. import PanelBody from 'sentry/components/panels/panelBody';
  8. import PanelHeader from 'sentry/components/panels/panelHeader';
  9. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  10. import {t} from 'sentry/locale';
  11. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  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. `;