mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-01 18:44:01 +08:00
Add dashboard functionality to clear sync errors
This commit is contained in:
parent
674da27296
commit
3e6e5e95b9
2 changed files with 52 additions and 0 deletions
|
@ -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)}
|
||||
|
|
30
packages/nylas-dashboard/routes/account.js
Normal file
30
packages/nylas-dashboard/routes/account.js
Normal 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"));
|
||||
})
|
||||
})
|
||||
},
|
||||
});
|
||||
};
|
Loading…
Reference in a new issue