1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Convert withCurrentUser and withWhitelabel to withContext

This commit is contained in:
Brett Sun 2016-06-08 13:11:16 +02:00
parent 75247b2594
commit 5073b0988d
40 changed files with 218 additions and 129 deletions

View File

@ -20,11 +20,11 @@ import AccordionListItemEditionWidget from './accordion_list_item_edition_widget
import CreateEditionsForm from '../ascribe_forms/create_editions_form';
import AclProxy from '../acl_proxy';
import withContext from '../context/with_context';
import { whitelabelShape } from '../prop_types';
import { mergeOptions } from '../../utils/general_utils';
import { getLangText } from '../../utils/lang_utils';
import { withWhitelabel } from '../../utils/react_utils';
let AccordionListItemWallet = React.createClass({
@ -165,4 +165,4 @@ let AccordionListItemWallet = React.createClass({
}
});
export default withWhitelabel(AccordionListItemWallet);
export default withContext(AccordionListItemWallet, 'whitelabel');

View File

@ -7,10 +7,10 @@ import Button from 'react-bootstrap/lib/Button';
import ModalWrapper from '../ascribe_modal/modal_wrapper';
import UnConsignRequestForm from '../ascribe_forms/form_unconsign_request';
import withContext from '../context/with_context';
import { currentUserShape } from '../prop_types';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser } from '../../utils/react_utils';
import ApiUrls from '../../constants/api_urls';
@ -50,4 +50,4 @@ ${currentUser.username}`
}
});
export default withCurrentUser(UnConsignRequestButton);
export default withContext(UnConsignRequestButton, 'currentUser');

View File

@ -22,12 +22,12 @@ import Form from '../ascribe_forms/form';
import Property from '../ascribe_forms/property';
import AclProxy from '../acl_proxy';
import withContext from '../context/with_context';
import ApiUrls from '../../constants/api_urls';
import AscribeSpinner from '../ascribe_spinner';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser } from '../../utils/react_utils';
/**
@ -151,7 +151,7 @@ const Edition = React.createClass({
});
let EditionSummary = withCurrentUser(React.createClass({
let EditionSummary = withContext(React.createClass({
propTypes: {
edition: React.PropTypes.object.isRequired,
@ -216,7 +216,7 @@ let EditionSummary = withCurrentUser(React.createClass({
</div>
);
}
}));
}), 'isLoggedIn');
let CoaDetails = React.createClass({
@ -359,4 +359,4 @@ let SpoolDetails = React.createClass({
}
});
export default withCurrentUser(Edition);
export default withContext(Edition, 'isLoggedIn');

View File

@ -17,14 +17,13 @@ import CollapsibleButton from './../ascribe_collapsible/collapsible_button';
import AscribeSpinner from '../ascribe_spinner';
import AclProxy from '../acl_proxy';
import withContext from '../context/with_context';
import { currentUserShape } from '../prop_types';
import AppConstants from '../../constants/application_constants';
import { extractFileExtensionFromUrl } from '../../utils/file_utils';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser } from '../../utils/react_utils';
const EMBED_IFRAME_HEIGHT = {
@ -184,4 +183,4 @@ let MediaContainer = React.createClass({
}
});
export default withCurrentUser(MediaContainer);
export default withContext(MediaContainer, 'currentUser');

View File

@ -9,8 +9,9 @@ import Form from '../ascribe_forms/form';
import Property from '../ascribe_forms/property';
import InputTextAreaToggable from '../ascribe_forms/input_textarea_toggable';
import withContext from '../context/with_context';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser } from '../../utils/react_utils';
let Note = React.createClass({
propTypes: {
@ -78,4 +79,4 @@ let Note = React.createClass({
}
});
export default withCurrentUser(Note);
export default withContext(Note, 'isLoggedIn');

View File

@ -37,13 +37,13 @@ import ListRequestActions from '../ascribe_forms/list_form_request_actions';
import AclProxy from '../acl_proxy';
import AscribeSpinner from '../ascribe_spinner';
import withContext from '../context/with_context';
import ApiUrls from '../../constants/api_urls';
import { setDocumentTitle } from '../../utils/dom_utils';
import { mergeOptions } from '../../utils/general_utils';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser } from '../../utils/react_utils';
/**
* This is the component that implements resource/data specific functionality
@ -341,4 +341,4 @@ const PieceContainer = React.createClass({
}
});
export default withRouter(withCurrentUser(PieceContainer));
export default withRouter(withContext(PieceContainer, 'isLoggedIn'));

View File

@ -12,13 +12,13 @@ import LoanForm from '../ascribe_forms/form_loan';
import LoanRequestAnswerForm from '../ascribe_forms/form_loan_request_answer';
import ShareForm from '../ascribe_forms/form_share_email';
import withContext from '../context/with_context';
import { currentUserShape } from '../prop_types';
import AppConstants from '../../constants/application_constants';
import ApiUrls from '../../constants/api_urls';
import { getAclFormMessage, getAclFormDataId } from '../../utils/form_utils';
import { withCurrentUser } from '../../utils/react_utils';
let AclFormFactory = React.createClass({
propTypes: {
@ -138,4 +138,4 @@ let AclFormFactory = React.createClass({
}
});
export default withCurrentUser(AclFormFactory);
export default withContext(AclFormFactory, 'currentUser');

View File

@ -8,13 +8,13 @@ import GlobalNotificationActions from '../../actions/global_notification_actions
import Form from './form';
import Property from './property';
import withContext from '../context/with_context';
import { currentUserShape } from '../prop_types';
import ApiUrls from '../../constants/api_urls';
import AppConstants from '../../constants/application_constants';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser } from '../../utils/react_utils';
const { bool } = React.PropTypes;
@ -85,4 +85,4 @@ const CopyrightAssociationForm = React.createClass({
}
});
export default withCurrentUser(CopyrightAssociationForm);
export default withContext(CopyrightAssociationForm, 'currentUser', 'isLoggedIn');

View File

@ -11,6 +11,7 @@ import FormSubmitButton from '../ascribe_buttons/form_submit_button';
import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_button';
import AscribeSpinner from '../ascribe_spinner';
import withContext from '../context/with_context';
import { currentUserShape } from '../prop_types';
import ApiUrls from '../../constants/api_urls';
@ -19,7 +20,6 @@ import { validationParts, validationTypes } from '../../constants/uploader_const
import { FileStatus, formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser } from '../../utils/react_utils';
let RegisterPieceForm = React.createClass({
@ -240,4 +240,4 @@ let RegisterPieceForm = React.createClass({
}
});
export default withCurrentUser(RegisterPieceForm);
export default withContext(RegisterPieceForm, 'currentUser');

View File

@ -5,12 +5,11 @@ import withRouter from 'react-router/es6/withRouter';
import UserStore from '../../stores/user_store';
import withContext from '../context/with_context';
import { currentUserShape, whitelabelShape } from '../prop_types';
import AppConstants from '../../constants/application_constants';
import { withCurrentUser, withWhitelabel } from '../../utils/react_utils';
const { bool, object } = React.PropTypes;
const WHEN_ENUM = ['loggedIn', 'loggedOut'];
@ -135,6 +134,6 @@ export function ProxyHandler(...redirectFunctions) {
}
});
return withRouter(withCurrentUser(withWhitelabel(ProxyHandlerComponent)));
return withRouter(withContext(ProxyHandlerComponent, 'currentUser', 'isLoggedIn', 'whitelabel'));
};
}

View File

@ -14,12 +14,12 @@ import CollapsibleParagraph from '../ascribe_collapsible/collapsible_paragraph';
import AclProxy from '../acl_proxy';
import AscribeSpinner from '../ascribe_spinner';
import withContext from '../context/with_context';
import { currentUserShape, whitelabelShape } from '../prop_types';
import ApiUrls from '../../constants/api_urls';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../utils/react_utils';
let AccountSettings = React.createClass({
propTypes: {
@ -112,4 +112,4 @@ let AccountSettings = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(AccountSettings));
export default withContext(AccountSettings, 'currentUser', 'whitelabel');

View File

@ -16,12 +16,12 @@ import CreateContractForm from '../ascribe_forms/form_create_contract';
import ActionPanel from '../ascribe_panel/action_panel';
import AclProxy from '../acl_proxy';
import withContext from '../context/with_context';
import { currentUserShape, whitelabelShape } from '../prop_types';
import { setDocumentTitle } from '../../utils/dom_utils';
import { truncateTextAtCharIndex } from '../../utils/general_utils';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../utils/react_utils';
let ContractSettings = React.createClass({
@ -183,4 +183,4 @@ let ContractSettings = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(ContractSettings));
export default withContext(ContractSettings, 'currentUser', 'whitelabel');

View File

@ -10,11 +10,11 @@ import BitcoinWalletSettings from './bitcoin_wallet_settings';
import WebhookSettings from './webhook_settings';
import AclProxy from '../acl_proxy';
import withContext from '../context/with_context';
import { whitelabelShape } from '../prop_types';
import { setDocumentTitle } from '../../utils/dom_utils';
import { getLangText } from '../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../utils/react_utils';
let SettingsContainer = React.createClass({
@ -64,4 +64,4 @@ let SettingsContainer = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(SettingsContainer));
export default withContext(SettingsContainer, 'isLoggedIn', 'whitelabel');

View File

@ -0,0 +1,137 @@
import React from 'react';
import { currentUserShape, whitelabelShape } from '../prop_types';
import { selectFromObject } from '../../utils/general_utils';
import { getDisplayName } from '../../utils/react_utils';
/**
* ContextPropDefinitions
* ======================
* contextType definitions for `contextProp`s.
*
* Each definition is of the form:
*
* contextProp = {
* 'contextTypes': {
* 'contextType': contextType used by the contextProp,
* ...
* },
* transformToProps: (optional) function that will receive the contextTypes from the component's
* context and should return an object containing the props to inject.
* }
*
* In the common case where your `contextProp` maps directly to the `contextType` used
* (eg. using `currentUser` as a `contextProp` to get the `currentUser` from context), you can omit
* the object definition and simply assign the `contextType` to the `contextProp`:
*
* contextProp = contextType
*
* as opposed to:
*
* contextProp = {
* 'contextTypes': {
* contextProp: contextType
* }
* }
*/
const ContextPropDefinitions = {
currentUser: currentUserShape.isRequired,
isLoggedIn: {
contextTypes: {
currentUser: currentUserShape.isRequired
},
transformToProps: ({ currentUser }) => ({ isLoggedIn: !!currentUser.email })
},
whitelabel: whitelabelShape.isRequired
};
// Expand any shortform definitions in ContextPropDefinitions into a normalized form that's
// easier for withContext to work with
Object.entries(ContextPropDefinitions).forEach(([prop, def]) => {
if (!def.hasOwnProperty('contextTypes')) {
ContextPropDefinitions[prop] = {
contextTypes: {
[prop]: def
}
};
}
});
/**
* Generalized version of react-router's `withRouter`.
* This injects the given `contextProp`s from the WrappedComponent's context into the component as
* a prop.
*
* Given `contextProp`s must have a matching definition in `ContextPropDefinitions`.
*
* @param {Component} WrappedComponent Component to inject context into
* @param {...string} contextProps Argument list of `contextProp`s (that must be registered in
* `ContextPropDefinitions`) to be injected into component as
* props
* @return {Component} Wrapped component
*/
export default function withContext(WrappedComponent, ...contextProps) {
const wrappedComponentName = getDisplayName(WrappedComponent);
if (!contextProps.length) {
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.warn(`Used withContext on ${wrappedComponentName} without supplying any ` +
"items to inject from the component's context. Ignoring...");
}
return WrappedComponent;
}
const contextTypes = contextProps.reduce((types, contextProp) => {
const contextDef = ContextPropDefinitions[contextProp];
if (contextDef) {
Object.assign(types, contextDef.contextTypes);
} else if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.warn(`No context types were found for '${contextProp}' when adding context ` +
`to ${wrappedComponentName}. Make sure to add the context information ` +
'with_context.js.');
}
return types;
}, {});
const WithContext = (props, context) => {
if (process.env.NODE_ENV !== 'production') {
// Check if the expected context was available
Object.keys(contextTypes).forEach((contextType) => {
if (!context[contextType]) {
// eslint-disable-next-line no-console
console.warn(`Expected '${contextType}' did not exist in ` +
`${wrappedComponentName}'s context during mounting`);
}
});
}
const injectedProps = Object.assign({}, ...contextProps.map((contextProp) => {
const contextDef = ContextPropDefinitions[contextProp];
if (contextDef) {
const contextForProp = selectFromObject(context, Object.keys(contextDef.contextTypes));
return typeof contextDef.transformToProps === 'function'
? contextDef.transformToProps(contextForProp)
: contextForProp;
} else {
// Will be ignored by Object.assign()
return undefined;
}
}));
return (
<WrappedComponent {...props} {...injectedProps} />
);
};
WithContext.displayName = `WithContext(${wrappedComponentName}): ${contextProps.join(', ')}`;
WithContext.contextTypes = contextTypes;
return WithContext;
}

View File

@ -14,6 +14,7 @@ import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import PieceListStore from '../stores/piece_list_store';
import AclProxy from './acl_proxy';
import withContext from './context/with_context';
import HeaderNotifications from './header_notifications';
import HeaderNotificationDebug from './header_notification_debug';
import NavRoutesLinks from './nav_routes_links';
@ -21,7 +22,6 @@ import { currentUserShape, whitelabelShape } from './prop_types';
import { constructHead } from '../utils/dom_utils';
import { getLangText } from '../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../utils/react_utils';
let Header = React.createClass({
@ -219,4 +219,4 @@ let Header = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(Header));
export default withContext(Header, 'currentUser', 'isLoggedIn', 'whitelabel');

View File

@ -10,10 +10,10 @@ import Nav from 'react-bootstrap/lib/Nav';
import NotificationActions from '../actions/notification_actions';
import NotificationStore from '../stores/notification_store';
import withContext from './context/with_context';
import { currentUserShape } from './prop_types';
import { getLangText } from '../utils/lang_utils';
import { withCurrentUser } from '../utils/react_utils';
let HeaderNotifications = React.createClass({
@ -158,4 +158,4 @@ let NotificationListItem = React.createClass({
}
});
export default withCurrentUser(HeaderNotifications);
export default withContext(HeaderNotifications, 'currentUser', 'isLoggedIn');

View File

@ -5,11 +5,11 @@ import Link from 'react-router/es6/Link';
import LoginForm from './ascribe_forms/form_login';
import withContext from './context/with_context';
import { whitelabelShape } from './prop_types';
import { setDocumentTitle } from '../utils/dom_utils';
import { getLangText } from '../utils/lang_utils';
import { withWhitelabel } from '../utils/react_utils';
let LoginContainer = React.createClass({
@ -43,4 +43,4 @@ let LoginContainer = React.createClass({
}
});
export default withWhitelabel(LoginContainer);
export default withContext(LoginContainer, 'whitelabel');

View File

@ -13,7 +13,9 @@ import GlobalNotificationActions from '../actions/global_notification_actions';
import Property from './ascribe_forms/property';
import RegisterPieceForm from './ascribe_forms/form_register_piece';
import withContext from './context/with_context';
import { whitelabelShape } from './prop_types';
import { getLangText } from '../utils/lang_utils';
import { setDocumentTitle } from '../utils/dom_utils';
@ -105,5 +107,4 @@ const RegisterPiece = React.createClass( {
}
});
export default withRouter(RegisterPiece);
export default withRouter(withContext(RegisterPiece, 'whitelabel'));

View File

@ -2,6 +2,7 @@
import React from 'react';
// FIXME: Input is deprecated
import Input from 'react-bootstrap/lib/Input';
import Glyphicon from 'react-bootstrap/lib/Glyphicon';

View File

@ -3,11 +3,11 @@ import Link from 'react-router/es6/Link';
import SignupForm from './ascribe_forms/form_signup';
import withContext from './context/with_context';
import { whitelabelShape } from './prop_types';
import { setDocumentTitle } from '../utils/dom_utils';
import { getLangText } from '../utils/lang_utils';
import { withWhitelabel } from '../utils/react_utils';
let SignupContainer = React.createClass({
@ -68,4 +68,4 @@ let SignupContainer = React.createClass({
});
export default withWhitelabel(SignupContainer);
export default withContext(SignupContainer, 'whitelabel');

View File

@ -5,11 +5,11 @@ import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let Vivi23Landing = React.createClass({
@ -69,4 +69,4 @@ let Vivi23Landing = React.createClass({
}
});
export default withWhitelabel(Vivi23Landing);
export default withContext(Vivi23Landing, 'whitelabel');

View File

@ -5,11 +5,11 @@ import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { getLangText } from '../../../../../utils/lang_utils';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let ArtcityLanding = React.createClass({
@ -63,4 +63,4 @@ let ArtcityLanding = React.createClass({
}
});
export default withWhitelabel(ArtcityLanding);
export default withContext(ArtcityLanding, 'whitelabel');

View File

@ -7,10 +7,10 @@ import AclButtonList from '../../../../ascribe_buttons/acl_button_list';
import DeleteButton from '../../../../ascribe_buttons/delete_button';
import AclProxy from '../../../../acl_proxy';
import withContext from '../../../../context/with_context';
import { currentUserShape } from '../../../../prop_types';
import { mergeOptions } from '../../../../../utils/general_utils';
import { withCurrentUser } from '../../../../../utils/react_utils';
let WalletActionPanel = React.createClass({
@ -71,4 +71,4 @@ let WalletActionPanel = React.createClass({
}
});
export default withCurrentUser(WalletActionPanel);
export default withContext(WalletActionPanel, 'currentUser');

View File

@ -13,11 +13,11 @@ import Note from '../../../../ascribe_detail/note';
import Piece from '../../../../../components/ascribe_detail/piece';
import AscribeSpinner from '../../../../ascribe_spinner';
import withContext from '../../../../context/with_context';
import ApiUrls from '../../../../../constants/api_urls';
import { getLangText } from '../../../../../utils/lang_utils';
import { withCurrentUser } from '../../../../../utils/react_utils';
let WalletPieceContainer = React.createClass({
@ -101,4 +101,4 @@ let WalletPieceContainer = React.createClass({
}
});
export default withCurrentUser(WalletPieceContainer);
export default withContext(WalletPieceContainer, 'isLoggedIn');

View File

@ -6,11 +6,11 @@ import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let CylandLanding = React.createClass({
@ -64,4 +64,4 @@ let CylandLanding = React.createClass({
}
});
export default withWhitelabel(CylandLanding);
export default withContext(CylandLanding, 'whitelabel');

View File

@ -5,11 +5,11 @@ import PieceList from '../../../../piece_list';
import CylandAccordionListItem from './cyland_accordion_list/cyland_accordion_list_item';
import withContext from '../../../../context/with_context';
import { currentUserShape, whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../../../../utils/react_utils';
let CylandPieceList = React.createClass({
propTypes: {
@ -57,4 +57,4 @@ let CylandPieceList = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(CylandPieceList));
export default withContext(CylandPieceList, 'currentUser', 'whitelabel');

View File

@ -24,6 +24,7 @@ import RegisterPieceForm from '../../../../ascribe_forms/form_register_piece';
import SlidesContainer from '../../../../ascribe_slides_container/slides_container';
import withContext from '../../../../context/with_context';
import { currentUserShape, whitelabelShape } from '../../../../prop_types';
import ApiUrls from '../../../../../constants/api_urls';
@ -32,7 +33,6 @@ import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getAclFormMessage } from '../../../../../utils/form_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { mergeOptions } from '../../../../../utils/general_utils';
import { withCurrentUser, withWhitelabel } from '../../../../../utils/react_utils';
const CylandRegisterPiece = React.createClass({
@ -221,4 +221,4 @@ const CylandRegisterPiece = React.createClass({
}
});
export default withRouter(withCurrentUser(withWhitelabel(CylandRegisterPiece)));
export default withRouter(withContext(CylandRegisterPiece, 'currentUser', 'isLoggedIn'));

View File

@ -5,11 +5,11 @@ import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let DemoLanding = React.createClass({
@ -63,4 +63,4 @@ let DemoLanding = React.createClass({
}
});
export default withWhitelabel(DemoLanding);
export default withContext(DemoLanding, 'whitelabel');

View File

@ -14,11 +14,10 @@ import IkonotvSubmitButton from '../ikonotv_buttons/ikonotv_submit_button';
import AccordionListItemPiece from '../../../../../ascribe_accordion_list/accordion_list_item_piece';
import AclProxy from '../../../../../acl_proxy';
import withContext from '../../../../../context/with_context';
import { currentUserShape } from '../../../../../prop_types';
import { getLangText } from '../../../../../../utils/lang_utils';
import { mergeOptions } from '../../../../../../utils/general_utils';
import { withCurrentUser } from '../../../../../../utils/react_utils';
let IkonotvAccordionListItem = React.createClass({
@ -120,4 +119,4 @@ let IkonotvAccordionListItem = React.createClass({
}
});
export default withCurrentUser(IkonotvAccordionListItem);
export default withContext(IkonotvAccordionListItem, 'currentUser');

View File

@ -15,13 +15,13 @@ import OwnershipFetcher from '../../../../../fetchers/ownership_fetcher';
import CopyrightAssociationForm from '../../../../ascribe_forms/form_copyright_association';
import Property from '../../../../ascribe_forms/property';
import withContext from '../../../../context/with_context';
import { currentUserShape, whitelabelShape } from '../../../../prop_types';
import AppConstants from '../../../../../constants/application_constants';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../../../../utils/react_utils';
const IkonotvContractNotifications = React.createClass({
@ -201,4 +201,4 @@ const IkonotvContractNotifications = React.createClass({
}
});
export default withRouter(withCurrentUser(withWhitelabel(IkonotvContractNotifications)));
export default withRouter(withContext(IkonotvContractNotifications, 'currentUser', 'whitelabel'));

View File

@ -6,9 +6,10 @@ import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withCurrentUser } from '../../../../../utils/react_utils';
let IkonotvLanding = React.createClass({
@ -101,4 +102,4 @@ let IkonotvLanding = React.createClass({
}
});
export default withCurrentUser(IkonotvLanding);
export default withContext(IkonotvLanding, 'isLoggedIn');

View File

@ -8,11 +8,11 @@ import NotificationStore from '../../../../../stores/notification_store';
import IkonotvAccordionListItem from './ikonotv_accordion_list/ikonotv_accordion_list_item';
import withContext from '../../../../context/with_context';
import { currentUserShape, whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../../../../utils/react_utils';
let IkonotvPieceList = React.createClass({
@ -91,4 +91,4 @@ let IkonotvPieceList = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(IkonotvPieceList));
export default withContext(IkonotvPieceList, 'currentUser', 'whitelabel');

View File

@ -22,13 +22,13 @@ import LoanForm from '../../../../ascribe_forms/form_loan';
import SlidesContainer from '../../../../ascribe_slides_container/slides_container';
import withContext from '../../../../context/with_context';
import { currentUserShape, whitelabelShape } from '../../../../prop_types';
import ApiUrls from '../../../../../constants/api_urls';
import { mergeOptions } from '../../../../../utils/general_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../../../../utils/react_utils';
const IkonotvRegisterPiece = React.createClass({
@ -246,4 +246,4 @@ const IkonotvRegisterPiece = React.createClass({
}
});
export default withRouter(withCurrentUser(withWhitelabel(IkonotvRegisterPiece)));
export default withRouter(withContext(IkonotvRegisterPiece, 'currentUser', 'whitelabel'));

View File

@ -5,11 +5,11 @@ import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let LumenusLanding = React.createClass({
@ -65,4 +65,4 @@ let LumenusLanding = React.createClass({
}
});
export default withWhitelabel(LumenusLanding);
export default withContext(LumenusLanding, 'whitelabel');

View File

@ -14,11 +14,11 @@ import AclFormFactory from '../../../../../ascribe_forms/acl_form_factory';
import ModalWrapper from '../../../../../ascribe_modal/modal_wrapper';
import AclProxy from '../../../../../acl_proxy';
import withContext from '../../../../../context/with_context';
import { currentUserShape, whitelabelShape } from '../../../../../prop_types';
import { getAclFormMessage, getAclFormDataId } from '../../../../../../utils/form_utils';
import { getLangText } from '../../../../../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../../../../../utils/react_utils';
let MarketSubmitButton = React.createClass({
propTypes: {
@ -187,4 +187,4 @@ let MarketSubmitButton = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(MarketSubmitButton));
export default withContext(MarketSubmitButton, 'currentUser', 'whitelabel');

View File

@ -5,11 +5,11 @@ import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let MarketLanding = React.createClass({
@ -69,4 +69,4 @@ let MarketLanding = React.createClass({
}
});
export default withWhitelabel(MarketLanding);
export default withContext(MarketLanding, 'whitelabel');

View File

@ -4,12 +4,12 @@ import React from 'react';
import MarketAclButtonList from './market_buttons/market_acl_button_list';
import withContext from '../../../../context/with_context';
import PieceList from '../../../../piece_list';
import { currentUserShape, whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withCurrentUser, withWhitelabel } from '../../../../../utils/react_utils';
let MarketPieceList = React.createClass({
propTypes: {
@ -71,4 +71,4 @@ let MarketPieceList = React.createClass({
}
});
export default withCurrentUser(withWhitelabel(MarketPieceList));
export default withContext(MarketPieceList, 'currentUser', 'whitelabel');

View File

@ -17,12 +17,12 @@ import RegisterPieceForm from '../../../../ascribe_forms/form_register_piece';
import SlidesContainer from '../../../../ascribe_slides_container/slides_container';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { mergeOptions } from '../../../../../utils/general_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let MarketRegisterPiece = React.createClass({
propTypes: {
@ -162,4 +162,4 @@ let MarketRegisterPiece = React.createClass({
}
});
export default withRouter(withWhitelabel(MarketRegisterPiece));
export default withRouter(withContext(MarketRegisterPiece, 'whitelabel'));

View File

@ -5,11 +5,11 @@ import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
import withContext from '../../../../context/with_context';
import { whitelabelShape } from '../../../../prop_types';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { getLangText } from '../../../../../utils/lang_utils';
import { withWhitelabel } from '../../../../../utils/react_utils';
let PollineLanding = React.createClass({
@ -63,4 +63,4 @@ let PollineLanding = React.createClass({
}
});
export default withWhitelabel(PollineLanding);
export default withContext(PollineLanding, 'whitelabel');

View File

@ -1,7 +1,3 @@
import React from 'react';
import { currentUserShape, whitelabelShape } from '../components/prop_types';
/**
* Taken from react-router (https://github.com/reactjs/react-router/blob/master/modules/withRouter.js)
* FIXME: should be put into react-component's utils
@ -9,48 +5,3 @@ import { currentUserShape, whitelabelShape } from '../components/prop_types';
export function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
}
/**
* Similar to react-router's `withRouter`, this injects the `currentUser` from the Component's
* context into the Component as a prop. It also injects whether the user's logged in or not as
* `isLoggedIn`.
*
* @param {Component} Component Component to inject `context.currentUser` and `isLoggedIn` into
* @return {Component} Wrapped component
*/
export function withCurrentUser(Component) {
const contextTypes = {
currentUser: currentUserShape.isRequired
};
const WithCurrentUser = (props, { currentUser }) => (
<Component {...props} currentUser={currentUser} isLoggedIn={!!currentUser.email} />
);
WithCurrentUser.displayName = `WithCurrentUser(${getDisplayName(Component)})`;
WithCurrentUser.contextTypes = contextTypes;
return WithCurrentUser;
}
/**
* Similar to react-router's `withRouter`, this injects the `whitelabel` from the Component's
* context into the Component as a prop.
*
* @param {Component} Component Component to inject `context.whitelabel` into
* @return {Component} Wrapped component
*/
export function withWhitelabel(Component) {
const contextTypes = {
whitelabel: whitelabelShape.isRequired
};
const WithWhitelabel = (props, { whitelabel }) => (
<Component {...props} whitelabel={whitelabel} />
);
WithWhitelabel.displayName = `WithWhitelabel(${getDisplayName(Component)})`;
WithWhitelabel.contextTypes = contextTypes;
return WithWhitelabel;
}