Commit 231fba94 authored by Paul Kaplan's avatar Paul Kaplan

Check for duplicates locally before trying to add the project to the studio

parent 4fcdf9b9
...@@ -11,13 +11,15 @@ const Errors = keyMirror({ ...@@ -11,13 +11,15 @@ const Errors = keyMirror({
SERVER: null, SERVER: null,
PERMISSION: null, PERMISSION: null,
UNKNOWN_PROJECT: null, UNKNOWN_PROJECT: null,
RATE_LIMIT: null RATE_LIMIT: null,
DUPLICATE: null
}); });
const normalizeError = (err, body, res) => { const normalizeError = (err, body, res) => {
if (err) return Errors.NETWORK; if (err) return Errors.NETWORK;
if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION; if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION;
if (res.statusCode === 404) return Errors.UNKNOWN_PROJECT; if (res.statusCode === 404) return Errors.UNKNOWN_PROJECT;
if (res.statusCode === 409) return Errors.DUPLICATE;
if (res.statusCode === 429) return Errors.RATE_LIMIT; if (res.statusCode === 429) return Errors.RATE_LIMIT;
if (res.statusCode !== 200) return Errors.SERVER; if (res.statusCode !== 200) return Errors.SERVER;
return null; return null;
...@@ -73,6 +75,11 @@ const addProject = projectIdOrUrl => ((dispatch, getState) => new Promise((resol ...@@ -73,6 +75,11 @@ const addProject = projectIdOrUrl => ((dispatch, getState) => new Promise((resol
const state = getState(); const state = getState();
const studioId = selectStudioId(state); const studioId = selectStudioId(state);
const token = selectToken(state); const token = selectToken(state);
// Check for existing duplicates before going to the server
if (projects.selector(state).items.filter(p => p.id === projectId).length !== 0) {
return reject(Errors.DUPLICATE);
}
api({ api({
uri: `/studios/${studioId}/project/${projectId}`, uri: `/studios/${studioId}/project/${projectId}`,
method: 'POST', method: 'POST',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment