import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { goBack } from 'react-router-redux';
import moment from 'moment';
import Avatar from 'components/Avatar';
import Button from 'components/buttons/Button';
import ChangePasswordForm from 'components/forms/ChangePasswordForm';
import Icon from 'components/icons/Icon';
import { logoutUser, updateUser } from 'redux/nodes/auth/actions';
import Modal from 'components/modals/Modal';
import { renderFlash } from 'redux/nodes/notifications/actions';
import userInterface from 'interfaces/user';
import UserSettingsForm from 'components/forms/UserSettingsForm';
const baseClass = 'user-settings';
export class UserSettingsPage extends Component {
static propTypes = {
dispatch: PropTypes.func.isRequired,
errors: PropTypes.shape({
username: PropTypes.string,
base: PropTypes.string,
}),
user: userInterface,
};
constructor (props) {
super(props);
this.state = { showModal: false };
}
onCancel = (evt) => {
evt.preventDefault();
const { dispatch } = this.props;
dispatch(goBack());
return false;
}
onLogout = (evt) => {
evt.preventDefault();
const { dispatch } = this.props;
dispatch(logoutUser());
return false;
}
onShowModal = (evt) => {
evt.preventDefault();
this.setState({ showModal: true });
return false;
}
onToggleModal = (evt) => {
evt.preventDefault();
const { showModal } = this.state;
this.setState({ showModal: !showModal });
return false;
}
handleSubmit = (formData) => {
const { dispatch, user } = this.props;
return dispatch(updateUser(user, formData))
.then(() => {
return dispatch(renderFlash('success', 'Account updated!'));
})
.catch(() => false);
}
handleSubmitPasswordForm = (formData) => {
console.log('Change Password Form submitted', formData);
this.setState({ showModal: false });
return false;
}
renderModal = () => {
const { showModal } = this.state;
const { handleSubmitPasswordForm, onToggleModal } = this;
if (!showModal) {
return false;
}
return (