-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use "Completed Order" component in Profile page #3112
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
76a4763
- Create new branch off release-1.5.1
c3b805f
- Create a container file for userOrdersList
8837002
- Display orderID as userOrdersList header in profile page
faf620e
- Fix layout on profile page
2e655bd
- Refactor code
2974d80
Merge branch 'master' of github.com:reactioncommerce/reaction into up…
5a44015
Merge branch 'master' into update-esther-fix-issue-3018
efalayi 745a1d3
Merge branch 'update-esther-fix-issue-3018' of github.com:reactioncom…
208f828
- Reduce padding on smaller screens
7cbf6a8
Merge branch 'master' of github.com:reactioncommerce/reaction into up…
c884282
- Conditionally display delivery date
d1a0899
- Fix sentence case css style
214c958
- Change cart to items in completed orders page
8ab74e0
- Fix translation
d6030d2
- Refactor code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
imports/plugins/core/accounts/client/components/ordersList.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import CompletedOrder from "../../../checkout/client/components/completedOrder"; | ||
|
||
/** | ||
* @summary React component to display an array of completed orders | ||
* @class OrdersList | ||
* @extends {Component} | ||
* @property {Array} allOrdersInfo - array of orders | ||
* @property {Function} handeleDisplayMedia - function to display order image | ||
*/ | ||
class OrdersList extends Component { | ||
static propTypes = { | ||
allOrdersInfo: PropTypes.array, | ||
handleDisplayMedia: PropTypes.func, | ||
isProfilePage: PropTypes.bool | ||
} | ||
|
||
render() { | ||
const { allOrdersInfo, handleDisplayMedia } = this.props; | ||
|
||
if (allOrdersInfo) { | ||
return ( | ||
<div> | ||
{allOrdersInfo.map((order) => { | ||
const orderKey = order.orderId; | ||
return ( | ||
<CompletedOrder | ||
key={orderKey} | ||
shops={order.shops} | ||
order={order.order} | ||
orderId={order.orderId} | ||
orderSummary={order.orderSummary} | ||
paymentMethods={order.paymentMethods} | ||
productImages={order.productImages} | ||
handleDisplayMedia={handleDisplayMedia} | ||
isProfilePage={this.props.isProfilePage} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div className="alert alert-info"> | ||
<span data-i18n="cartCompleted.noOrdersFound">No orders found.</span> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default OrdersList; |
92 changes: 92 additions & 0 deletions
92
imports/plugins/core/accounts/client/containers/userOrdersListContainer.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { compose, withProps } from "recompose"; | ||
import { Meteor } from "meteor/meteor"; | ||
import { Router } from "/client/modules/router/"; | ||
import { Media } from "/lib/collections"; | ||
import { registerComponent, composeWithTracker } from "@reactioncommerce/reaction-components"; | ||
import OrdersList from "../components/ordersList"; | ||
|
||
|
||
const handlers = {}; | ||
|
||
handlers.handleDisplayMedia = (item) => { | ||
const variantId = item.variants._id; | ||
const productId = item.productId; | ||
|
||
const variantImage = Media.findOne({ | ||
"metadata.variantId": variantId, | ||
"metadata.productId": productId | ||
}); | ||
|
||
if (variantImage) { | ||
return variantImage; | ||
} | ||
|
||
const defaultImage = Media.findOne({ | ||
"metadata.productId": productId, | ||
"metadata.priority": 0 | ||
}); | ||
|
||
if (defaultImage) { | ||
return defaultImage; | ||
} | ||
return false; | ||
}; | ||
|
||
function composer(props, onData) { | ||
// Get user order from props | ||
const orders = props.orders; | ||
const allOrdersInfo = []; | ||
let isProfilePage = false; | ||
|
||
if (Router.getRouteName() === "account/profile") { | ||
isProfilePage = true; | ||
} | ||
|
||
if (orders.length > 0) { | ||
orders.map((order) => { | ||
const imageSub = Meteor.subscribe("CartImages", order.items); | ||
const orderSummary = { | ||
quantityTotal: order.getCount(), | ||
subtotal: order.getSubTotal(), | ||
shippingTotal: order.getShippingTotal(), | ||
tax: order.getTaxTotal(), | ||
discounts: order.getDiscounts(), | ||
total: order.getTotal(), | ||
shipping: order.shipping | ||
}; | ||
if (imageSub.ready()) { | ||
const productImages = Media.find().fetch(); | ||
const orderId = order._id; | ||
const orderInfo = { | ||
shops: order.getShopSummary(), | ||
order, | ||
orderId, | ||
orderSummary, | ||
paymentMethods: order.getUniquePaymentMethods(), | ||
productImages | ||
}; | ||
allOrdersInfo.push(orderInfo); | ||
} | ||
}); | ||
onData(null, { | ||
allOrdersInfo, | ||
isProfilePage | ||
}); | ||
} else { | ||
onData(null, { | ||
orders, | ||
isProfilePage | ||
}); | ||
} | ||
} | ||
|
||
|
||
registerComponent("OrdersList", OrdersList, [ | ||
withProps(handlers), | ||
composeWithTracker(composer) | ||
]); | ||
|
||
export default compose( | ||
withProps(handlers), | ||
composeWithTracker(composer) | ||
)(OrdersList); |
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
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
6 changes: 6 additions & 0 deletions
6
imports/plugins/core/accounts/client/templates/profile/userOrdersList.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<template name="userOrdersList"> | ||
<div> | ||
{{> React completedOrders }} | ||
</div> | ||
|
||
</template> |
23 changes: 23 additions & 0 deletions
23
imports/plugins/core/accounts/client/templates/profile/userOrdersList.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Template } from "meteor/templating"; | ||
import UserOrdersList from "/imports/plugins/core/accounts/client/containers/userOrdersListContainer"; | ||
|
||
/** | ||
* userOrdersList helpers | ||
* | ||
*/ | ||
Template.userOrdersList.helpers({ | ||
// Returns React Component | ||
completedOrders() { | ||
let orders; | ||
|
||
if (Template.currentData() && Template.currentData().data) { | ||
orders = Template.currentData().data.fetch(); | ||
} else { | ||
orders = []; | ||
} | ||
|
||
return { component: UserOrdersList, | ||
orders | ||
}; | ||
} | ||
}); |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This component should not need to be aware of what route it is in. It should be handled by passing in a prop. Components should be as dumb as possible.