diff --git a/troposphere/static/js/actions/APITokenActions.js b/troposphere/static/js/actions/APITokenActions.js index 5eb52478c..83eb94bf5 100644 --- a/troposphere/static/js/actions/APITokenActions.js +++ b/troposphere/static/js/actions/APITokenActions.js @@ -1,9 +1,10 @@ import APITokenConstants from "constants/APITokenConstants"; import APIToken from "models/APIToken"; +import NotificationController from "controllers/NotificationController"; import Utils from "./Utils"; export default { - create: ({name, atmo_user}, callback) => { + create: ({name, atmo_user}, successCallback, failCallback) => { if (!name) throw new Error("Missing Token name"); if (!atmo_user) throw new Error("Missing Token author"); let apiToken = new APIToken({ @@ -18,10 +19,16 @@ export default { .save() .done(() => { Utils.dispatch(APITokenConstants.UPDATE_TOKEN, {apiToken}); - callback(apiToken); + successCallback(apiToken); }) .fail(() => { Utils.dispatch(APITokenConstants.REMOVE_TOKEN, {apiToken}); + NotificationController.error( + "Error creating token.", + "Your login might be expired. If you continue to see this error " + + "after logging in again, contact support." + ); + failCallback(apiToken); }); return apiToken; }, diff --git a/troposphere/static/js/components/modals/api_token/APITokenCreate.jsx b/troposphere/static/js/components/modals/api_token/APITokenCreate.jsx index 8af96ac02..2fa10ca13 100644 --- a/troposphere/static/js/components/modals/api_token/APITokenCreate.jsx +++ b/troposphere/static/js/components/modals/api_token/APITokenCreate.jsx @@ -37,12 +37,21 @@ export default React.createClass({ this.setState({ isSubmitting: true }); - actions.APITokenActions.create(attributes, (response) => { - this.setState({ - isSubmitting: false, - successView: true, - hash: response.changed.token - }); + actions.APITokenActions.create(attributes, this.successCallback, this.failCallback); + }, + + successCallback(response) { + this.setState({ + isSubmitting: false, + successView: true, + hash: response.changed.token + }); + }, + + failCallback(response) { + this.setState({ + isSubmitting: false, + successView: false }); },