mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 10:16:26 +00:00
add mail sending request & add response alerts for PersonalSettingModal & fix preventDefault bug(PersonalSettingModal)
This commit is contained in:
@@ -6,6 +6,8 @@ var Catalyst = require('../Mixins/Catalyst')
|
|||||||
|
|
||||||
var AuthActions = require('../Actions/AuthActions')
|
var AuthActions = require('../Actions/AuthActions')
|
||||||
|
|
||||||
|
var AuthStore = require('../Stores/AuthStore')
|
||||||
|
|
||||||
var apiUrl = 'http://localhost:8000/'
|
var apiUrl = 'http://localhost:8000/'
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
@@ -17,6 +19,7 @@ module.exports = React.createClass({
|
|||||||
getInitialState: function () {
|
getInitialState: function () {
|
||||||
return {
|
return {
|
||||||
currentTab: 'profile',
|
currentTab: 'profile',
|
||||||
|
profileName: this.props.currentUser.profileName,
|
||||||
userName: this.props.currentUser.name,
|
userName: this.props.currentUser.name,
|
||||||
email: this.props.currentUser.email,
|
email: this.props.currentUser.email,
|
||||||
currentPassword: '',
|
currentPassword: '',
|
||||||
@@ -26,6 +29,32 @@ module.exports = React.createClass({
|
|||||||
contactContent: ''
|
contactContent: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
this.unsubscribe = AuthStore.listen(this.onListen)
|
||||||
|
},
|
||||||
|
componentWillUnmount: function () {
|
||||||
|
this.unsubscribe()
|
||||||
|
},
|
||||||
|
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 () {
|
activeProfile: function () {
|
||||||
this.setState({currentTab: 'profile'})
|
this.setState({currentTab: 'profile'})
|
||||||
},
|
},
|
||||||
@@ -39,12 +68,24 @@ module.exports = React.createClass({
|
|||||||
this.setState({currentTab: 'logout'})
|
this.setState({currentTab: 'logout'})
|
||||||
},
|
},
|
||||||
saveProfile: function () {
|
saveProfile: function () {
|
||||||
|
this.setState({
|
||||||
|
isUpdatingProfile: true,
|
||||||
|
isUpdatingProfileDone: false,
|
||||||
|
isUpdatingProfileFailed: false
|
||||||
|
}, function () {
|
||||||
AuthActions.updateProfile({
|
AuthActions.updateProfile({
|
||||||
|
profileName: this.state.profileName,
|
||||||
name: this.state.userName,
|
name: this.state.userName,
|
||||||
email: this.state.email
|
email: this.state.email
|
||||||
})
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
savePassword: function () {
|
savePassword: function () {
|
||||||
|
this.setState({
|
||||||
|
isChangingPassword: true,
|
||||||
|
isChangingPasswordDone: false,
|
||||||
|
isChangingPasswordFailed: false
|
||||||
|
})
|
||||||
if (this.state.newPassword === this.state.confirmation) {
|
if (this.state.newPassword === this.state.confirmation) {
|
||||||
request
|
request
|
||||||
.put(apiUrl + 'auth/password')
|
.put(apiUrl + 'auth/password')
|
||||||
@@ -56,21 +97,65 @@ module.exports = React.createClass({
|
|||||||
newPassword: this.state.newPassword
|
newPassword: this.state.newPassword
|
||||||
})
|
})
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err)
|
||||||
this.setState({
|
this.setState({
|
||||||
currentPassword: '',
|
currentPassword: '',
|
||||||
newPassword: '',
|
newPassword: '',
|
||||||
confirmation: ''
|
confirmation: '',
|
||||||
|
isChangingPassword: false,
|
||||||
|
isChangingPasswordDone: false,
|
||||||
|
isChangingPasswordFailed: true
|
||||||
})
|
})
|
||||||
if (err) {
|
|
||||||
console.error(err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
currentPassword: '',
|
||||||
|
newPassword: '',
|
||||||
|
confirmation: '',
|
||||||
|
isChangingPassword: false,
|
||||||
|
isChangingPasswordDone: true,
|
||||||
|
isChangingPasswordFailed: false
|
||||||
|
})
|
||||||
|
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sendEmail: function () {
|
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 () {
|
logOut: function () {
|
||||||
AuthActions.logout()
|
AuthActions.logout()
|
||||||
@@ -84,6 +169,10 @@ module.exports = React.createClass({
|
|||||||
content = (
|
content = (
|
||||||
<div className='profile'>
|
<div className='profile'>
|
||||||
<div className='profileTop'>
|
<div className='profileTop'>
|
||||||
|
<div className='profileFormRow'>
|
||||||
|
<label>Profile Name</label>
|
||||||
|
<input valueLink={this.linkState('profileName')} className='block-input' type='text' placeholder='Name'/>
|
||||||
|
</div>
|
||||||
<div className='profileFormRow'>
|
<div className='profileFormRow'>
|
||||||
<label>Name</label>
|
<label>Name</label>
|
||||||
<input valueLink={this.linkState('userName')} className='block-input' type='text' placeholder='Name'/>
|
<input valueLink={this.linkState('userName')} className='block-input' type='text' placeholder='Name'/>
|
||||||
@@ -94,6 +183,9 @@ module.exports = React.createClass({
|
|||||||
</div>
|
</div>
|
||||||
<div className='profileFormRow'>
|
<div className='profileFormRow'>
|
||||||
<button onClick={this.saveProfile} className='saveButton btn-primary'>Save</button>
|
<button onClick={this.saveProfile} className='saveButton btn-primary'>Save</button>
|
||||||
|
<p className={'alertInfo' + (this.state.isUpdatingProfile ? '' : ' hide')}>Updating profile...</p>
|
||||||
|
<p className={'alertSuccess' + (this.state.isUpdatingProfileDone ? '' : ' hide')}>Successfully updated</p>
|
||||||
|
<p className={'alertError' + (this.state.isUpdatingProfileFailed ? '' : ' hide')}>An Error occurred</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -112,6 +204,9 @@ module.exports = React.createClass({
|
|||||||
</div>
|
</div>
|
||||||
<div className='profileFormRow'>
|
<div className='profileFormRow'>
|
||||||
<button onClick={this.savePassword} className='saveButton btn-primary'>Save</button>
|
<button onClick={this.savePassword} className='saveButton btn-primary'>Save</button>
|
||||||
|
<p className={'alertInfo' + (this.state.isChangingPassword ? '' : ' hide')}>Changing password...</p>
|
||||||
|
<p className={'alertSuccess' + (this.state.isChangingPasswordDone ? '' : ' hide')}>Successfully changed</p>
|
||||||
|
<p className={'alertError' + (this.state.isChangingPasswordFailed ? '' : ' hide')}>An Error occurred</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -126,7 +221,10 @@ module.exports = React.createClass({
|
|||||||
<input valueLink={this.linkState('contactTitle')} className='block-input' type='text' placeholder='title'/>
|
<input valueLink={this.linkState('contactTitle')} className='block-input' type='text' placeholder='title'/>
|
||||||
<textarea valueLink={this.linkState('contactContent')} className='block-input' placeholder='message content'/>
|
<textarea valueLink={this.linkState('contactContent')} className='block-input' placeholder='message content'/>
|
||||||
<div className='contactFormRow'>
|
<div className='contactFormRow'>
|
||||||
<button onClick={this.sendEmail} className='saveButton btn-primary'>Send</button>
|
<button disabled={this.state.isSending} onClick={this.sendEmail} className='saveButton btn-primary'>Send</button>
|
||||||
|
<p className={'alertInfo' + (this.state.isSending ? '' : ' hide')}>Sending...</p>
|
||||||
|
<p className={'alertSuccess' + (this.state.isSendingDone ? '' : ' hide')}>Successfully sent</p>
|
||||||
|
<p className={'alertError' + (this.state.isSendingFailed ? '' : ' hide')}>An Error occurred</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ module.exports = React.createClass({
|
|||||||
if (planet != null) {
|
if (planet != null) {
|
||||||
this.transitionTo('planet', {userName: planet.userName, planetName: planet.name})
|
this.transitionTo('planet', {userName: planet.userName, planetName: planet.name})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var planets = this.props.currentUser.Planets.map(function (planet, index) {
|
var planets = this.props.currentUser.Planets.map(function (planet, index) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ module.exports = React.createClass({
|
|||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
onListen: function (res) {
|
onListen: function (res) {
|
||||||
if (res.status == null) return
|
if (res == null || res.status == null) return
|
||||||
|
|
||||||
if (res.status === 'planetCreated') {
|
if (res.status === 'planetCreated') {
|
||||||
var currentUser = this.state.currentUser
|
var currentUser = this.state.currentUser
|
||||||
|
|||||||
@@ -76,7 +76,10 @@ var AuthStore = Reflux.createStore({
|
|||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
this.trigger(null)
|
this.trigger({
|
||||||
|
status: 'userProfileUpdatingFailed',
|
||||||
|
data: err
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,26 @@
|
|||||||
input
|
input
|
||||||
float left
|
float left
|
||||||
width 250px
|
width 250px
|
||||||
|
.alertSuccess, .alertError, .alertInfo
|
||||||
|
float right
|
||||||
|
line-height 44px
|
||||||
|
border-radius 5px
|
||||||
|
transition 0.1s
|
||||||
|
overflow hidden
|
||||||
|
white-space nowrap
|
||||||
|
width 200px
|
||||||
|
text-align center
|
||||||
|
&.hide
|
||||||
|
width 0
|
||||||
|
.alertSuccess
|
||||||
|
background-color successBackgroundColor
|
||||||
|
color successTextColor
|
||||||
|
.alertError
|
||||||
|
background-color errorBackgroundColor
|
||||||
|
color errorTextColor
|
||||||
|
.alertInfo
|
||||||
|
background-color infoBackgroundColor
|
||||||
|
color infoTextColor
|
||||||
.saveButton
|
.saveButton
|
||||||
float right
|
float right
|
||||||
.contact
|
.contact
|
||||||
@@ -185,6 +205,26 @@
|
|||||||
clearfix()
|
clearfix()
|
||||||
.saveButton
|
.saveButton
|
||||||
float right
|
float right
|
||||||
|
.alertSuccess, .alertError, .alertInfo
|
||||||
|
float right
|
||||||
|
line-height 44px
|
||||||
|
border-radius 5px
|
||||||
|
transition 0.1s
|
||||||
|
overflow hidden
|
||||||
|
white-space nowrap
|
||||||
|
width 200px
|
||||||
|
text-align center
|
||||||
|
&.hide
|
||||||
|
width 0
|
||||||
|
.alertSuccess
|
||||||
|
background-color successBackgroundColor
|
||||||
|
color successTextColor
|
||||||
|
.alertError
|
||||||
|
background-color errorBackgroundColor
|
||||||
|
color errorTextColor
|
||||||
|
.alertInfo
|
||||||
|
background-color infoBackgroundColor
|
||||||
|
color infoTextColor
|
||||||
.info
|
.info
|
||||||
text-align left
|
text-align left
|
||||||
.infoLabel
|
.infoLabel
|
||||||
|
|||||||
@@ -38,3 +38,10 @@ tableEvenBgColor = white
|
|||||||
|
|
||||||
facebookColor= #3b5998
|
facebookColor= #3b5998
|
||||||
githubBtn= #201F1F
|
githubBtn= #201F1F
|
||||||
|
|
||||||
|
successBackgroundColor= #E0F0D9
|
||||||
|
successTextColor= #3E753F
|
||||||
|
errorBackgroundColor= #F2DEDE
|
||||||
|
errorTextColor= #A64444
|
||||||
|
infoBackgroundColor= #D9EDF7
|
||||||
|
infoTextColor= #34708E
|
||||||
|
|||||||
Reference in New Issue
Block a user