diff --git a/browser/main/Actions/AuthActions.js b/browser/main/Actions/AuthActions.js index f0b84f05..a9c437fe 100644 --- a/browser/main/Actions/AuthActions.js +++ b/browser/main/Actions/AuthActions.js @@ -3,5 +3,6 @@ var Reflux = require('reflux') module.exports = Reflux.createActions([ 'login', 'register', - 'logout' + 'logout', + 'updateProfile' ]) diff --git a/browser/main/Components/PersonalSettingModal.jsx b/browser/main/Components/PersonalSettingModal.jsx new file mode 100644 index 00000000..af73063a --- /dev/null +++ b/browser/main/Components/PersonalSettingModal.jsx @@ -0,0 +1,171 @@ +/* global localStorage */ +var React = require('react/addons') +var request = require('superagent') + +var Catalyst = require('../Mixins/Catalyst') + +var AuthActions = require('../Actions/AuthActions') + +var apiUrl = 'http://localhost:8000/' + +module.exports = React.createClass({ + mixins: [Catalyst.LinkedStateMixin], + propTypes: { + close: React.PropTypes.func, + currentUser: React.PropTypes.object + }, + getInitialState: function () { + return { + currentTab: 'profile', + userName: this.props.currentUser.name, + email: this.props.currentUser.email, + currentPassword: '', + newPassword: '', + confirmation: '', + contactTitle: '', + contactContent: '' + } + }, + 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 () { + AuthActions.updateProfile({ + name: this.state.userName, + email: this.state.email + }) + }, + savePassword: function () { + 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) { + this.setState({ + currentPassword: '', + newPassword: '', + confirmation: '' + }) + if (err) { + console.error(err) + return + } + + }.bind(this)) + } + }, + sendEmail: function () { + + }, + logOut: function () { + AuthActions.logout() + }, + interceptClick: function (e) { + e.stopPropagation() + }, + render: function () { + var content + if (this.state.currentTab === 'profile') { + content = ( +
+
+
+ + +
+
+ + +
+
+ +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ ) + } else if (this.state.currentTab === 'contact') { + content = ( +
+

+ Let us know your opinion about CodeXen.
+ Your feedback might be used to improvement of CodeXen. +

+ +