diff --git a/docs/refactor-todo.md b/docs/refactor-todo.md index c0329bc2..04da4929 100644 --- a/docs/refactor-todo.md +++ b/docs/refactor-todo.md @@ -10,6 +10,7 @@ queryParams of the piece_list_store should all be reflected in the url and not a - Use classNames plugin instead of if-conditional-classes - Instead of using `currentUser && currentUser.email` in an validation that checks whether we user is logged in or now, in the `UserStore` on login we set a boolean property called `isLoggedIn` that can then be used instead of `email` - Refactor AclProxy to be a generic hide/show element component. Have it take data input and a validation function to assess whether it should show or hide child elements. Move current Acl checks to another place, eg. acl_utils.js. +- Convert all fetchers to [alt.js's sources](http://alt.js.org/docs/async/) # Refactor DONE - Refactor forms to generic-declarative form component ✓ diff --git a/js/actions/user_actions.js b/js/actions/user_actions.js index 3780a802..a661b8de 100644 --- a/js/actions/user_actions.js +++ b/js/actions/user_actions.js @@ -1,37 +1,18 @@ 'use strict'; import { altUser } from '../alt'; -import UserFetcher from '../fetchers/user_fetcher'; class UserActions { constructor() { this.generateActions( - 'updateCurrentUser', - 'deleteCurrentUser' + 'fetchCurrentUser', + 'successFetchCurrentUser', + 'logoutCurrentUser', + 'successLogoutCurrentUser', + 'errorCurrentUser' ); } - - fetchCurrentUser() { - UserFetcher.fetchOne() - .then((res) => { - this.actions.updateCurrentUser(res.users[0]); - }) - .catch((err) => { - console.logGlobal(err); - this.actions.updateCurrentUser({}); - }); - } - - logoutCurrentUser() { - UserFetcher.logout() - .then(() => { - this.actions.deleteCurrentUser(); - }) - .catch((err) => { - console.logGlobal(err); - }); - } } export default altUser.createActions(UserActions); diff --git a/js/actions/whitelabel_actions.js b/js/actions/whitelabel_actions.js index a1460fb8..3d0e9d41 100644 --- a/js/actions/whitelabel_actions.js +++ b/js/actions/whitelabel_actions.js @@ -1,29 +1,16 @@ 'use strict'; import { altWhitelabel } from '../alt'; -import WhitelabelFetcher from '../fetchers/whitelabel_fetcher'; class WhitelabelActions { constructor() { this.generateActions( - 'updateWhitelabel' + 'fetchWhitelabel', + 'successFetchWhitelabel', + 'errorWhitelabel' ); } - - fetchWhitelabel() { - WhitelabelFetcher.fetch() - .then((res) => { - if(res && res.whitelabel) { - this.actions.updateWhitelabel(res.whitelabel); - } else { - this.actions.updateWhitelabel({}); - } - }) - .catch((err) => { - console.logGlobal(err); - }); - } } export default altWhitelabel.createActions(WhitelabelActions); diff --git a/js/app.js b/js/app.js index c9451e47..520bedbd 100644 --- a/js/app.js +++ b/js/app.js @@ -30,6 +30,7 @@ import GoogleAnalyticsHandler from './third_party/ga'; import RavenHandler from './third_party/raven'; import IntercomHandler from './third_party/intercom'; import NotificationsHandler from './third_party/notifications'; +import FacebookHandler from './third_party/facebook'; /* eslint-enable */ initLogging(); diff --git a/js/components/ascribe_buttons/acl_button_list.js b/js/components/ascribe_buttons/acl_button_list.js index 83495363..35e42c20 100644 --- a/js/components/ascribe_buttons/acl_button_list.js +++ b/js/components/ascribe_buttons/acl_button_list.js @@ -6,9 +6,9 @@ import UserActions from '../../actions/user_actions'; import UserStore from '../../stores/user_store'; import ConsignButton from './acls/consign_button'; +import EmailButton from './acls/email_button'; import LoanButton from './acls/loan_button'; import LoanRequestButton from './acls/loan_request_button'; -import ShareButton from './acls/share_button'; import TransferButton from './acls/transfer_button'; import UnconsignButton from './acls/unconsign_button'; @@ -41,7 +41,7 @@ let AclButtonList = React.createClass({ componentDidMount() { UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); + UserActions.fetchCurrentUser.defer(); window.addEventListener('resize', this.handleResize); window.dispatchEvent(new Event('resize')); @@ -90,7 +90,7 @@ let AclButtonList = React.createClass({ return (