@@ -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