aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/delayApp/Component.js
blob: ff0f1f2f8ebe4c38ada275c95b449abfd9c66525 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { inject, observer } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';
import injectSheet from 'react-jss';

import { gaEvent } from '../../lib/analytics';

import Button from '../../components/ui/Button';

import { config } from '.';
import styles from './styles';

const messages = defineMessages({
  headline: {
    id: 'feature.delayApp.headline',
    defaultMessage: '!!!Please purchase license to skip waiting',
  },
  action: {
    id: 'feature.delayApp.action',
    defaultMessage: '!!!Get a Franz Supporter License',
  },
  text: {
    id: 'feature.delayApp.text',
    defaultMessage: '!!!Franz will continue in {seconds} seconds.',
  },
});

export default @inject('actions') @injectSheet(styles) @observer class DelayApp extends Component {
  static propTypes = {
    // eslint-disable-next-line
    classes: PropTypes.object.isRequired,
  };

  static contextTypes = {
    intl: intlShape,
  };

  state = {
    countdown: config.delayDuration,
  };

  countdownInterval = null;

  countdownIntervalTimeout = 1000;

  componentDidMount() {
    this.countdownInterval = setInterval(() => {
      this.setState(prevState => ({
        countdown: prevState.countdown - this.countdownIntervalTimeout,
      }));

      if (this.state.countdown <= 0) {
        // reload();
        clearInterval(this.countdownInterval);
      }
    }, this.countdownIntervalTimeout);
  }

  componentWillUnmount() {
    clearInterval(this.countdownInterval);
  }

  handleCTAClick() {
    const { actions } = this.props;

    actions.ui.openSettings({ path: 'user' });

    gaEvent('DelayApp', 'subscribe_click', 'Delay App Feature');
  }

  render() {
    const { classes } = this.props;
    const { intl } = this.context;

    return (
      <div className={`${classes.container}`}>
        <h1 className={classes.headline}>{intl.formatMessage(messages.headline)}</h1>
        <Button
          label={intl.formatMessage(messages.action)}
          className={classes.button}
          buttonType="inverted"
          onClick={this.handleCTAClick.bind(this)}
        />
        <p className="footnote">
          {intl.formatMessage(messages.text, {
            seconds: this.state.countdown / 1000,
          })}
        </p>
      </div>
    );
  }
}

DelayApp.wrappedComponent.propTypes = {
  actions: PropTypes.shape({
    ui: PropTypes.shape({
      openSettings: PropTypes.func.isRequired,
    }).isRequired,
  }).isRequired,
};