Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ListErrors from './ListErrors';
- import React from 'react';
- import { Link } from 'react-router';
- import agent from '../agent';
- import { connect } from 'react-redux';
- // extract settings and current user from state
- const mapStateToProps = state => ({
- ...state.settings,
- currentUser: state.common.currentUser
- });
- const mapDispatchToProps = dispatch => ({
- // LOGOUT dispatch
- onClickLogout: () => dispatch({ type: 'LOGOUT' }),
- // SETTINGS_SAVED dispatch + settings form promise
- onSubmitForm: user =>
- dispatch({ type: 'SETTINGS_SAVED', payload: agent.Auth.save(user) })
- });
- class Settings extends React.Component {
- render() {
- return (
- <div className="settings-page">
- <div className="container page">
- <div className="row">
- <div className="col-md-6 offset-md-3 col-xs-12">
- <h1 className="text-xs-center">Your Settings</h1>
- <ListErrors errors={this.props.errors}></ListErrors>
- {/* pass props to settingsform component */}
- <SettingsForm
- currentUser={this.props.currentUser}
- onSubmitForm={this.props.onSubmitForm} />
- <hr />
- {/* logout button */}
- <button
- className="btn btn-outline-danger"
- onClick={this.props.onClickLogout}>
- Or click here to logout.
- </button>
- </div>
- </div>
- </div>
- </div>
- );
- }
- }
- export default connect(mapStateToProps, mapDispatchToProps)(Settings);
Add Comment
Please, Sign In to add comment