narrowLayout.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {logout} from 'app/actionCreators/account';
  4. import {Client} from 'app/api';
  5. import {IconSentry} from 'app/icons';
  6. import {t} from 'app/locale';
  7. type Props = {
  8. showLogout?: boolean;
  9. maxWidth?: string;
  10. };
  11. class NarrowLayout extends Component<Props> {
  12. UNSAFE_componentWillMount() {
  13. document.body.classList.add('narrow');
  14. }
  15. componentWillUnmount() {
  16. this.api.clear();
  17. document.body.classList.remove('narrow');
  18. }
  19. private api = new Client();
  20. handleLogout = () => {
  21. logout(this.api).then(() => window.location.assign('/auth/login'));
  22. };
  23. render() {
  24. return (
  25. <div className="app">
  26. <div className="pattern-bg" />
  27. <div className="container" style={{maxWidth: this.props.maxWidth}}>
  28. <div className="box box-modal">
  29. <div className="box-header">
  30. <a href="/">
  31. <IconSentry size="lg" />
  32. </a>
  33. {this.props.showLogout && (
  34. <a className="logout pull-right" onClick={this.handleLogout}>
  35. <Logout>{t('Sign out')}</Logout>
  36. </a>
  37. )}
  38. </div>
  39. <div className="box-content with-padding">{this.props.children}</div>
  40. </div>
  41. </div>
  42. </div>
  43. );
  44. }
  45. }
  46. const Logout = styled('span')`
  47. font-size: 16px;
  48. `;
  49. export default NarrowLayout;