diff --git a/packages/nylas-dashboard/public/js/app.jsx b/packages/nylas-dashboard/public/js/app.jsx index efa32b442..0a4acad2b 100644 --- a/packages/nylas-dashboard/public/js/app.jsx +++ b/packages/nylas-dashboard/public/js/app.jsx @@ -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 (
Error
+ this.clearError()}>Clear Error
               {JSON.stringify(error, null, 2)}
diff --git a/packages/nylas-dashboard/routes/account.js b/packages/nylas-dashboard/routes/account.js
new file mode 100644
index 000000000..a7c8c4fe5
--- /dev/null
+++ b/packages/nylas-dashboard/routes/account.js
@@ -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"));
+        })
+      })
+    },
+  });
+};