Permalink
Browse files

Connecting our new component

  • Loading branch information...
ionofzion committed Nov 2, 2018
1 parent 5cd66f7 commit 8ff0be4b41086305e66ac3743ebaf0908974fc1f
Showing with 48 additions and 5 deletions.
  1. +39 −5 app/containers/Admin.jsx
  2. +9 −0 assets/css/admin.css
@@ -3,14 +3,17 @@ import PropTypes from 'prop-types';
import fetchWP from '../utils/fetchWP';
import Notice from '../components/notice';
export default class Admin extends Component {
constructor(props) {
super(props);
// Set the default states
this.state = {
email: '',
savedEmail: ''
savedEmail: '',
notice: false,
};
this.fetchWP = new fetchWP({
@@ -37,7 +40,12 @@ export default class Admin extends Component {
this.fetchWP.post( 'admin', { email: this.state.email } )
.then(
(json) => this.processOkResponse(json, 'saved'),
(err) => console.log('error', err)
(err) => this.setState({
notice: {
type: 'error',
message: err.message, // The error message returned by the REST API
}
})
);
}
@@ -54,9 +62,18 @@ export default class Admin extends Component {
this.setState({
email: json.value,
savedEmail: json.value,
notice: {
type: 'success',
message: `Setting ${action} successfully.`,
}
});
} else {
console.log(`Setting was not ${action}.`, json);
this.setState({
notice: {
type: 'error',
message: `Setting was not ${action}.`,
}
});
}
}
@@ -69,7 +86,12 @@ export default class Admin extends Component {
handleSave = (event) => {
event.preventDefault();
if ( this.state.email === this.state.savedEmail ) {
console.log('Setting unchanged');
this.setState({
notice: {
type: 'warning',
message: 'Setting unchanged.',
}
});
} else {
this.updateSetting();
}
@@ -80,10 +102,22 @@ export default class Admin extends Component {
this.deleteSetting();
}
clearNotice = () => {
this.setState({
notice: false,
});
}
render() {
// Here we update the contents of the h1, and the label, type and value of the input.
let notice;
if ( this.state.notice ) {
notice = <Notice notice={this.state.notice} onDismissClick={this.clearNotice} />
}
return (
<div className="wrap">
{notice}
<form>
<h1>Contact Form Settings</h1>
@@ -0,0 +1,9 @@
.notice {
position: relative;
}
.notice_dismiss .dashicons {
position: absolute;
top: 10px;
right: 9px;
}

0 comments on commit 8ff0be4

Please sign in to comment.