Skip to content
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

feat: Add Receipt Page from ecommerce to MFE #189

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

julianajlk
Copy link
Contributor

@julianajlk julianajlk commented Jun 10, 2022

REV-2683.
We're moving the Receipt Page from ecommerce repo to this MFE for the Theseus Project.
Current receipt page template: https://github.com/edx/ecommerce/blob/947c9068928281d24a54a86ea6df3340309a4f57/ecommerce/templates/edx/checkout/receipt.html#L1
Related backend PRs:
openedx/ecommerce#3748
openedx/ecommerce#3778
openedx/ecommerce#3781

Note: for screenshots of all the different versions, pls refer to https://2u-internal.atlassian.net/l/cp/N8fuc5Py

Receipt page before:
ReceiptPage_OLD_basic

Receipt page after:
ReceiptPage_basic

Order History update tag-along:
This is not part of this ticket, but Paragon's Table component will be deprecated, I'm updating the Order History page to use DataTable so that both Order History and Receipt Page have the same look for tables.
Screen Shot 2022-06-07 at 3 43 08 PM

Screen Shot 2022-06-07 at 3 42 35 PM

This PR:

  • Creates the receipt page
  • Updates Order History to use the new DataTable Paragon component
  • Adds unit/snapshot tests

This PR is dependent on the backend work in https://2u-internal.atlassian.net/browse/REV-2788

To test locally:

  1. Enroll in a course, upgrade and make a purchase
  2. Go to http://localhost:1996/orders to make sure you have orders
  3. Choose an order number (ie. EDX-100005) and go to http://localhost:1996/receipt/?order_number={order-number}
  4. To see a discount, a coupon must be created here http://localhost:18130/coupons/ and applied at checkout
  5. This page CANNOT be accessed yet through the "View Order Details" link on Order History, this contains our current ecommerce receipt page

@julianajlk julianajlk force-pushed the julianajlk/REV-2683/receipt-page branch from 41ca02e to 8a88ebb Compare June 10, 2022 16:58
@julianajlk julianajlk force-pushed the julianajlk/REV-2683/receipt-page branch 4 times, most recently from 7152add to 328ee6b Compare July 27, 2022 17:13
@openedx openedx deleted a comment from codecov bot Jul 27, 2022
@codecov
Copy link

codecov bot commented Jul 27, 2022

Codecov Report

Base: 48.78% // Head: 50.35% // Increases project coverage by +1.57% 🎉

Coverage data is based on head (fea1b62) compared to base (6934c12).
Patch coverage: 52.06% of modified lines in pull request are covered.

❗ Current head fea1b62 differs from pull request most recent head bf86fe5. Consider uploading reports for the commit bf86fe5 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #189      +/-   ##
==========================================
+ Coverage   48.78%   50.35%   +1.57%     
==========================================
  Files          15       22       +7     
  Lines         164      284     +120     
  Branches       28       66      +38     
==========================================
+ Hits           80      143      +63     
- Misses         79      130      +51     
- Partials        5       11       +6     
Impacted Files Coverage Δ
src/components/NotFoundPage.jsx 0.00% <0.00%> (ø)
src/index.jsx 0.00% <ø> (ø)
src/order-history/OrderHistoryPage.jsx 78.04% <ø> (ø)
src/receipt/reducer.js 0.00% <0.00%> (ø)
src/receipt/saga.js 0.00% <0.00%> (ø)
src/receipt/service.js 0.00% <0.00%> (ø)
src/reducers.js 0.00% <ø> (ø)
src/sagas.js 0.00% <ø> (ø)
src/receipt/ReceiptPage.jsx 71.62% <71.62%> (ø)
src/receipt/ReceiptPage.messages.jsx 100.00% <100.00%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@julianajlk julianajlk force-pushed the julianajlk/REV-2683/receipt-page branch 2 times, most recently from 870f807 to 0cc9490 Compare July 27, 2022 19:14
@julianajlk julianajlk force-pushed the julianajlk/REV-2683/receipt-page branch 2 times, most recently from 46f483b to 9d7d7b3 Compare July 27, 2022 20:27
@dianekaplan
Copy link
Contributor

dianekaplan commented Jul 28, 2022

(junk comment, can delete)

yield put(fetchOrderBegin());
const result = yield call(OrderApiService.getOrder, orderToFetch);
yield put(fetchOrderSuccess(result));
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ are there pieces that can move out of the try and into the else block, so it's clearer which bit we're targetting? Or could any of these fail separately/differently?

@julianajlk julianajlk force-pushed the julianajlk/REV-2683/receipt-page branch 11 times, most recently from 46b7926 to 7c16f3a Compare August 16, 2022 14:21
data-order-id={order.number}
data-total-amount={order.total_before_discounts_incl_tax}
data-product-ids={order.order_product_ids}
// data-back-button="{{ disable_back_button | default:0 }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional comment - will remove soon

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some feedback. Also, curious, were you intending to have tests cover the placed where Codecov says there is no test coverage?

src/components/NotFoundPage.jsx Outdated Show resolved Hide resolved
@@ -10,7 +12,16 @@ export default function NotFoundPage() {
defaultMessage="The page you're looking for is unavailable or there's an error in the URL. Please check the URL and try again."
description="error message when a page does not exist"
/>
<span>{error}</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If error is optional (looks like it defaults to null), we should avoid rendering the span if there is no error provided otherwise its an empty span in the DOM that serves no purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page will only render if there is error in fetching the order (in src/receipt/saga.js). But I see your point, better to be safe than render an empty element.

Although now that I think about it, the actual error in this case is not very useful to the end learner? Following the original but I am likely going to remove it from here

className="order-history table-bordered"
itemCount={this.props.orders.length}
data={this.getTableData()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this.getTableData above, it looks like the data is formatted to include JSX elements inside of the data array itself in order to customize how the displayed is rendered in the table cell. However, by formatting the data passed to the data prop in DataTable with JSX elements, it'd prevent the table from supporting client-side sorting/filtering/etc. since it no longer has access to the underlying data itself. DataTable only has access to the JSX elements instead.

Alternatively, the proper way to format the cell data in DataTable is by overriding the Cell attribute within the columns definition. See these docs as an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done that in ReceiptPage.jsx when I learned about Cell from you 😬, I will update this here, good catch because I was just updating the deprecated table component to use DataTable, thanks!

const { LMS_BASE_URL } = getConfig();
const DASHBOARD_URL = `${LMS_BASE_URL}/dashboard`;
const FIND_COURSES_URL = `${LMS_BASE_URL}/courses`;
class ReceiptPage extends React.Component {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious] Is the reason you're using a class component here because this is based on some other page component? Typically, we tend to prefer functional components over class components now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason is likely that I am rusty in React and still use class components 😅 For state I will useState() hooks, assuming that's the way to go?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should totally make the jump to functional React components 😉 It's refreshing haha!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yes, if you want to change this to a functional component, useState is how you'd implement state, yes. That said, the decision on whether to change it from class -> functional is up to you :) I was just curious.

src/receipt/ReceiptPage.jsx Outdated Show resolved Hide resolved
}

.page__receipt {
h2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious/confirmation] Are the styles here relevant for all h2 on the page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should be, but weirdly I am modifying the size of 1 out of the 2 h2's with a specific px size.

I think this is another case of "following the original" which is not a good explanation but I will change them to be different heading levels since they are different.

}

.thank-you {
font-size: 38px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious] Why 38px here? It's not a font size in our design system's type ramp. See https://paragon-openedx.netlify.app/foundations/typography.

If we do need a custom font size here, we should use convert this to rem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aforementioned px specific size 😅 - will update to Paragon friendly size! Thanks for asking!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And preferably using a SCSS variable or CSS utility class, too (not hardcoded) 😉


.copy {
> div {
margin-bottom: 1rem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, it's preferred to use Paragon's SCSS spacer or utility classes than hard coded rem values for margins, e.g. mb-3 or map-get($spacers, 3).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this specifically, but sometimes I come across a case where I want a specific size that is not the same as bootstrap utility margin class spacer value, would I just revert to using a pixel or a fraction of a rem here?

Why is it preferred to use utility classes, because they render with the component as opposed to being compiled in a separate SCSS file? Just curious.

Copy link
Member

@adamstankiewicz adamstankiewicz Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julianajlk

sometimes I come across a case where I want a specific size that is not the same as bootstrap utility margin class spacer value, would I just revert to using a pixel or a fraction of a rem here?

Personally, I find the closest existing spacer value to the pixel value I'm given. In an ideal world, the handoff from design -> engineering wouldn't refer to any hard coded pixel/rem values and would instead refer to an existing spacer value.

Why is it preferred to use utility classes, because they render with the component as opposed to being compiled in a separate SCSS file? Just curious.

If spacing throughout the UI is using the same spacer values, it's trivial to update our spacing definitions in once place and have it apply everywhere. If we only use hard coded values for spacing, and our foundation spacing design tokens change (e.g., maybe mb-3 is equivalent to 1rem now, but 2rem in the future), that change wouldn't propagate where spacing is hardcoded, leading to inconsistency in the UI.

}

.order-total {
font-size: 0.875rem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the small type ramp in our design system. This could be replaced with $font-size-sm or use a small utility class name on the element itself.

margin: 2rem 0 4rem 0;

.dashboard-link {
margin-right: 2.5rem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to other feedback, if we treat these links at button links instead of Hyperlinks, I believe ActionRow should handle the spacing between the two action buttons already without needing explicit custom spacing.

Example (see default spacing between action buttons in ActionRow):
image

Copy link
Contributor Author

@julianajlk julianajlk Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense now that I understand ActionRow better! Someone in fedex recommended this and I didn't stop to think that it needs an action by the name of the component (for the other case I used it for just text formatting)

@julianajlk julianajlk force-pushed the julianajlk/REV-2683/receipt-page branch from 7c16f3a to 1d13a50 Compare August 30, 2022 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants