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

Code to add checkout functionality. #9

Open
wants to merge 1 commit into
base: pokemon-cart
Choose a base branch
from

Conversation

Akansha-star
Copy link

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
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.

import styled from "styled-components";
import { addOrderDetails } from "../common/pokemonStorage";

const SubmitButton = styled.button`
Copy link
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 :)

const { name, value } = event.target;

setContact((prevValue) => {
if (name === "fName") {
Copy link
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 :)


export function CheckOut() {
const [contact, setContact] = useState({
fName: "",
Copy link
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
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
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
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
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


export const getCartItems = () => {
try {
const cartStorage = localStorage.getItem(STORAGE_KEY);
return JSON.parse(cartStorage);
return cartStorage ? JSON.parse(cartStorage) : [];
Copy link
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) || [].

} catch (e) {
return [];
}
};

export const addToCart = (item) => {
const cartStorage = getCartItems();
const currentCounter = getCounter();
const foundIndex = cartStorage.findIndex((itm) => itm.name === item.name);
Copy link
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
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