Added privacy settings page

This commit is contained in:
2019-06-14 18:03:27 +10:00
parent e1744d6964
commit b29cfe19d7
8 changed files with 277 additions and 5 deletions
+3 -1
View File
@@ -39,6 +39,7 @@ class CommonLinks extends React.Component {
<p className='mobile centered'><Link to='/patronlist' onClick={this.props.onClickPatronList}>Patron List</Link></p>
<p className='mobile centered'><Link to='/rules' onClick={this.props.onClickRules}>Rules</Link></p>
<p className='mobile centered'><Link to='/statistics' onClick={this.props.onClickStatistics}>Game Stats</Link></p>
<p className='mobile centered'><Link to='/privacysettings' onClick={this.props.onClickPrivacySettings}>Privacy Settings</Link></p>
<Extra />
@@ -80,7 +81,8 @@ CommonLinks.propTypes = {
onClickTaskList: PropTypes.func,
onClickPatronList: PropTypes.func,
onClickRules: PropTypes.func,
onClickStatistics: PropTypes.func
onClickStatistics: PropTypes.func,
onClickPrivacySettings: PropTypes.func
};
function mapStoreToProps(store) {
+122
View File
@@ -0,0 +1,122 @@
import React from 'react';
import PropTypes from 'prop-types';
class Signup extends React.Component {
constructor(props) {
super(props);
this.state = {
promotions: false
};
this.sendRequest('/privacysettingsrequest');
}
render() {
return (
<div className='panel'>
<form className='table noCollapse' action='/privacysettingsupdaterequest' method='post' onSubmit={this.submit.bind(this)}>
<hr />
<div className='break' />
<div className='row'>
<label className='col' htmlFor='promotions'>Allow Emails:</label>
<input className='col' id='promotions' type='checkbox' name='promotions' checked={this.state.promotions} onChange={this.updatePromotions.bind(this)} />
<div className='col double mobile hide' />
</div>
<div className='break' />
<div className='row'>
<button className='col' type='submit'>Update Privacy Settings</button>
<div className='col mobile hide' />
<div className='col double mobile hide' />
</div>
</form>
</div>
);
}
//TODO: Fix this copy/pasted crap
//gameplay functions
sendRequest(url, args = {}) { //send a unified request, using my credentials
//build the XHR
let xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
let json = JSON.parse(xhr.responseText);
this.setState({
promotions: json.promotions
});
}
else if (xhr.status === 400) {
this.setWarning(xhr.responseText);
}
}
};
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify({
id: this.props.id,
token: this.props.token,
...args
}));
}
submit(e) {
e.preventDefault();
//build the XHR
let form = e.target;
let formData = new FormData(form);
formData.append('id', this.props.id);
formData.append('token', this.props.token);
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
let json = JSON.parse(xhr.responseText);
if (this.props.onSuccess) {
this.props.onSuccess(json.msg);
}
}
else if (xhr.status === 400 && this.props.setWarning) {
this.props.setWarning(xhr.responseText);
}
}
};
//send the XHR
xhr.open('POST', form.action, true);
xhr.send(formData);
this.clearInput();
}
clearInput() {
this.setState({ promotions: false });
}
updatePromotions(evt) {
this.setState({ promotions: !this.state.promotions });
}
};
Signup.propTypes = {
id: PropTypes.number.isRequired,
token: PropTypes.number.isRequired,
setWarning: PropTypes.func,
onSuccess: PropTypes.func
};
export default Signup;