/* global localStorage */ var React = require('react/addons') var ReactRouter = require('react-router') var Navigation = ReactRouter.Navigation var request = require('superagent') var LinkedState = require('../Mixins/LinkedState') var ProfileImage = require('./ProfileImage') var apiUrl = require('../../../config').apiUrl module.exports = React.createClass({ mixins: [LinkedState, Navigation], propTypes: { close: React.PropTypes.func, currentUser: React.PropTypes.object }, getInitialState: function () { return { currentTab: 'profile', profileName: this.props.currentUser.profileName, userName: this.props.currentUser.name, email: this.props.currentUser.email, currentPassword: '', newPassword: '', confirmation: '', contactTitle: '', contactContent: '' } }, componentDidMount: function () { }, componentWillUnmount: function () { }, onListen: function (res) { console.log(res) if (res.status === 'userProfileUpdated') { this.setState({ isUpdatingProfile: false, isUpdatingProfileDone: true, isUpdatingProfileFailed: false }) return } if (res.status === 'userProfileUpdatingFailed') { this.setState({ isUpdatingProfile: false, isUpdatingProfileDone: false, isUpdatingProfileFailed: true }) return } }, activeProfile: function () { this.setState({currentTab: 'profile'}) }, activeContact: function () { this.setState({currentTab: 'contact'}) }, activeInfo: function () { this.setState({currentTab: 'info'}) }, activeLogout: function () { this.setState({currentTab: 'logout'}) }, saveProfile: function () { }, savePassword: function () { this.setState({ isChangingPassword: true, isChangingPasswordDone: false, isChangingPasswordFailed: false }) if (this.state.newPassword === this.state.confirmation) { request .put(apiUrl + 'auth/password') .set({ Authorization: 'Bearer ' + localStorage.getItem('token') }) .send({ currentPassword: this.state.currentPassword, newPassword: this.state.newPassword }) .end(function (err, res) { if (err) { console.error(err) this.setState({ currentPassword: '', newPassword: '', confirmation: '', isChangingPassword: false, isChangingPasswordDone: false, isChangingPasswordFailed: true }) return } this.setState({ currentPassword: '', newPassword: '', confirmation: '', isChangingPassword: false, isChangingPasswordDone: true, isChangingPasswordFailed: false }) }.bind(this)) } }, sendEmail: function () { this.setState({ isSending: true, isSendingDone: false, isSendingFailed: false }, function () { request .post(apiUrl + 'mail') .set({ Authorization: 'Bearer ' + localStorage.getItem('token') }) .send({ title: this.state.contactTitle, content: this.state.contactContent }) .end(function (err, res) { if (err) { console.error(err) this.setState({ isSending: false, isSendingDone: false, isSendingFailed: true }) return } this.setState({ isSending: false, isSendingDone: true, isSendingFailed: false, contactTitle: '', contactContent: '' }) }.bind(this)) }) }, logOut: function () { localStorage.removeItem('currentUser') localStorage.removeItem('token') }, interceptClick: function (e) { e.stopPropagation() }, render: function () { var content if (this.state.currentTab === 'profile') { content = (
Updating profile...
Successfully updated
An Error occurred
Changing password...
Successfully changed
An Error occurred
Let us know your opinion about CodeXen.
Your feedback might be used to improvement of CodeXen.
Sending...
Successfully sent
An Error occurred
Are you sure to logout?