mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Load current user and whitelabel settings in AscribeApp
This commit is contained in:
parent
19841ce6c4
commit
d622ddac06
@ -2,10 +2,18 @@
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Header from '../components/header';
|
||||
import Footer from '../components/footer';
|
||||
import UserActions from '../actions/user_actions';
|
||||
import UserStore from '../stores/user_store';
|
||||
|
||||
import WhitelabelActions from '../actions/whitelabel_actions';
|
||||
import WhitelabelStore from '../stores/whitelabel_store';
|
||||
|
||||
import Header from './header';
|
||||
import Footer from './footer';
|
||||
import GlobalNotification from './global_notification';
|
||||
|
||||
import { mergeOptions } from '../utils/general_utils';
|
||||
|
||||
|
||||
let AscribeApp = React.createClass({
|
||||
propTypes: {
|
||||
@ -16,15 +24,48 @@ let AscribeApp = React.createClass({
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object)
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
WhitelabelStore.getState()
|
||||
);
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
WhitelabelStore.listen(this.onChange);
|
||||
|
||||
UserActions.fetchCurrentUser();
|
||||
WhitelabelActions.fetchWhitelabel();
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
UserStore.unlisten(this.onChange);
|
||||
WhitelabelActions.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
},
|
||||
|
||||
render() {
|
||||
let { children, routes } = this.props;
|
||||
const { children, routes } = this.props;
|
||||
const { currentUser, whitelabel } = this.state;
|
||||
|
||||
// Add the current user and whitelabel settings to all child routes
|
||||
const childrenWithProps = React.Children.map(children, (child) => {
|
||||
return React.cloneElement(child, {
|
||||
currentUser,
|
||||
whitelabel
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="container ascribe-default-app">
|
||||
<Header routes={routes} />
|
||||
{/* Routes are injected here */}
|
||||
<div className="ascribe-body">
|
||||
{children}
|
||||
{/* Routes are injected here */}
|
||||
{childrenWithProps}
|
||||
</div>
|
||||
<Footer />
|
||||
<GlobalNotification />
|
||||
|
@ -9,16 +9,12 @@ import { ResourceNotFoundError } from '../../models/errors';
|
||||
import EditionActions from '../../actions/edition_actions';
|
||||
import EditionStore from '../../stores/edition_store';
|
||||
|
||||
import UserActions from '../../actions/user_actions';
|
||||
import UserStore from '../../stores/user_store';
|
||||
|
||||
import Edition from './edition';
|
||||
|
||||
import AscribeSpinner from '../ascribe_spinner';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
import { setDocumentTitle } from '../../utils/dom_utils';
|
||||
import { mergeOptions } from '../../utils/general_utils';
|
||||
|
||||
|
||||
/**
|
||||
@ -28,21 +24,24 @@ let EditionContainer = React.createClass({
|
||||
propTypes: {
|
||||
actionPanelButtonListType: React.PropTypes.func,
|
||||
furtherDetailsType: React.PropTypes.func,
|
||||
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object,
|
||||
params: React.PropTypes.object
|
||||
},
|
||||
|
||||
mixins: [History, ReactError],
|
||||
|
||||
getInitialState() {
|
||||
return mergeOptions(
|
||||
EditionStore.getState(),
|
||||
UserStore.getState()
|
||||
);
|
||||
return EditionStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
EditionStore.listen(this.onChange);
|
||||
UserStore.listen(this.onChange);
|
||||
|
||||
// Every time we're entering the edition detail page,
|
||||
// just reset the edition that is saved in the edition store
|
||||
@ -50,21 +49,19 @@ let EditionContainer = React.createClass({
|
||||
// the edition detail a second time
|
||||
EditionActions.flushEdition();
|
||||
EditionActions.fetchEdition(this.props.params.editionId);
|
||||
|
||||
UserActions.fetchCurrentUser();
|
||||
},
|
||||
|
||||
// This is done to update the container when the user clicks on the prev or next
|
||||
// button to update the URL parameter (and therefore to switch pieces)
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if(this.props.params.editionId !== nextProps.params.editionId) {
|
||||
if (this.props.params.editionId !== nextProps.params.editionId) {
|
||||
EditionActions.fetchEdition(this.props.params.editionId);
|
||||
}
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
const { editionMeta } = this.state;
|
||||
if(editionMeta.err && editionMeta.err.json && editionMeta.err.json.status === 404) {
|
||||
if (editionMeta.err && editionMeta.err.json && editionMeta.err.json.status === 404) {
|
||||
this.throws(new ResourceNotFoundError(getLangText("Oops, the edition you're looking for doesn't exist.")));
|
||||
}
|
||||
},
|
||||
@ -72,7 +69,6 @@ let EditionContainer = React.createClass({
|
||||
componentWillUnmount() {
|
||||
window.clearInterval(this.state.timerId);
|
||||
EditionStore.unlisten(this.onChange);
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
@ -88,8 +84,8 @@ let EditionContainer = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
const { edition, currentUser, coaMeta } = this.state;
|
||||
const { actionPanelButtonListType, furtherDetailsType } = this.props;
|
||||
const { edition, coaMeta } = this.state;
|
||||
const { actionPanelButtonListType, currentUser, furtherDetailsType } = this.props;
|
||||
|
||||
if (Object.keys(edition).length && edition.id) {
|
||||
setDocumentTitle([edition.artist_name, edition.title].join(', '));
|
||||
|
@ -54,6 +54,13 @@ import { setDocumentTitle } from '../../utils/dom_utils';
|
||||
let PieceContainer = React.createClass({
|
||||
propTypes: {
|
||||
furtherDetailsType: React.PropTypes.func,
|
||||
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object,
|
||||
params: React.PropTypes.object
|
||||
},
|
||||
|
||||
@ -67,7 +74,6 @@ let PieceContainer = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
PieceListStore.getState(),
|
||||
PieceStore.getState(),
|
||||
{
|
||||
@ -77,7 +83,6 @@ let PieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
PieceListStore.listen(this.onChange);
|
||||
PieceStore.listen(this.onChange);
|
||||
|
||||
@ -87,7 +92,6 @@ let PieceContainer = React.createClass({
|
||||
PieceActions.updatePiece({});
|
||||
|
||||
this.loadPiece();
|
||||
UserActions.fetchCurrentUser();
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
@ -100,7 +104,6 @@ let PieceContainer = React.createClass({
|
||||
|
||||
componentWillUnmount() {
|
||||
PieceStore.unlisten(this.onChange);
|
||||
UserStore.unlisten(this.onChange);
|
||||
PieceListStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
@ -201,7 +204,8 @@ let PieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
getActions() {
|
||||
const { piece, currentUser } = this.state;
|
||||
const { piece } = this.state;
|
||||
const { currentUser } = this.props;
|
||||
|
||||
if (piece && piece.notifications && piece.notifications.length > 0) {
|
||||
return (
|
||||
@ -284,19 +288,19 @@ let PieceContainer = React.createClass({
|
||||
</CollapsibleParagraph>
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Notes')}
|
||||
show={!!(this.state.currentUser.username
|
||||
show={!!(this.props.currentUser.username
|
||||
|| this.state.piece.acl.acl_edit
|
||||
|| this.state.piece.public_note)}>
|
||||
<Note
|
||||
id={this.getId}
|
||||
label={getLangText('Personal note (private)')}
|
||||
defaultValue={this.state.piece.private_note || null}
|
||||
show = {!!this.state.currentUser.username}
|
||||
show = {!!this.props.currentUser.username}
|
||||
placeholder={getLangText('Enter your comments ...')}
|
||||
editable={true}
|
||||
successMessage={getLangText('Private note saved')}
|
||||
url={ApiUrls.note_private_piece}
|
||||
currentUser={this.state.currentUser}/>
|
||||
currentUser={this.props.currentUser}/>
|
||||
<Note
|
||||
id={this.getId}
|
||||
label={getLangText('Personal note (public)')}
|
||||
@ -306,7 +310,7 @@ let PieceContainer = React.createClass({
|
||||
show={!!(this.state.piece.public_note || this.state.piece.acl.acl_edit)}
|
||||
successMessage={getLangText('Public note saved')}
|
||||
url={ApiUrls.note_public_piece}
|
||||
currentUser={this.state.currentUser}/>
|
||||
currentUser={this.props.currentUser}/>
|
||||
</CollapsibleParagraph>
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Further Details')}
|
||||
|
@ -5,7 +5,6 @@ import { RouteContext } from 'react-router';
|
||||
import history from '../../history';
|
||||
|
||||
import UserStore from '../../stores/user_store';
|
||||
import UserActions from '../../actions/user_actions';
|
||||
|
||||
import AppConstants from '../../constants/application_constants';
|
||||
|
||||
@ -35,23 +34,22 @@ export function AuthRedirect({to, when}) {
|
||||
//
|
||||
// So if when === 'loggedIn', we're checking if the user is logged in (and
|
||||
// vice versa)
|
||||
let exprToValidate = when === 'loggedIn' ? currentUser && currentUser.email
|
||||
: currentUser && !currentUser.email;
|
||||
const exprToValidate = when === 'loggedIn' ? currentUser && currentUser.email
|
||||
: currentUser && !currentUser.email;
|
||||
|
||||
// and redirect if `true`.
|
||||
if(exprToValidate) {
|
||||
if (exprToValidate) {
|
||||
window.setTimeout(() => history.replaceState(null, to, query));
|
||||
return true;
|
||||
|
||||
// Otherwise there can also be the case that the backend
|
||||
// wants to redirect the user to a specific route when the user is logged out already
|
||||
} else if(!exprToValidate && when === 'loggedIn' && redirect) {
|
||||
|
||||
} else if (!exprToValidate && when === 'loggedIn' && redirect) {
|
||||
delete query.redirect;
|
||||
window.setTimeout(() => history.replaceState(null, '/' + redirect, query));
|
||||
return true;
|
||||
|
||||
} else if(!exprToValidate && when === 'loggedOut' && redirectAuthenticated) {
|
||||
} else if (!exprToValidate && when === 'loggedOut' && redirectAuthenticated) {
|
||||
/*
|
||||
* redirectAuthenticated contains an arbitrary path
|
||||
* eg pieces/<id>, editions/<bitcoin_id>, collection, settings, ...
|
||||
@ -64,6 +62,7 @@ export function AuthRedirect({to, when}) {
|
||||
window.location = AppConstants.baseUrl + redirectAuthenticated;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
@ -81,6 +80,7 @@ export function ProxyHandler(...redirectFunctions) {
|
||||
displayName: 'ProxyHandler',
|
||||
|
||||
propTypes: {
|
||||
currentUser: object,
|
||||
location: object
|
||||
},
|
||||
|
||||
@ -88,40 +88,22 @@ export function ProxyHandler(...redirectFunctions) {
|
||||
// to use the `Lifecycle` widget in further down nested components
|
||||
mixins: [RouteContext],
|
||||
|
||||
getInitialState() {
|
||||
return UserStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
UserActions.fetchCurrentUser();
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
if(!UserStore.isLoading()) {
|
||||
const { currentUser } = this.state;
|
||||
const { query } = this.props.location;
|
||||
const { currentUser, location: { query } } = this.props;
|
||||
|
||||
for(let i = 0; i < redirectFunctions.length; i++) {
|
||||
if (!UserStore.isLoading()) {
|
||||
for (let i = 0; i < redirectFunctions.length; i++) {
|
||||
// if a redirectFunction redirects the user,
|
||||
// it should return `true` and therefore
|
||||
// stop/avoid the execution of all functions
|
||||
// that follow
|
||||
if(redirectFunctions[i](currentUser, query)) {
|
||||
if (redirectFunctions[i](currentUser, query)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Component {...this.props}/>
|
||||
|
@ -29,29 +29,24 @@ import { mergeOptions, truncateTextAtCharIndex } from '../../utils/general_utils
|
||||
|
||||
let ContractSettings = React.createClass({
|
||||
propTypes: {
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
getInitialState(){
|
||||
return mergeOptions(
|
||||
ContractListStore.getState(),
|
||||
UserStore.getState()
|
||||
);
|
||||
getInitialState() {
|
||||
return ContractListStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
ContractListStore.listen(this.onChange);
|
||||
UserStore.listen(this.onChange);
|
||||
WhitelabelStore.listen(this.onChange);
|
||||
|
||||
WhitelabelActions.fetchWhitelabel();
|
||||
UserActions.fetchCurrentUser();
|
||||
ContractListActions.fetchContractList(true);
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
WhitelabelStore.unlisten(this.onChange);
|
||||
UserStore.unlisten(this.onChange);
|
||||
ContractListStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
@ -74,22 +69,23 @@ let ContractSettings = React.createClass({
|
||||
};
|
||||
},
|
||||
|
||||
getPublicContracts(){
|
||||
getPublicContracts() {
|
||||
return this.state.contractList.filter((contract) => contract.is_public);
|
||||
},
|
||||
|
||||
getPrivateContracts(){
|
||||
getPrivateContracts() {
|
||||
return this.state.contractList.filter((contract) => !contract.is_public);
|
||||
},
|
||||
|
||||
render() {
|
||||
let publicContracts = this.getPublicContracts();
|
||||
let privateContracts = this.getPrivateContracts();
|
||||
const { currentUser, location, whitelabel } = this.props;
|
||||
const publicContracts = this.getPublicContracts();
|
||||
const privateContracts = this.getPrivateContracts();
|
||||
let createPublicContractForm = null;
|
||||
|
||||
setDocumentTitle(getLangText('Contracts settings'));
|
||||
|
||||
if(publicContracts.length === 0) {
|
||||
if (publicContracts.length === 0) {
|
||||
createPublicContractForm = (
|
||||
<CreateContractForm
|
||||
isPublic={true}
|
||||
@ -97,7 +93,7 @@ let ContractSettings = React.createClass({
|
||||
singular: 'new contract',
|
||||
plural: 'new contracts'
|
||||
}}
|
||||
location={this.props.location}/>
|
||||
location={location} />
|
||||
);
|
||||
}
|
||||
|
||||
@ -108,7 +104,7 @@ let ContractSettings = React.createClass({
|
||||
defaultExpanded={true}>
|
||||
<AclProxy
|
||||
aclName="acl_edit_public_contract"
|
||||
aclObject={this.state.currentUser.acl}>
|
||||
aclObject={currentUser.acl}>
|
||||
<div>
|
||||
{createPublicContractForm}
|
||||
{publicContracts.map((contract, i) => {
|
||||
@ -120,11 +116,11 @@ let ContractSettings = React.createClass({
|
||||
buttons={
|
||||
<div className="pull-right">
|
||||
<AclProxy
|
||||
aclObject={this.state.whitelabel}
|
||||
aclObject={whitelabel}
|
||||
aclName="acl_update_public_contract">
|
||||
<ContractSettingsUpdateButton
|
||||
contract={contract}
|
||||
location={this.props.location}/>
|
||||
location={location}/>
|
||||
</AclProxy>
|
||||
<a
|
||||
className="btn btn-default btn-sm margin-left-2px"
|
||||
@ -147,7 +143,7 @@ let ContractSettings = React.createClass({
|
||||
</AclProxy>
|
||||
<AclProxy
|
||||
aclName="acl_edit_private_contract"
|
||||
aclObject={this.state.currentUser.acl}>
|
||||
aclObject={currentUser.acl}>
|
||||
<div>
|
||||
<CreateContractForm
|
||||
isPublic={false}
|
||||
@ -155,7 +151,7 @@ let ContractSettings = React.createClass({
|
||||
singular: getLangText('new contract'),
|
||||
plural: getLangText('new contracts')
|
||||
}}
|
||||
location={this.props.location}/>
|
||||
location={location}/>
|
||||
{privateContracts.map((contract, i) => {
|
||||
return (
|
||||
<ActionPanel
|
||||
@ -165,11 +161,11 @@ let ContractSettings = React.createClass({
|
||||
buttons={
|
||||
<div className="pull-right">
|
||||
<AclProxy
|
||||
aclObject={this.state.whitelabel}
|
||||
aclObject={whitelabel}
|
||||
aclName="acl_update_private_contract">
|
||||
<ContractSettingsUpdateButton
|
||||
contract={contract}
|
||||
location={this.props.location}/>
|
||||
location={location}/>
|
||||
</AclProxy>
|
||||
<a
|
||||
className="btn btn-default btn-sm margin-left-2px"
|
||||
|
@ -2,12 +2,8 @@
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import UserStore from '../../stores/user_store';
|
||||
import UserActions from '../../actions/user_actions';
|
||||
|
||||
import WhitelabelStore from '../../stores/whitelabel_store';
|
||||
import WhitelabelActions from '../../actions/whitelabel_actions';
|
||||
|
||||
import AccountSettings from './account_settings';
|
||||
import BitcoinWalletSettings from './bitcoin_wallet_settings';
|
||||
import APISettings from './api_settings';
|
||||
@ -24,56 +20,42 @@ let SettingsContainer = React.createClass({
|
||||
propTypes: {
|
||||
children: React.PropTypes.oneOfType([
|
||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||
React.PropTypes.element])
|
||||
React.PropTypes.element
|
||||
]),
|
||||
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
WhitelabelStore.getState()
|
||||
);
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
WhitelabelStore.listen(this.onChange);
|
||||
|
||||
WhitelabelActions.fetchWhitelabel();
|
||||
UserActions.fetchCurrentUser();
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
WhitelabelStore.unlisten(this.onChange);
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
loadUser(invalidateCache){
|
||||
loadUser(invalidateCache) {
|
||||
UserActions.fetchCurrentUser(invalidateCache);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
},
|
||||
|
||||
render() {
|
||||
const { currentUser, whitelabel } = this.props;
|
||||
|
||||
setDocumentTitle(getLangText('Account settings'));
|
||||
|
||||
if (this.state.currentUser && this.state.currentUser.username) {
|
||||
if (currentUser && currentUser.username) {
|
||||
return (
|
||||
<div className="settings-container">
|
||||
<AccountSettings
|
||||
currentUser={this.state.currentUser}
|
||||
currentUser={currentUser}
|
||||
loadUser={this.loadUser}
|
||||
whitelabel={this.state.whitelabel}/>
|
||||
whitelabel={whitelabel} />
|
||||
{this.props.children}
|
||||
<AclProxy
|
||||
aclObject={this.state.whitelabel}
|
||||
aclObject={whitelabel}
|
||||
aclName="acl_view_settings_api">
|
||||
<APISettings />
|
||||
</AclProxy>
|
||||
<WebhookSettings />
|
||||
<AclProxy
|
||||
aclObject={this.state.whitelabel}
|
||||
aclObject={whitelabel}
|
||||
aclName="acl_view_settings_bitcoin">
|
||||
<BitcoinWalletSettings />
|
||||
</AclProxy>
|
||||
|
@ -18,6 +18,11 @@ import { setDocumentTitle } from '../utils/dom_utils';
|
||||
|
||||
let CoaVerifyContainer = React.createClass({
|
||||
propTypes: {
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
@ -60,9 +65,8 @@ let CoaVerifyForm = React.createClass({
|
||||
},
|
||||
|
||||
handleSuccess(response){
|
||||
let notification = null;
|
||||
if (response.verdict) {
|
||||
notification = new GlobalNotificationModel(getLangText('Certificate of Authenticity successfully verified'), 'success');
|
||||
const notification = new GlobalNotificationModel(getLangText('Certificate of Authenticity successfully verified'), 'success');
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,14 @@ import { getLangText } from '../utils/lang_utils';
|
||||
|
||||
let ErrorNotFoundPage = React.createClass({
|
||||
propTypes: {
|
||||
message: React.PropTypes.string
|
||||
message: React.PropTypes.string,
|
||||
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
getDefaultProps() {
|
||||
|
@ -15,6 +15,12 @@ let LoginContainer = React.createClass({
|
||||
redirectOnLoggedIn: React.PropTypes.bool,
|
||||
redirectOnLoginSuccess: React.PropTypes.bool,
|
||||
onLogin: React.PropTypes.func,
|
||||
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
|
@ -12,6 +12,15 @@ import { setDocumentTitle } from '../utils/dom_utils';
|
||||
|
||||
|
||||
let LogoutContainer = React.createClass({
|
||||
propTypes: {
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
mixins: [History],
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -16,39 +16,43 @@ import { setDocumentTitle } from '../utils/dom_utils';
|
||||
|
||||
let PasswordResetContainer = React.createClass({
|
||||
propTypes: {
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {isRequested: false};
|
||||
return { isRequested: false };
|
||||
},
|
||||
|
||||
handleRequestSuccess(email) {
|
||||
this.setState({isRequested: email});
|
||||
this.setState({ isRequested: email });
|
||||
},
|
||||
|
||||
render() {
|
||||
let { location } = this.props;
|
||||
const { email: emailQuery, token: tokenQuery } = this.props.location.query;
|
||||
const { isRequested } = this.state;
|
||||
|
||||
if (location.query.email && location.query.token) {
|
||||
if (emailQuery && tokenQuery) {
|
||||
return (
|
||||
<div>
|
||||
<PasswordResetForm
|
||||
email={location.query.email}
|
||||
token={location.query.token}/>
|
||||
email={emailQuery}
|
||||
token={tokenQuery} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
else {
|
||||
if (this.state.isRequested === false) {
|
||||
} else {
|
||||
if (isRequested === false) {
|
||||
return (
|
||||
<div>
|
||||
<PasswordRequestResetForm
|
||||
handleRequestSuccess={this.handleRequestSuccess}/>
|
||||
handleRequestSuccess={this.handleRequestSuccess} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
else if (this.state.isRequested) {
|
||||
} else if (isRequested) {
|
||||
return (
|
||||
<div>
|
||||
<div className="ascribe-login-text ascribe-login-header">
|
||||
@ -56,12 +60,11 @@ let PasswordResetContainer = React.createClass({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return <span />;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let PasswordRequestResetForm = React.createClass({
|
||||
@ -70,9 +73,10 @@ let PasswordRequestResetForm = React.createClass({
|
||||
},
|
||||
|
||||
handleSuccess() {
|
||||
let notificationText = getLangText('If your email address exists in our database, you will receive a password recovery link in a few minutes.');
|
||||
let notification = new GlobalNotificationModel(notificationText, 'success', 50000);
|
||||
const notificationText = getLangText('If your email address exists in our database, you will receive a password recovery link in a few minutes.');
|
||||
const notification = new GlobalNotificationModel(notificationText, 'success', 50000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
this.props.handleRequestSuccess(this.refs.form.refs.email.state.value);
|
||||
},
|
||||
|
||||
@ -90,12 +94,13 @@ let PasswordRequestResetForm = React.createClass({
|
||||
type="submit"
|
||||
className="btn btn-default btn-wide">
|
||||
{getLangText('Reset your password')}
|
||||
</button>}
|
||||
</button>
|
||||
}
|
||||
spinner={
|
||||
<span className="btn btn-default btn-wide btn-spinner">
|
||||
<AscribeSpinner color="dark-blue" size="md" />
|
||||
</span>
|
||||
}>
|
||||
}>
|
||||
<div className="ascribe-form-header">
|
||||
<h3>{getLangText('Reset your password')}</h3>
|
||||
</div>
|
||||
@ -131,7 +136,7 @@ let PasswordResetForm = React.createClass({
|
||||
|
||||
handleSuccess() {
|
||||
this.history.pushState(null, '/collection');
|
||||
let notification = new GlobalNotificationModel(getLangText('password successfully updated'), 'success', 10000);
|
||||
const notification = new GlobalNotificationModel(getLangText('password successfully updated'), 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
},
|
||||
|
||||
@ -148,12 +153,13 @@ let PasswordResetForm = React.createClass({
|
||||
type="submit"
|
||||
className="btn btn-default btn-wide">
|
||||
{getLangText('Reset your password')}
|
||||
</button>}
|
||||
</button>
|
||||
}
|
||||
spinner={
|
||||
<span className="btn btn-default btn-wide btn-spinner">
|
||||
<AscribeSpinner color="dark-blue" size="md" />
|
||||
</span>
|
||||
}>
|
||||
}>
|
||||
<div className="ascribe-form-header">
|
||||
<h3>{getLangText('Reset the password for')} {this.props.email}</h3>
|
||||
</div>
|
||||
|
@ -43,6 +43,12 @@ let PieceList = React.createClass({
|
||||
filterParams: React.PropTypes.array,
|
||||
orderParams: React.PropTypes.array,
|
||||
orderBy: React.PropTypes.string,
|
||||
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
@ -85,7 +91,7 @@ let PieceList = React.createClass({
|
||||
PieceListStore.listen(this.onChange);
|
||||
EditionListStore.listen(this.onChange);
|
||||
|
||||
let page = this.props.location.query.page || 1;
|
||||
const page = this.props.location.query.page || 1;
|
||||
if (this.props.canLoadPieceList && (this.state.pieceList.length === 0 || this.state.page !== page)) {
|
||||
this.loadPieceList({ page });
|
||||
}
|
||||
@ -161,8 +167,8 @@ let PieceList = React.createClass({
|
||||
},
|
||||
|
||||
getPagination() {
|
||||
let currentPage = parseInt(this.props.location.query.page, 10) || 1;
|
||||
let totalPages = Math.ceil(this.state.pieceListCount / this.state.pageSize);
|
||||
const currentPage = parseInt(this.props.location.query.page, 10) || 1;
|
||||
const totalPages = Math.ceil(this.state.pieceListCount / this.state.pageSize);
|
||||
|
||||
if (this.state.pieceListCount > 20) {
|
||||
return (
|
||||
@ -188,8 +194,7 @@ let PieceList = React.createClass({
|
||||
});
|
||||
|
||||
// first we need to apply the filter on the piece list
|
||||
this
|
||||
.loadPieceList({ page: 1, filterBy })
|
||||
this.loadPieceList({ page: 1, filterBy })
|
||||
.then(() => {
|
||||
// but also, we need to filter all the open edition lists
|
||||
this.state.pieceList
|
||||
@ -223,23 +228,22 @@ let PieceList = React.createClass({
|
||||
},
|
||||
|
||||
fetchSelectedPieceEditionList() {
|
||||
let filteredPieceIdList = Object.keys(this.state.editionList)
|
||||
.filter((pieceId) => {
|
||||
return this.state.editionList[pieceId]
|
||||
.filter((edition) => edition.selected).length > 0;
|
||||
});
|
||||
const filteredPieceIdList = Object.keys(this.state.editionList)
|
||||
.filter((pieceId) => {
|
||||
return this.state.editionList[pieceId]
|
||||
.filter((edition) => edition.selected)
|
||||
.length;
|
||||
});
|
||||
return filteredPieceIdList;
|
||||
},
|
||||
|
||||
fetchSelectedEditionList() {
|
||||
let selectedEditionList = [];
|
||||
|
||||
Object
|
||||
.keys(this.state.editionList)
|
||||
.forEach((pieceId) => {
|
||||
let filteredEditionsForPiece = this.state.editionList[pieceId].filter((edition) => edition.selected);
|
||||
selectedEditionList = selectedEditionList.concat(filteredEditionsForPiece);
|
||||
});
|
||||
const selectedEditionList = Object.keys(this.state.editionList)
|
||||
.reduce((selectedList, pieceId) => {
|
||||
const selectedEditionsForPiece = this.state.editionList[pieceId]
|
||||
.filter((edition) => edition.selected);
|
||||
return selectedList.concat(selectedEditionsForPiece);
|
||||
}, []);
|
||||
|
||||
return selectedEditionList;
|
||||
},
|
||||
@ -250,7 +254,7 @@ let PieceList = React.createClass({
|
||||
|
||||
this.fetchSelectedPieceEditionList()
|
||||
.forEach((pieceId) => {
|
||||
EditionListActions.refreshEditionList({pieceId});
|
||||
EditionListActions.refreshEditionList({ pieceId });
|
||||
});
|
||||
EditionListActions.clearAllEditionSelections();
|
||||
},
|
||||
|
@ -12,21 +12,17 @@ import WhitelabelStore from '../stores/whitelabel_store';
|
||||
import PieceListStore from '../stores/piece_list_store';
|
||||
import PieceListActions from '../actions/piece_list_actions';
|
||||
|
||||
import UserStore from '../stores/user_store';
|
||||
|
||||
import GlobalNotificationModel from '../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../actions/global_notification_actions';
|
||||
|
||||
import Property from './ascribe_forms/property';
|
||||
import RegisterPieceForm from './ascribe_forms/form_register_piece';
|
||||
|
||||
import { mergeOptions } from '../utils/general_utils';
|
||||
import { getLangText } from '../utils/lang_utils';
|
||||
import { setDocumentTitle } from '../utils/dom_utils';
|
||||
|
||||
|
||||
let RegisterPiece = React.createClass( {
|
||||
|
||||
propTypes: {
|
||||
headerMessage: React.PropTypes.string,
|
||||
submitMessage: React.PropTypes.string,
|
||||
@ -35,30 +31,27 @@ let RegisterPiece = React.createClass( {
|
||||
React.PropTypes.element,
|
||||
React.PropTypes.string
|
||||
]),
|
||||
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
mixins: [History],
|
||||
|
||||
getInitialState(){
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
WhitelabelStore.getState(),
|
||||
PieceListStore.getState()
|
||||
);
|
||||
return PieceListStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
PieceListStore.listen(this.onChange);
|
||||
UserStore.listen(this.onChange);
|
||||
WhitelabelStore.listen(this.onChange);
|
||||
WhitelabelActions.fetchWhitelabel();
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
PieceListStore.unlisten(this.onChange);
|
||||
UserStore.unlisten(this.onChange);
|
||||
WhitelabelStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
@ -66,7 +59,7 @@ let RegisterPiece = React.createClass( {
|
||||
},
|
||||
|
||||
handleSuccess(response){
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
// once the user was able to register a piece successfully, we need to make sure to keep
|
||||
@ -84,7 +77,7 @@ let RegisterPiece = React.createClass( {
|
||||
},
|
||||
|
||||
getSpecifyEditions() {
|
||||
if(this.state.whitelabel && this.state.whitelabel.acl_create_editions || Object.keys(this.state.whitelabel).length === 0) {
|
||||
if (this.props.whitelabel && this.props.whitelabel.acl_create_editions || Object.keys(this.props.whitelabel).length === 0) {
|
||||
return (
|
||||
<Property
|
||||
name="num_editions"
|
||||
|
@ -11,6 +11,11 @@ import { setDocumentTitle } from '../utils/dom_utils';
|
||||
|
||||
let SignupContainer = React.createClass({
|
||||
propTypes: {
|
||||
// Provided from AscribeApp
|
||||
currentUser: React.PropTypes.object,
|
||||
whitelabel: React.PropTypes.object,
|
||||
|
||||
//Provided from router
|
||||
location: React.PropTypes.object
|
||||
},
|
||||
|
||||
@ -31,7 +36,7 @@ let SignupContainer = React.createClass({
|
||||
render() {
|
||||
setDocumentTitle(getLangText('Sign up'));
|
||||
|
||||
if (this.state.submitted){
|
||||
if (this.state.submitted) {
|
||||
return (
|
||||
<div className="ascribe-login-wrapper">
|
||||
<br/>
|
||||
|
Loading…
Reference in New Issue
Block a user