-
Notifications
You must be signed in to change notification settings - Fork 7
/
connector.js
37 lines (34 loc) · 1.32 KB
/
connector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Copyright (c) 2017-present, Shopgate, Inc. All rights reserved.
*
* This source code is licensed under the Apache 2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { connect } from 'react-redux';
import submitReview from '@shopgate/pwa-common-commerce/reviews/actions/submitReview';
import {
getDefaultAuthorName,
getUserReviewForProduct,
getUserReviewFirstFetchState,
} from '@shopgate/pwa-common-commerce/reviews/selectors';
import { getCurrentBaseProductId } from '@shopgate/pwa-common-commerce/product/selectors/product';
/**
* Maps the contents of the state to the component props.
* @param {Object} state The current application state.
* @return {Object} The extended component props.
*/
const mapStateToProps = state => ({
authorName: getDefaultAuthorName(state),
productId: getCurrentBaseProductId(state),
review: getUserReviewForProduct(state),
isLoadingUserReview: getUserReviewFirstFetchState(state),
});
/**
* Connects the dispatch function to a callable function in the props.
* @param {Function} dispatch The redux dispatch function.
* @return {Object} The extended component props.
*/
const mapDispatchToProps = dispatch => ({
submit: (review, update) => dispatch(submitReview(review, update)),
});
export default connect(mapStateToProps, mapDispatchToProps);