AllenYuan

settings scaffold

May 5th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ListErrors from './ListErrors';
  2. import React from 'react';
  3. import { Link } from 'react-router';
  4. import agent from '../agent';
  5. import { connect } from 'react-redux';
  6.  
  7. // extract settings and current user from state
  8. const mapStateToProps = state => ({
  9.   ...state.settings,
  10.   currentUser: state.common.currentUser
  11. });
  12.  
  13. const mapDispatchToProps = dispatch => ({
  14.   // LOGOUT dispatch
  15.   onClickLogout: () => dispatch({ type: 'LOGOUT' }),
  16.   // SETTINGS_SAVED dispatch + settings form promise
  17.   onSubmitForm: user =>
  18.     dispatch({ type: 'SETTINGS_SAVED', payload: agent.Auth.save(user) })
  19. });
  20.  
  21. class Settings extends React.Component {
  22.   render() {
  23.     return (
  24.       <div className="settings-page">
  25.         <div className="container page">
  26.           <div className="row">
  27.             <div className="col-md-6 offset-md-3 col-xs-12">
  28.               <h1 className="text-xs-center">Your Settings</h1>
  29.               <ListErrors errors={this.props.errors}></ListErrors>
  30.               {/* pass props to settingsform component */}
  31.               <SettingsForm
  32.                 currentUser={this.props.currentUser}
  33.                 onSubmitForm={this.props.onSubmitForm} />
  34.               <hr />
  35.               {/* logout button */}
  36.               <button
  37.                 className="btn btn-outline-danger"
  38.                 onClick={this.props.onClickLogout}>
  39.                 Or click here to logout.
  40.               </button>
  41.             </div>
  42.           </div>
  43.         </div>
  44.       </div>
  45.     );
  46.   }
  47. }
  48.  
  49. export default connect(mapStateToProps, mapDispatchToProps)(Settings);
Add Comment
Please, Sign In to add comment