-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
257 additions
and
4 deletions.
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,53 @@ | ||
import React, { useState } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { Form, Button, Col } from "react-bootstrap"; | ||
import FormContainer from "../components/FormContainer"; | ||
import CheckoutSteps from "../components/CheckoutSteps"; | ||
import { savePaymentMethod } from "../actions/cartActions"; | ||
|
||
function PaymentPage({ history }) { | ||
const cart = useSelector((state) => state.cart); | ||
const { shippingAddress } = cart; | ||
|
||
const dispatch = useDispatch(); | ||
|
||
const [paymentMethod, setPaymentMethod] = useState("PAYPAL"); | ||
|
||
if (!shippingAddress) { | ||
history.push("/shipping"); | ||
} | ||
|
||
const submitHandler = (e) => { | ||
e.preventDefault(); | ||
dispatch(savePaymentMethod(paymentMethod)); | ||
history.push("/placeorder"); | ||
}; | ||
|
||
return ( | ||
<> | ||
<CheckoutSteps step1 step2 step3 /> | ||
<FormContainer> | ||
<Form onSubmit={submitHandler}> | ||
<Form.Group> | ||
<Form.Label as="legend">Select Method</Form.Label> | ||
<Col> | ||
<Form.Check | ||
type="radio" | ||
label="PayPal or Credit Card" | ||
id="paypal" | ||
name="paymentMethod" | ||
checked | ||
onChange={(e) => setPaymentMethod(e.target.value)} | ||
></Form.Check> | ||
</Col> | ||
</Form.Group> | ||
<Button type="submit" variant="primary"> | ||
Submit | ||
</Button> | ||
</Form> | ||
</FormContainer> | ||
</> | ||
); | ||
} | ||
|
||
export default PaymentPage; |
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,129 @@ | ||
import React from "react"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import { Button, Col, Row, ListGroup, Image, Card } from "react-bootstrap"; | ||
import CheckoutSteps from "../components/CheckoutSteps"; | ||
import Message from "../components/Message"; | ||
import { Link } from "react-router-dom"; | ||
|
||
function PlaceOrderPage() { | ||
const cart = useSelector((state) => state.cart); | ||
|
||
cart.itemsPrice = cart.cartItems | ||
.reduce((acc, item) => acc + item.price * item.qtn, 0) | ||
.toFixed(2); | ||
|
||
cart.shippingPrice = (cart.itemsPrice > 100 ? 0 : 10).toFixed(2); | ||
|
||
cart.taxPrice = Number(0.2 * cart.itemsPrice).toFixed(2); | ||
|
||
cart.totalPrice = ( | ||
Number(cart.itemsPrice) + | ||
Number(cart.taxPrice) + | ||
Number(cart.shippingPrice) | ||
).toFixed(2); | ||
|
||
function placeorderHandler() { | ||
console.log("placeorder"); | ||
} | ||
return ( | ||
<> | ||
<CheckoutSteps step1 step2 step3 step4 /> | ||
<Row> | ||
<Col md={8}> | ||
<ListGroup variant="flush"> | ||
<ListGroup.Item> | ||
<h2>Shipping Info</h2> | ||
<p> | ||
<strong>Shipping: </strong> | ||
{cart.shippingAddress.address}, {cart.shippingAddress.city},{" "} | ||
{cart.shippingAddress.country} | ||
</p> | ||
</ListGroup.Item> | ||
<ListGroup.Item> | ||
<h2>Payment Method</h2> | ||
<p> | ||
<strong>Method: </strong> | ||
{cart.paymentMethod} | ||
</p> | ||
</ListGroup.Item> | ||
<ListGroup.Item> | ||
<h2>Order Item: </h2> | ||
{cart.cartItems.length === 0 ? ( | ||
<Message variant="info"> Your cart is empty.</Message> | ||
) : ( | ||
<ListGroup variant="flush"> | ||
{cart.cartItems.map((item, index) => ( | ||
<ListGroup.Item key={index}> | ||
<Row> | ||
<Col md={2}> | ||
<Image | ||
src={item.image} | ||
alt={item.name} | ||
fluid | ||
rounded | ||
/> | ||
</Col> | ||
<Col> | ||
<Link to={`/product/${item._id}`}>{item.name}</Link> | ||
</Col> | ||
<Col md={5}> | ||
{item.qtn} x Rs.{item.price} = Rs.{" "} | ||
{(item.qtn * item.price).toFixed(2)} | ||
</Col> | ||
</Row> | ||
</ListGroup.Item> | ||
))} | ||
</ListGroup> | ||
)} | ||
</ListGroup.Item> | ||
</ListGroup> | ||
</Col> | ||
<Col md={4}> | ||
<Card> | ||
<ListGroup variant="flush"> | ||
<ListGroup.Item> | ||
<h2>Order Summery</h2> | ||
</ListGroup.Item> | ||
<ListGroup.Item> | ||
<Row> | ||
<Col>Item:</Col> | ||
<Col>Rs. {cart.itemsPrice}</Col> | ||
</Row> | ||
</ListGroup.Item> | ||
<ListGroup.Item> | ||
<Row> | ||
<Col>Shipping: </Col> | ||
<Col>Rs. {cart.shippingPrice}</Col> | ||
</Row> | ||
</ListGroup.Item> | ||
<ListGroup.Item> | ||
<Row> | ||
<Col>Tax: </Col> | ||
<Col>Rs. {cart.taxPrice}</Col> | ||
</Row> | ||
</ListGroup.Item> | ||
<ListGroup.Item> | ||
<Row> | ||
<Col>Total: </Col> | ||
<Col>Rs. {cart.totalPrice}</Col> | ||
</Row> | ||
</ListGroup.Item> | ||
<ListGroup.Item> | ||
<Button | ||
type="button" | ||
className="btn-block" | ||
disabled={cart.cartItems.length === 0} | ||
onClick={placeorderHandler} | ||
> | ||
Place Order | ||
</Button> | ||
</ListGroup.Item> | ||
</ListGroup> | ||
</Card> | ||
</Col> | ||
</Row> | ||
</> | ||
); | ||
} | ||
|
||
export default PlaceOrderPage; |
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
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,48 @@ | ||
import React from "react"; | ||
import { Nav } from "react-bootstrap"; | ||
import { LinkContainer } from "react-router-bootstrap"; | ||
|
||
function CheckoutSteps({ step1, step2, step3, step4 }) { | ||
return ( | ||
<Nav className="justify-content-center mb-4"> | ||
<Nav.Item> | ||
{step1 ? ( | ||
<LinkContainer to="/login"> | ||
<Nav.Link>Login</Nav.Link> | ||
</LinkContainer> | ||
) : ( | ||
<Nav.Link disabled>Login</Nav.Link> | ||
)} | ||
</Nav.Item> | ||
<Nav.Item> | ||
{step2 ? ( | ||
<LinkContainer to="/shipping"> | ||
<Nav.Link>Shipping</Nav.Link> | ||
</LinkContainer> | ||
) : ( | ||
<Nav.Link disabled>Shipping</Nav.Link> | ||
)} | ||
</Nav.Item> | ||
<Nav.Item> | ||
{step3 ? ( | ||
<LinkContainer to="/payment"> | ||
<Nav.Link>Payment</Nav.Link> | ||
</LinkContainer> | ||
) : ( | ||
<Nav.Link disabled>Payment</Nav.Link> | ||
)} | ||
</Nav.Item> | ||
<Nav.Item> | ||
{step4 ? ( | ||
<LinkContainer to="/placeorder"> | ||
<Nav.Link>Place Order</Nav.Link> | ||
</LinkContainer> | ||
) : ( | ||
<Nav.Link disabled>Place Order</Nav.Link> | ||
)} | ||
</Nav.Item> | ||
</Nav> | ||
); | ||
} | ||
|
||
export default CheckoutSteps; |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export const CART_ADD_ITEM = "CART_ADD_ITEM"; | ||
export const CART_REMOVE_ITEM = "CART_REMOVE_ITEM"; | ||
|
||
export const CART_SAVE_SHIPPING_ADDRESS = "CART_SAVE_SHIPPING_ADDRESS"; | ||
|
||
export const CART_SAVE_PAYMENT_METHOD = "CART_SAVE_PAYMENT_METHOD"; |
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