-
Notifications
You must be signed in to change notification settings - Fork 5
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
Checkout #8
base: master
Are you sure you want to change the base?
Checkout #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import Form from "./components/Form"; | ||
|
||
export function Checkout() { | ||
return <div>Checkout</div>; | ||
return <div> | ||
<Form /> | ||
</div>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, {useState} from 'react' | ||
import { useHistory } from "react-router-dom"; | ||
import styled from 'styled-components' | ||
import {setCustomerDetail} from "../../common/customerInfo" | ||
|
||
const FormWrapper = styled.div` | ||
margin-bottom: 2rem; | ||
max-width: 1000px; | ||
margin: auto; | ||
background-color: black; | ||
color: white; | ||
justify-content: centre; | ||
align-item: center; | ||
`; | ||
const PanelStyle = styled.div` | ||
margin: 2rem; | ||
background-color: white; | ||
padding: 2rem; | ||
display: block; | ||
`; | ||
const FormLayout = styled.form` | ||
display: block; | ||
margin: 2px; | ||
`; | ||
const Label = styled.label` | ||
font-weight: 20px; | ||
color: black; | ||
display: block; | ||
`; | ||
const Input = styled.input` | ||
width: 100px; | ||
height: 15px; | ||
`; | ||
const Address = styled.textarea` | ||
width: 100px; | ||
height: 15px | ||
`; | ||
const SubmitButton = styled.button` | ||
width : 60px; | ||
height: 30px; | ||
display: block; | ||
margin: 5px; | ||
`; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed empty line |
||
|
||
function Form() { | ||
const [customer, setCustomer] = useState(); | ||
const history = useHistory(); | ||
const handleChange = (e)=>{ | ||
const name=e.target.value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pay attention to the code style, this is super important when you're submitting your code for review. |
||
setCustomer(name); | ||
setCustomerDetail(name); | ||
} | ||
const handleSubmit = () =>{ | ||
history.push(`/order-completed`); | ||
} | ||
|
||
return ( | ||
<FormWrapper> | ||
<h1>CHECKOUT</h1> | ||
<PanelStyle> | ||
<FormLayout onSubmit={handleSubmit}> | ||
<Label>NAME</Label> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to use caps in the field names. Name them just with first capital letter, that would be enough |
||
<Input type="text" maxLength="20" minLength="3" value={customer} onChange={(e)=>handleChange(e)}/> | ||
<Label>EMAIL</Label> | ||
<Input type="email" /> | ||
<Label>CITY</Label> | ||
<Input type="text-area" /> | ||
<Label>ADDRESS</Label> | ||
<Address /> | ||
<Label>CARD</Label> | ||
<Input type="number"/> | ||
<SubmitButton>SUBMIT</SubmitButton> | ||
</FormLayout> | ||
</PanelStyle> | ||
</FormWrapper> | ||
) | ||
} | ||
export default Form | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,68 @@ | ||
import styled from 'styled-components' | ||
import {getCustomerDetail} from '../common/customerInfo' | ||
import {getCartItems} from '../common/pokemonStorage' | ||
|
||
const Wrapper = styled.div` | ||
margin: 5px; | ||
width: 550px; | ||
background-color: #ffffcc ; | ||
`; | ||
const Message = styled.h4` | ||
padding: 10px; | ||
display: flex; | ||
`; | ||
const ScrollStyle = styled.div` | ||
overflow-y: scroll; | ||
max-height: 500px; | ||
width: 500px; | ||
`; | ||
const CardStyle = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr 3fr 1fr; | ||
img { | ||
width: 100px; | ||
background-color: cream; | ||
} | ||
div { | ||
padding: 1rem; | ||
} | ||
`; | ||
|
||
const CardPriceStyle = styled.div` | ||
padding: 1rem; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-end; | ||
`; | ||
const Card = ({name, img, type, price, quantity}) =>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should not this |
||
<CardStyle> | ||
<img src={img} alt={name} /> | ||
<div> | ||
<strong>{name}</strong> | ||
<p>{type}</p> | ||
</div> | ||
<CardPriceStyle> | ||
<p>{quantity}</p> <p>{price}</p> | ||
</CardPriceStyle> | ||
</CardStyle> | ||
); | ||
export function OrderCompleted() { | ||
return <div>OrderCompleted</div>; | ||
const customerName = getCustomerDetail(); | ||
const cart= getCartItems(); | ||
return ( | ||
<Wrapper> | ||
<Message>Hello {customerName} your order was successfully placed, Thank You for Shopping with us!!</Message> | ||
<br /> | ||
<Message>ORDERED LIST</Message> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: don't use caps text in the UI, this is not a good practice. |
||
<ScrollStyle> | ||
{cart.map((item) => ( | ||
<Card | ||
key={item.name} | ||
{...item} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better would be to not just spread whatever is inside item object, but explicitely pass props one by one. This will increase quality of the code (and you want need to turn off eslint rules) |
||
/> | ||
))} | ||
<h5>TOTAL AMOUNT={cart.reduce((acc, current) => acc + current.price, 0)}</h5> | ||
</ScrollStyle> | ||
</Wrapper> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,67 @@ | ||
import styled from "styled-components"; | ||
import { useState } from "react"; | ||
import { useHistory } from "react-router-dom"; | ||
import { GRAY } from "./constants"; | ||
import { Card } from "./components/Card"; | ||
import { Total } from "./components/Total"; | ||
import { getCartItems, removeFromCart } from "../common/pokemonStorage"; | ||
|
||
const LayoutStyle = styled.div` | ||
display: grid; | ||
grid-template-columns: 2fr 1fr; | ||
max-width: 1024px; | ||
background-color: ${GRAY}; | ||
margin: auto; | ||
`; | ||
|
||
const PanelStyle = styled.div` | ||
margin: 1rem; | ||
background-color: white; | ||
padding: 1rem; | ||
`; | ||
|
||
const ScrollStyle = styled.div` | ||
overflow-y: scroll; | ||
max-height: 500px; | ||
`; | ||
|
||
export function ShoppingCart() { | ||
return <div>ShoppingCart</div>; | ||
const [cart, setCart] = useState(getCartItems()); | ||
const history = useHistory(); | ||
const handleRemove = (name) => { | ||
setCart(removeFromCart(name)); | ||
}; | ||
|
||
const handleCheckout = () =>{ | ||
history.push(`/checkout`); | ||
} | ||
if (cart.length === 0) { | ||
return ( | ||
<LayoutStyle> | ||
<PanelStyle> | ||
<h2>Your cart is empty</h2>{" "} | ||
</PanelStyle> | ||
</LayoutStyle> | ||
); | ||
} | ||
|
||
return ( | ||
<LayoutStyle> | ||
<PanelStyle> | ||
<h2>Place you order ({cart.length} article)</h2> | ||
<ScrollStyle> | ||
{cart.map((item) => ( | ||
<Card | ||
key={item.name} | ||
{...item} | ||
onRemove={() => handleRemove(item.name)} | ||
/> | ||
))} | ||
</ScrollStyle> | ||
</PanelStyle> | ||
<PanelStyle> | ||
<Total total={cart.reduce((acc, current) => acc + current.price, 0)} handleCheckout= {handleCheckout} /> | ||
</PanelStyle> | ||
</LayoutStyle> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import styled from "styled-components"; | ||
import { GRAY } from "../constants"; | ||
import { HRStyle } from "./Hr"; | ||
|
||
const CardStyle = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr 3fr 1fr; | ||
img { | ||
width: 100px; | ||
background-color: ${GRAY}; | ||
} | ||
div { | ||
padding: 1rem; | ||
} | ||
`; | ||
|
||
const CardPriceStyle = styled.div` | ||
padding: 1rem; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-end; | ||
`; | ||
|
||
const RemoveStyle = styled.a` | ||
color: black; | ||
cursor: pointer; | ||
&:hover { | ||
text-decoration: underline; | ||
} | ||
`; | ||
|
||
export const Card = ({ name, img, type, price, quantity, onRemove }) => ( | ||
<> | ||
<CardStyle> | ||
<img src={img} alt={name} /> | ||
<div> | ||
<strong>{name}</strong> | ||
<p>{type}</p> | ||
<RemoveStyle onClick={onRemove}>Remove</RemoveStyle> | ||
</div> | ||
<CardPriceStyle> | ||
<p>{quantity}</p> | ||
<p>{price}</p> | ||
</CardPriceStyle> | ||
</CardStyle> | ||
<HRStyle /> | ||
</> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import styled from "styled-components"; | ||
import { GRAY } from "../constants"; | ||
|
||
export const HRStyle = styled.hr` | ||
border: 0.5px solid ${GRAY}; | ||
`; |
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.
something wrong with indentation. And check it in all the files and code, because there are some places below when it's broken.