settings.js 912 B

1234567891011121314151617181920212223242526272829
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4. import { decode } from 'jsonwebtoken';
  5. import BodyWrapper from '../components/BodyWrapper';
  6. import Footer from '../components/Footer';
  7. import { authUser } from '../actions';
  8. import Settings from '../components/Settings';
  9. const SettingsPage = ({ auth, isAuthenticated }) => (
  10. <BodyWrapper>
  11. {isAuthenticated ? <Settings /> : <PageLoading />}
  12. <Footer />
  13. </BodyWrapper>
  14. );
  15. SettingsPage.getInitialProps = ({ req, reduxStore }) => {
  16. const token = decode(req && req.cookies && req.cookies.token);
  17. if (token && reduxStore) reduxStore.dispatch(authUser(token));
  18. return {};
  19. };
  20. SettingsPage.propTypes = {
  21. isAuthenticated: PropTypes.bool.isRequired,
  22. };
  23. const mapStateToProps = ({ auth }) => ({ isAuthenticated: auth.isAuthenticated, auth });
  24. export default connect(mapStateToProps)(SettingsPage);