aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/auth/AuthLayout.js
blob: 2741b8a15f7902c04b36cade717c0eb341b4e198 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { RouteTransition } from 'react-router-transition';
import { intlShape } from 'react-intl';

import Link from '../ui/Link';
import InfoBar from '../ui/InfoBar';

import { oneOrManyChildElements, globalError as globalErrorPropType } from '../../prop-types';
import globalMessages from '../../i18n/globalMessages';

@observer
export default class AuthLayout extends Component {
  static propTypes = {
    children: oneOrManyChildElements.isRequired,
    pathname: PropTypes.string.isRequired,
    error: globalErrorPropType.isRequired,
    isOnline: PropTypes.bool.isRequired,
    isAPIHealthy: PropTypes.bool.isRequired,
    retryHealthCheck: PropTypes.func.isRequired,
    isHealthCheckLoading: PropTypes.bool.isRequired,
  };

  static contextTypes = {
    intl: intlShape,
  };

  render() {
    const {
      children,
      pathname,
      error,
      isOnline,
      isAPIHealthy,
      retryHealthCheck,
      isHealthCheckLoading,
    } = this.props;
    const { intl } = this.context;

    return (
      <div className="auth">
        {!isOnline && (
          <InfoBar
            type="warning"
          >
            <span className="mdi mdi-flash" />
            {intl.formatMessage(globalMessages.notConnectedToTheInternet)}
          </InfoBar>
        )}
        {isOnline && !isAPIHealthy && (
          <InfoBar
            type="danger"
            ctaLabel="Try again"
            ctaLoading={isHealthCheckLoading}
            sticky
            onClick={retryHealthCheck}
          >
            <span className="mdi mdi-flash" />
            {intl.formatMessage(globalMessages.APIUnhealthy)}
          </InfoBar>
        )}
        <div className="auth__layout">
          <RouteTransition
            pathname={pathname}
            atEnter={{ opacity: 0 }}
            atLeave={{ opacity: 0 }}
            atActive={{ opacity: 1 }}
            mapStyles={styles => ({
              transform: `translateX(${styles.translateX}%)`,
              opacity: styles.opacity,
            })}
            component="span"
          >
            {/* Inject globalError into children  */}
            {React.cloneElement(children, {
              error,
            })}
          </RouteTransition>
        </div>
        {/* </div> */}
        <Link to="https://adlk.io" className="auth__adlk" target="_blank">
          <img src="./assets/images/adlk.svg" alt="" />
        </Link>
      </div>
    );
  }
}