TypeError: orderItem.items is undefined

1
Posted at January 21, 2022 24 Views . 0 Saved .

Sir, please help me to get rid out of this typeError

My order index.js code

import React, { useState } from "react";import { useDispatch, useSelector } from "react-redux"; import { updateOrder } from "../../actions"; import Layout from "../Layout"; import Card from "../UI/Card"; import "./style.css"; /** * @author * @function Orders **/ const Orders = (props) => { const order = useSelector((state) => state.order); const [type, setType] = useState(""); const dispatch = useDispatch(); const onOrderUpdate = (orderId) => { const payload = { orderId, type, }; dispatch(updateOrder(payload)); }; const formatDate = (date) => { if (date) { const d = new Date(date); return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`; } return ""; }; return ( {order.orders.map((orderItem, index) => (

Items
{orderItem.items.map((item, index) => (
{item.productId.name}
))}
Total Price
{orderItem.totalAmount}
Payment Type
{orderItem.paymentType}
Payment Status
{orderItem.paymentStatus}
{orderItem.orderStatus.map((status) => (
{status.type}
{formatDate(status.date)}
))}
{/* select input to apply order action */}
setType(e.target.value)}> {orderItem.orderStatus.map((status) => { return ( <> {!status.isCompleted ? ( ) : null} </> ); })}
{/* button to confirm action */}
onOrderUpdate(orderItem._id)}> confirm
))} ); }; export default Orders;

order.action.js

import axios from "../helpers/axios";import { orderConstants } from "./constants"; export const getCustomerOrders = () => { return async (dispatch) => { dispatch({ type: orderConstants.GET_CUSTOMER_ORDER_REQUEST }); try { const res = await axios.post("/order/getCustomerOrders"); if (res.status === 200) { const { orders } = res.data; dispatch({ type: orderConstants.GET_CUSTOMER_ORDER_SUCCESS, payload: { orders }, }); } else { const { error } = res.data; dispatch({ type: orderConstants.GET_CUSTOMER_ORDER_FAILURE, payload: { error }, }); } } catch (error) { console.log(error); } }; }; export const updateOrder = (payload) => { return async (dispatch) => { dispatch({ type: orderConstants.UPDATE_CUSTOMER_ORDER_REQUEST }); try { const res = await axios.post("/order/update", payload); if (res.status === 201) { dispatch({ type: orderConstants.UPDATE_CUSTOMER_ORDER_SUCCESS }); dispatch(getCustomerOrders()); } else { const { error } = res.data; dispatch({ type: orderConstants.UPDATE_CUSTOMER_ORDER_FAILURE, payload: { error }, }); } } catch (error) { console.log(error); } }; };

order.reducer.js

import { orderConstants } from "../actions/constants"; const initState = { orders: [1], }; export default (state = initState, action) => { switch (action.type) { case orderConstants.GET_CUSTOMER_ORDER_SUCCESS: console.log("FAIL") state = { ...state, orders: action.payload.orders, }; break; } return state; };

India
Current I am a software developer my age is 13 yrs and I know Web Developing using Reactjs, Mern, and as well Android Developing also
0 Comments

Loading..!