Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit f3c57c9

Browse files
#655: Unsubscribe-all option in profile
1 parent 61fbb8e commit f3c57c9

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/views/Delete.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ class Delete extends React.Component {
3232
}
3333

3434
handleDeleteOnClick () {
35-
const confirmString = window.prompt('To delete your account, type your username or email below, then hit "OK."', '').trim().toLowerCase()
35+
let confirmString = window.prompt('To unsubscribe from all email updates, type your username or email below, then hit "OK."', '')
36+
if (confirmString) {
37+
confirmString = confirmString.trim().toLowerCase()
38+
}
3639
if (confirmString && ((confirmString === this.state.data.usernameNormal) || (confirmString === this.state.data.email))) {
3740
axios.delete(config.api.getUriPrefix() + '/user')
3841
.then(res => {

src/views/Profile.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Profile extends React.Component {
1515
constructor (props) {
1616
super(props)
1717
this.state = {
18-
data: { affiliation: '', name: '' },
18+
data: { affiliation: '', name: '', usernameNormal: '', email: '' },
1919
showEditModal: false,
2020
requestFailedMessage: ''
2121
}
@@ -24,6 +24,7 @@ class Profile extends React.Component {
2424
this.handleHideModal = this.handleHideModal.bind(this)
2525
this.handleShowModal = this.handleShowModal.bind(this)
2626
this.handleUpdateDetails = this.handleUpdateDetails.bind(this)
27+
this.handleUnsubscribe = this.handleUnsubscribe.bind(this)
2728
}
2829

2930
handleOnChange (field, value) {
@@ -54,6 +55,28 @@ class Profile extends React.Component {
5455
})
5556
}
5657

58+
handleUnsubscribe () {
59+
let confirmString = window.prompt('To unsubscribe from all email updates, type your username or email below, then hit "OK."', '')
60+
if (confirmString) {
61+
confirmString = confirmString.trim().toLowerCase()
62+
}
63+
if (confirmString && ((confirmString === this.state.data.usernameNormal) || (confirmString === this.state.data.email))) {
64+
axios.post(config.api.getUriPrefix() + '/user/unsubscribe', {})
65+
.then(res => {
66+
this.setState({
67+
data: res.data.data,
68+
requestFailedMessage: ''
69+
})
70+
window.alert('Successfully unsubscribed from all email updates!')
71+
})
72+
.catch(err => {
73+
this.setState({ requestFailedMessage: ErrorHandler(err) })
74+
})
75+
} else {
76+
this.setState({ requestFailedMessage: 'Entered incorrect username/email!' })
77+
}
78+
}
79+
5780
componentDidMount () {
5881
axios.get(config.api.getUriPrefix() + '/user')
5982
.then(res => {
@@ -92,6 +115,10 @@ class Profile extends React.Component {
92115
<Link to='/Token'><Button variant='primary'>Manage API Token</Button></Link>
93116
</FormFieldWideRow>
94117
<br />
118+
<FormFieldWideRow className='text-center'>
119+
<Button variant='primary' onClick={this.handleUnsubscribe}>Unsubscribe From All Email Updates</Button>
120+
</FormFieldWideRow>
121+
<br />
95122
<FormFieldWideRow className='text-center'>
96123
<Link to='/Password'><Button variant='primary'>Change password</Button></Link>
97124
</FormFieldWideRow>

0 commit comments

Comments
 (0)