summaryrefslogtreecommitdiffhomepage
path: root/app/containers/AccountPage.js
blob: 1c54167b506c53a6259b56863bf39c640d991ad9 (plain)
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
// @flow

import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { push } from 'react-router-redux';
import Account from '../components/Account';
import accountActions from '../redux/account/actions';
import { links } from '../config';
import { openLink } from '../lib/platform';

import type { ReduxState, ReduxDispatch } from '../redux/store';
import type { SharedRouteProps } from '../routes';

const mapStateToProps = (state: ReduxState) => ({
  accountToken: state.account.accountToken,
  accountExpiry: state.account.expiry,
});
const mapDispatchToProps = (dispatch: ReduxDispatch, props: SharedRouteProps) => {
  const { backend } = props;
  const { push: pushHistory } = bindActionCreators({ push }, dispatch);
  const { logout } = bindActionCreators(accountActions, dispatch);

  return {
    updateAccountExpiry: () => backend.updateAccountExpiry(),
    onLogout: () => {
      logout(backend);
    },
    onClose: () => {
      pushHistory('/settings');
    },
    onBuyMore: () => openLink(links['purchase']),
  };
};

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(Account);