-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3112 from reactioncommerce/update-esther-fix-issu…
…e-3018 Use "Completed Order" component in Profile page
- Loading branch information
Showing
16 changed files
with
322 additions
and
43 deletions.
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.