Skip to content

Code to add checkout functionality.#9

Open
Akansha-star wants to merge 1 commit into
ReDI-Munich-Frontend:pokemon-cartfrom
Akansha-star:pokemon-cart
Open

Code to add checkout functionality.#9
Akansha-star wants to merge 1 commit into
ReDI-Munich-Frontend:pokemon-cartfrom
Akansha-star:pokemon-cart

Conversation

@Akansha-star
Copy link
Copy Markdown

Added the ability to update the cart items quantity. Linked the "Checkout" button to the checkout page. Created a form in the Checkout page. The "Place order" button has been linked to the Order completed page. Order complete page shows user info and order info. Cart clear implemented on Order complete.

Added the ability to update the cart items quantity. Linked the "Checkout" button to the checkout page. Created a form in the Checkout page. The "Place order" button has been linked to the Order completed page. Order complete page shows user info and order info. Cart clear implemented on Order complete.
Copy link
Copy Markdown
Contributor

@MrTim MrTim left a comment

Choose a reason for hiding this comment

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

Nice work! I checked the code but not how it works, so hope that you checked that it's working.
Left some comment and improvement sugessions, please take a look.

Comment thread src/Checkout/Checkout.js
import styled from "styled-components";
import { addOrderDetails } from "../common/pokemonStorage";

const SubmitButton = styled.button`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think since it's too many styled components needed it make sense to move them into a separate file. Nothing wrong with this implementation just nice code splitting :)

Comment thread src/Checkout/Checkout.js
const { name, value } = event.target;

setContact((prevValue) => {
if (name === "fName") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All that could be written shorter:

setContact((prevState) => {
  ...prevState,
  [name]: value,
});

Let me know if you don't understand this structure so I can explain what it does :)

Comment thread src/Checkout/Checkout.js

export function CheckOut() {
const [contact, setContact] = useState({
fName: "",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: name property as it is - meaning write it in full words firstName, lastName. Because you're not saving any space here but readability would be way better.

return <div>OrderCompleted</div>;
const cart = getCartItems();
const order = getOrderDetails();
console.log("order", order);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no need for console.log

import { useHistory } from "react-router-dom";
import styled from "styled-components";
import { HRStyle } from "./Hr";
import {} from "module";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is probably some leftover code

try {
const counterStorage = localStorage.getItem(COUNTER_KEY);
if (counterStorage) {
/* eslint-disable */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't use this generic disabling syntax - because it's not telling to others what exactly you're trying to fix with it. In case you need to do it - disable exact rule which is failing

flex-direction: column;
align-items: flex-end;
`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

too many empty lines

try {
const cartStorage = localStorage.getItem(STORAGE_KEY);
return JSON.parse(cartStorage);
return cartStorage ? JSON.parse(cartStorage) : [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can do it shorter: JSON.parse(cartStorage) || [].

export const addToCart = (item) => {
const cartStorage = getCartItems();
const currentCounter = getCounter();
const foundIndex = cartStorage.findIndex((itm) => itm.name === item.name);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here about names: itm is not really a good name. In such case I'll go with just i as a short from item, or with full cartItem which probably better because you see instantly that you're trying to find same nae in cart

localStorage.setItem(STORAGE_KEY, JSON.stringify(filteredCart));
return filteredCart;
const currentCounter = getCounter();
console.log("currentCounter", currentCounter);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

console.log

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.

2 participants