(props)
| 4 | import CheckoutSteps from '../components/CheckoutSteps'; |
| 5 | import { createOrder } from '../actions/orderActions'; |
| 6 | function PlaceOrderScreen(props) { |
| 7 | |
| 8 | const cart = useSelector(state => state.cart); |
| 9 | const orderCreate = useSelector(state => state.orderCreate); |
| 10 | const { loading, success, error, order } = orderCreate; |
| 11 | |
| 12 | const { cartItems, shipping, payment } = cart; |
| 13 | if (!shipping.address) { |
| 14 | props.history.push("/shipping"); |
| 15 | } else if (!payment.paymentMethod) { |
| 16 | props.history.push("/payment"); |
| 17 | } |
| 18 | const itemsPrice = cartItems.reduce((a, c) => a + c.price * c.qty, 0); |
| 19 | const shippingPrice = itemsPrice > 100 ? 0 : 10; |
| 20 | const taxPrice = 0.15 * itemsPrice; |
| 21 | const totalPrice = itemsPrice + shippingPrice + taxPrice; |
| 22 | |
| 23 | const dispatch = useDispatch(); |
| 24 | |
| 25 | const placeOrderHandler = () => { |
| 26 | // create an order |
| 27 | dispatch(createOrder({ |
| 28 | orderItems: cartItems, shipping, payment, itemsPrice, shippingPrice, |
| 29 | taxPrice, totalPrice |
| 30 | })); |
| 31 | } |
| 32 | useEffect(() => { |
| 33 | if (success) { |
| 34 | props.history.push("/order/" + order._id); |
| 35 | } |
| 36 | |
| 37 | }, [success]); |
| 38 | |
| 39 | return <div> |
| 40 | <CheckoutSteps step1 step2 step3 step4 ></CheckoutSteps> |
| 41 | <div className="placeorder"> |
| 42 | <div className="placeorder-info"> |
| 43 | <div> |
| 44 | <h3> |
| 45 | Shipping |
| 46 | </h3> |
| 47 | <div> |
| 48 | {cart.shipping.address}, {cart.shipping.city}, |
| 49 | {cart.shipping.postalCode}, {cart.shipping.country}, |
| 50 | </div> |
| 51 | </div> |
| 52 | <div> |
| 53 | <h3>Payment</h3> |
| 54 | <div> |
| 55 | Payment Method: {cart.payment.paymentMethod} |
| 56 | </div> |
| 57 | </div> |
| 58 | <div> |
| 59 | <ul className="cart-list-container"> |
| 60 | <li> |
| 61 | <h3> |
| 62 | Shopping Cart |
| 63 | </h3> |
nothing calls this directly
no outgoing calls
no test coverage detected