diff --git a/client/src/components/Ecommerce/Screen/PaymentScreen.js b/client/src/components/Ecommerce/Screen/PaymentScreen.js index ed0d440..eb7c343 100644 --- a/client/src/components/Ecommerce/Screen/PaymentScreen.js +++ b/client/src/components/Ecommerce/Screen/PaymentScreen.js @@ -46,7 +46,7 @@ const PaymentScreen = ({ history }) => { id="Stripe" name="paymentMethod" value="Stripe" - checked={paymentMethod === "PayPal" ? true : false} + checked={paymentMethod === "PayPal"} onChange={(e) => setPaymentMethod(e.target.value)} > diff --git a/client/src/components/Ecommerce/Screen/PlaceOrderScreen.js b/client/src/components/Ecommerce/Screen/PlaceOrderScreen.js index f895ac7..12f7a8b 100644 --- a/client/src/components/Ecommerce/Screen/PlaceOrderScreen.js +++ b/client/src/components/Ecommerce/Screen/PlaceOrderScreen.js @@ -4,15 +4,34 @@ import { Button, Row, Col, ListGroup, Image, Card } from "react-bootstrap"; import { useDispatch, useSelector } from "react-redux"; import Message from "../Message"; import CheckoutSteps from "../CheckoutSteps"; - -/* import { ORDER_CREATE_RESET } from "../constants/orderConstants"; -import { USER_DETAILS_RESET } from "../constants/userConstants"; */ +import { createOrder } from "../../../redux/actions/orderActions"; const PlaceOrderScreen = ({ history }) => { + const dispatch = useDispatch(); + const cart = useSelector((state) => state.cart); + const orderCreate = useSelector((state) => state.orderCreate); + const { order, success, error } = orderCreate; + + useEffect(() => { + if (success) { + history.push(`/order/${order._id}`); + } + // eslint-disable-next-line + }, [history, success]); + const placeOrderHandler = () => { - console.log(""); + dispatch( + createOrder({ + orderItems: cart.cartItems, + shippingAddress: cart.shippingAddress, + paymentMethod: cart.paymentMethod, + itemsPrice: cart.itemsPrice, + shippingPrice: cart.shippingPrice, + totalPrice: cart.totalPrice, + }) + ); }; //Calculate Price const addDecimals = (num) => { @@ -22,10 +41,9 @@ const PlaceOrderScreen = ({ history }) => { cart.itemsPrice = addDecimals( cart.cartItems.reduce((acc, item) => acc + item.price * item.qty, 0) ); - cart.shippingPrice = 30; //addDecimals(cart.itemsPrice > 100 ? 0 : 100); - /* cart.taxPrice = addDecimals(Number((0.15 * cart.itemsPrice).toFixed(2))); */ + cart.shippingPrice = 30; + cart.totalPrice = Number(cart.itemsPrice) + Number(cart.shippingPrice); - //Number(cart.taxPrice) return ( <> @@ -34,7 +52,7 @@ const PlaceOrderScreen = ({ history }) => { -

Shipping

+

Delivery Location

Address: {cart.shippingAddress.address}, {cart.shippingAddress.city}{" "} @@ -47,7 +65,6 @@ const PlaceOrderScreen = ({ history }) => { Method: {cart.paymentMethod} -

Order Items

{cart.cartItems.length === 0 ? ( @@ -90,13 +107,13 @@ const PlaceOrderScreen = ({ history }) => { Items - ${cart.itemsPrice} + ৳{cart.itemsPrice} Delivery Charge - ${cart.shippingPrice} + ৳{cart.shippingPrice} {/* @@ -108,12 +125,12 @@ const PlaceOrderScreen = ({ history }) => { Total - ${cart.totalPrice} + ৳{cart.totalPrice} - {/* + {error && {error}} - */} +