|
| 1 | +import React, { useEffect } from "react"; |
| 2 | +import { useSelector, useDispatch } from "react-redux"; |
| 3 | +import { fetchLoggedInUserOrderAsync, selectUserOrders } from "../userSlice"; |
| 4 | +import { selectLoggedInUser } from "../../auth/authSlice"; |
| 5 | + |
| 6 | +export default function UserOrders() { |
| 7 | + const user = useSelector(selectLoggedInUser); |
| 8 | + const dispatch = useDispatch(); |
| 9 | + const orders = useSelector(selectUserOrders); |
| 10 | + |
| 11 | + useEffect(() => { |
| 12 | + dispatch(fetchLoggedInUserOrderAsync(user.id)); |
| 13 | + }, []); |
| 14 | + |
| 15 | + return ( |
| 16 | + <div> |
| 17 | + {orders.map((order) => ( |
| 18 | + <div> |
| 19 | + <div> |
| 20 | + <div className="mx-auto mt-12 bg-white max-w-7xl px-4 sm:px-6 lg:px-8"> |
| 21 | + <div className="border-t border-gray-200 px-4 py-6 sm:px-6"> |
| 22 | + <h1 className="text-4xl my-5 font-bold tracking-tight text-gray-900"> |
| 23 | + Order # {order.id} |
| 24 | + </h1> |
| 25 | + <h2 className="text-xl my-5 font-bold tracking-tight text-red-900"> |
| 26 | + Order Status : {order.status} |
| 27 | + </h2> |
| 28 | + <div className="flow-root"> |
| 29 | + <ul role="list" className="-my-6 divide-y divide-gray-200"> |
| 30 | + {order.items.map((item) => ( |
| 31 | + <li key={item.id} className="flex py-6"> |
| 32 | + <div className="h-24 w-24 flex-shrink-0 overflow-hidden rounded-md border border-gray-200"> |
| 33 | + <img |
| 34 | + src={item.thumbnail} |
| 35 | + alt={item.title} |
| 36 | + className="h-full w-full object-cover object-center" |
| 37 | + /> |
| 38 | + </div> |
| 39 | + |
| 40 | + <div className="ml-4 flex flex-1 flex-col"> |
| 41 | + <div> |
| 42 | + <div className="flex justify-between text-base font-medium text-gray-900"> |
| 43 | + <h3> |
| 44 | + <a href={item.href}>{item.title}</a> |
| 45 | + </h3> |
| 46 | + <p className="ml-4">${item.price}</p> |
| 47 | + </div> |
| 48 | + <p className="mt-1 text-sm text-gray-500"> |
| 49 | + {item.brand} |
| 50 | + </p> |
| 51 | + </div> |
| 52 | + <div className="flex flex-1 items-end justify-between text-sm"> |
| 53 | + <div className="text-gray-500"> |
| 54 | + <label |
| 55 | + htmlFor="quantity" |
| 56 | + className="inline mr-5 text-sm font-medium leading-6 text-gray-900" |
| 57 | + > |
| 58 | + Qty:{item.quantity} |
| 59 | + </label> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div className="flex"></div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + </li> |
| 66 | + ))} |
| 67 | + </ul> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + |
| 71 | + <div className="border-t border-gray-200 px-4 py-6 sm:px-6"> |
| 72 | + <div className="flex justify-between my-2 text-base font-medium text-gray-900"> |
| 73 | + <p>Subtotal</p> |
| 74 | + <p>${order.totalAmount}</p> |
| 75 | + </div> |
| 76 | + <div className="flex justify-between my-2 text-base font-medium text-gray-900"> |
| 77 | + <p>Total Items in Cart</p> |
| 78 | + <p>{order.totalItems} Items</p> |
| 79 | + </div> |
| 80 | + <p className="mt-0.5 text-sm text-gray-500">Shipping Address</p> |
| 81 | + <div className="flex justify-between gap-x-6 px-5 py-5 border-solid border-2 border-gray-200"> |
| 82 | + <div className="flex gap-x-4"> |
| 83 | + <div className="min-w-0 flex-auto"> |
| 84 | + <p className="text-sm font-semibold leading-6 text-gray-900"> |
| 85 | + {order.selectedAddress.name} |
| 86 | + </p> |
| 87 | + <p className="mt-1 truncate text-xs leading-5 text-gray-500"> |
| 88 | + {order.selectedAddress.street} |
| 89 | + </p> |
| 90 | + <p className="mt-1 truncate text-xs leading-5 text-gray-500"> |
| 91 | + {order.selectedAddress.pinCode} |
| 92 | + </p> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + <div className="hidden sm:flex sm:flex-col sm:items-end"> |
| 96 | + <p className="text-sm leading-6 text-gray-900"> |
| 97 | + Phone: {order.selectedAddress.phone} |
| 98 | + </p> |
| 99 | + <p className="text-sm leading-6 text-gray-500"> |
| 100 | + {order.selectedAddress.city} |
| 101 | + </p> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + ))} |
| 109 | + </div> |
| 110 | + ); |
| 111 | +} |
0 commit comments