TokenRevokedModal.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { css, cx } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { Button, InfoBox, Portal, stylesFactory, useTheme2 } from '@grafana/ui';
  5. import { getModalStyles } from '@grafana/ui/src/components/Modal/getModalStyles';
  6. interface Props {
  7. maxConcurrentSessions?: number;
  8. }
  9. export const TokenRevokedModal = (props: Props) => {
  10. const theme = useTheme2();
  11. const styles = getStyles(theme);
  12. const modalStyles = getModalStyles(theme);
  13. const showMaxConcurrentSessions = Boolean(props.maxConcurrentSessions);
  14. const redirectToLogin = () => {
  15. window.location.reload();
  16. };
  17. return (
  18. <Portal>
  19. <div className={modalStyles.modal}>
  20. <InfoBox title="You have been automatically signed out" severity="warning" className={styles.infobox}>
  21. <div className={styles.text}>
  22. <p>
  23. Your session token was automatically revoked because you have reached
  24. <strong>
  25. {` the maximum number of ${
  26. showMaxConcurrentSessions ? props.maxConcurrentSessions : ''
  27. } concurrent sessions `}
  28. </strong>
  29. for your account.
  30. </p>
  31. <p>
  32. <strong>To resume your session, sign in again.</strong>
  33. Contact your administrator or visit the license page to review your quota if you are repeatedly signed out
  34. automatically.
  35. </p>
  36. </div>
  37. <Button size="md" variant="primary" onClick={redirectToLogin}>
  38. Sign in
  39. </Button>
  40. </InfoBox>
  41. </div>
  42. <div className={cx(modalStyles.modalBackdrop, styles.backdrop)} />
  43. </Portal>
  44. );
  45. };
  46. const getStyles = stylesFactory((theme: GrafanaTheme2) => {
  47. return {
  48. infobox: css`
  49. margin-bottom: 0;
  50. `,
  51. text: css`
  52. margin: ${theme.spacing(1, 0, 2)};
  53. `,
  54. backdrop: css`
  55. background-color: ${theme.colors.background.canvas};
  56. opacity: 0.8;
  57. `,
  58. };
  59. });