Add dashboard functionality to clear sync errors

This commit is contained in:
Halla Moore 2016-07-11 16:16:33 -07:00
parent 674da27296
commit 3e6e5e95b9
2 changed files with 52 additions and 0 deletions

View file

@ -12,6 +12,27 @@ const {
} = window;
class Account extends React.Component {
constructor(props) {
super(props);
this.state = {
accountId: props.account.id,
}
}
clearError() {
const req = new XMLHttpRequest();
const url = `${window.location.protocol}/accounts/${this.state.accountId}/clear-sync-error`;
req.open("PUT", url, true);
req.onreadystatechange = () => {
if (req.readyState === XMLHttpRequest.DONE) {
if (req.status === 200) {
// Would setState here, but external updates currently refresh the account
} else {
console.error(req.responseText);
}
}
}
req.send();
}
renderError() {
const {account} = this.props;
@ -24,6 +45,7 @@ class Account extends React.Component {
return (
<div>
<div className="section">Error</div>
<span className="action-link" onClick={() => this.clearError()}>Clear Error</span>
<div className="error">
<pre>
{JSON.stringify(error, null, 2)}

View file

@ -0,0 +1,30 @@
const Joi = require('joi');
const {DatabaseConnector} = require(`nylas-core`);
module.exports = (server) => {
server.route({
method: 'PUT',
path: '/accounts/{accountId}/clear-sync-error',
config: {
description: 'Clears the sync error for the given account',
notes: 'Notes go here',
tags: ['accounts', 'sync-error'],
validate: {
params: {
accountId: Joi.number().integer(),
},
},
response: {
schema: Joi.string(),
},
},
handler: (request, reply) => {
DatabaseConnector.forShared().then(({Account}) => {
Account.find({where: {id: request.params.accountId}}).then((account) => {
account.syncError = null;
account.save().then(() => reply("Success"));
})
})
},
});
};