Skip to content

Commit

Permalink
#655: Unsubscribe-all option in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Sep 6, 2022
1 parent 61fbb8e commit f3c57c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/views/Delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class Delete extends React.Component {
}

handleDeleteOnClick () {
const confirmString = window.prompt('To delete your account, type your username or email below, then hit "OK."', '').trim().toLowerCase()
let confirmString = window.prompt('To unsubscribe from all email updates, type your username or email below, then hit "OK."', '')
if (confirmString) {
confirmString = confirmString.trim().toLowerCase()
}
if (confirmString && ((confirmString === this.state.data.usernameNormal) || (confirmString === this.state.data.email))) {
axios.delete(config.api.getUriPrefix() + '/user')
.then(res => {
Expand Down
29 changes: 28 additions & 1 deletion src/views/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Profile extends React.Component {
constructor (props) {
super(props)
this.state = {
data: { affiliation: '', name: '' },
data: { affiliation: '', name: '', usernameNormal: '', email: '' },
showEditModal: false,
requestFailedMessage: ''
}
Expand All @@ -24,6 +24,7 @@ class Profile extends React.Component {
this.handleHideModal = this.handleHideModal.bind(this)
this.handleShowModal = this.handleShowModal.bind(this)
this.handleUpdateDetails = this.handleUpdateDetails.bind(this)
this.handleUnsubscribe = this.handleUnsubscribe.bind(this)
}

handleOnChange (field, value) {
Expand Down Expand Up @@ -54,6 +55,28 @@ class Profile extends React.Component {
})
}

handleUnsubscribe () {
let confirmString = window.prompt('To unsubscribe from all email updates, type your username or email below, then hit "OK."', '')
if (confirmString) {
confirmString = confirmString.trim().toLowerCase()
}
if (confirmString && ((confirmString === this.state.data.usernameNormal) || (confirmString === this.state.data.email))) {
axios.post(config.api.getUriPrefix() + '/user/unsubscribe', {})
.then(res => {
this.setState({
data: res.data.data,
requestFailedMessage: ''
})
window.alert('Successfully unsubscribed from all email updates!')
})
.catch(err => {
this.setState({ requestFailedMessage: ErrorHandler(err) })
})
} else {
this.setState({ requestFailedMessage: 'Entered incorrect username/email!' })
}
}

componentDidMount () {
axios.get(config.api.getUriPrefix() + '/user')
.then(res => {
Expand Down Expand Up @@ -92,6 +115,10 @@ class Profile extends React.Component {
<Link to='/Token'><Button variant='primary'>Manage API Token</Button></Link>
</FormFieldWideRow>
<br />
<FormFieldWideRow className='text-center'>
<Button variant='primary' onClick={this.handleUnsubscribe}>Unsubscribe From All Email Updates</Button>
</FormFieldWideRow>
<br />
<FormFieldWideRow className='text-center'>
<Link to='/Password'><Button variant='primary'>Change password</Button></Link>
</FormFieldWideRow>
Expand Down

0 comments on commit f3c57c9

Please sign in to comment.