-
Notifications
You must be signed in to change notification settings - Fork 623
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
18l Solution #113
Open
SuperSimpleDev
wants to merge
1
commit into
18l
Choose a base branch
from
18l-2
base: 18l
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
18l Solution #113
Changes from all commits
Commits
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {getProduct, loadProductsFetch} from '../data/products.js'; | ||
import {orders} from '../data/orders.js'; | ||
import dayjs from 'https://unpkg.com/[email protected]/esm/index.js'; | ||
import formatCurrency from './utils/money.js'; | ||
|
||
async function loadPage() { | ||
await loadProductsFetch(); | ||
|
||
let ordersHTML = ''; | ||
|
||
orders.forEach((order) => { | ||
const orderTimeString = dayjs(order.orderTime).format('MMMM D'); | ||
|
||
ordersHTML += ` | ||
<div class="order-container"> | ||
<div class="order-header"> | ||
<div class="order-header-left-section"> | ||
<div class="order-date"> | ||
<div class="order-header-label">Order Placed:</div> | ||
<div>${orderTimeString}</div> | ||
</div> | ||
<div class="order-total"> | ||
<div class="order-header-label">Total:</div> | ||
<div>$${formatCurrency(order.totalCostCents)}</div> | ||
</div> | ||
</div> | ||
|
||
<div class="order-header-right-section"> | ||
<div class="order-header-label">Order ID:</div> | ||
<div>${order.id}</div> | ||
</div> | ||
</div> | ||
|
||
<div class="order-details-grid"> | ||
${productsListHTML(order)} | ||
</div> | ||
</div> | ||
`; | ||
}); | ||
|
||
function productsListHTML(order) { | ||
let productsListHTML = ''; | ||
|
||
order.products.forEach((productDetails) => { | ||
const product = getProduct(productDetails.productId); | ||
|
||
productsListHTML += ` | ||
<div class="product-image-container"> | ||
<img src="${product.image}"> | ||
</div> | ||
|
||
<div class="product-details"> | ||
<div class="product-name"> | ||
${product.name} | ||
</div> | ||
<div class="product-delivery-date"> | ||
Arriving on: ${ | ||
dayjs(productDetails.estimatedDeliveryTime).format('MMMM D') | ||
} | ||
</div> | ||
<div class="product-quantity"> | ||
Quantity: ${productDetails.quantity} | ||
</div> | ||
<button class="buy-again-button button-primary"> | ||
<img class="buy-again-icon" src="images/icons/buy-again.png"> | ||
<span class="buy-again-message">Buy it again</span> | ||
</button> | ||
</div> | ||
|
||
<div class="product-actions"> | ||
<a href="tracking.html?orderId=${order.id}&productId=${product.id}"> | ||
<button class="track-package-button button-secondary"> | ||
Track package | ||
</button> | ||
</a> | ||
</div> | ||
`; | ||
}); | ||
|
||
return productsListHTML; | ||
} | ||
|
||
document.querySelector('.js-orders-grid').innerHTML = ordersHTML; | ||
} | ||
|
||
loadPage(); |
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.
If we used cart-class.js in our project how can we send the cart to the backend from local Storage? I've tried this:
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.
I think that might be because you have not imported cart onto scripts/order.js
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.
I don't think we need to import the cart in scripts/order.js, because here we have to work with the data received from the backend. When Simon makes a POST request to the backend, doesn't import the cart in that file . I think the data that I send to the backend is wrong. 🙃 🫣😬
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.
I have private key for local Storage. Could this be a problem?
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.
the 'cart' was imported, check files you've imported.
body: JSON.stringify({
cart: cart
})
is the product in the cart (stored), that he used to fetched data from the backend.
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 is in paymentSummary.js file, where we add event listener to the button, not in scripts/orders.js. In this file we retrieve the data from backend and render the orders.html file.
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.
i don't really get you,
i don't know if this the section you're referring to.
document.querySelector('.js-place-order')
.addEventListener('click', async()=>{
try{
const response = await fetch('https://supersimplebackend.dev/orders',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
cart: cart
})
});
});
but to make a 'POST' we must give the backend data which we want from it, this is the data, body: JSON.stringify( cart: cart })
we gave to the backend when we makes the post
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.
Troubleshooting Cart Submission Issue
I encountered a similar issue while working with
paymentSummary.js
. The problem lies in how thecart.cartItems
are being handled. You are correctly sendingcartItems
to the backend, but the issue may be related to the structure or data types withincartItems
.Example of Correct
cart
Structure:Key Points to Check:
deliveryOptionId
Data Type:Ensure that
deliveryOptionId
is a string. Initially, I used numbers likedeliveryOptionId: 1
, but this resulted in a500 Internal Server Error
. When I changed it todeliveryOptionId: '1'
, the backend accepted the data and returned the expected response.Data Types of cartItems:
Verify that the data types for
productId
,quantity
, anddeliveryOptionId
match the expected types in your backend API.productId
: Stringquantity
: NumberdeliveryOptionId
: StringDocumentation:
Refer to the backend documentation to see the correct model for
cart.cartItems.
Conclusion:
Check the data structure and types being sent from the frontend to the backend. Changing
deliveryOptionId
to a string resolved the issue for me. I hope this helps you too!