From f3c57c997e720664aa714758d4509d8549f1181e Mon Sep 17 00:00:00 2001 From: Daniel Strano Date: Tue, 6 Sep 2022 14:07:55 -0400 Subject: [PATCH] #655: Unsubscribe-all option in profile --- src/views/Delete.js | 5 ++++- src/views/Profile.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/views/Delete.js b/src/views/Delete.js index 7439950c..b17ffe64 100644 --- a/src/views/Delete.js +++ b/src/views/Delete.js @@ -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 => { diff --git a/src/views/Profile.js b/src/views/Profile.js index 22c2fa47..6de96649 100644 --- a/src/views/Profile.js +++ b/src/views/Profile.js @@ -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: '' } @@ -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) { @@ -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 => { @@ -92,6 +115,10 @@ class Profile extends React.Component {
+ + + +