Created
December 8, 2016 18:40
-
-
Save thenormalsquid/7bb4db13feac96638bf2d8b688b7ffdd to your computer and use it in GitHub Desktop.
example usage of reselect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PropTypes } from 'react'; | |
import { compose } from 'recompose'; | |
import { withStyles, onMount, connect } from '_util/HOCs'; | |
import { FlexBox } from '@madmobilenpm/mmui'; | |
import AppView from 'view'; | |
import { getGroupedFulfillments, getFulfillmentById } from '_redux/selectors'; | |
import * as actions from 'actions/fulfillment'; | |
import FulfillmentList from 'components/fulfillment/FulfillmentList'; | |
import FulfillmentOrderHeader from 'components/fulfillment/FulfillmentOrderHeader'; | |
import ProductList from 'components/fulfillment/ProductList'; | |
type Props = { | |
props?: void, | |
groupedFulfillments: { [key: string]: FulfillmentMethod }, | |
unfulfilledCount: number | |
}; | |
type WrappedProps = { | |
styles: Styles | |
} & Props; | |
const componentStyles = ({ theme: { colors } }) => ({ | |
container: {} | |
}); | |
export const FulfillmentContainer: Component<WrappedProps> = ({ styles, groupedFulfillments, unfulfilledCount, setSelected, selectedFulfillment }) => | |
<AppView title="Fulfillment"> | |
<FlexBox align="stretch" flex="1 1 auto"> | |
{selectedFulfillment.orderDetails ? | |
<FlexBox column align="stretch" flex> | |
<FulfillmentOrderHeader orderDetails={selectedFulfillment.orderDetails} /> | |
<ProductList products={selectedFulfillment.orderDetails.products} /> | |
</FlexBox> : | |
<FlexBox column align="center" justify="center" flex> | |
It looks like you haven't selected a fulfillment method | |
</FlexBox> | |
} | |
<FulfillmentList | |
setSelected={setSelected} | |
groupedFulfillments={groupedFulfillments} | |
unfulfilledCount={unfulfilledCount} | |
selectedId={selectedFulfillment.id} /> | |
</FlexBox> | |
</AppView>; | |
export const enhancer = compose( | |
connect(state => ({ | |
groupedFulfillments: getGroupedFulfillments(state).toJS(), | |
unfulfilledCount: state.app.config.modules.fulfillment.badgeCount, | |
selectedFulfillment: getFulfillmentById(state, state.fulfillment.selectedId).toJS() | |
}), | |
actions), | |
onMount(props => { | |
props.loadFulfillmentCount(); | |
props.getFulfillmentList(); | |
}), | |
withStyles(componentStyles) | |
); | |
const WrappedComponent: Component<Props> = enhancer(FulfillmentContainer); | |
export default WrappedComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment