import React from 'react';
import {useEffect, useState} from "react";
import {Box, CircularProgress, Divider, Pagination, Typography} from "@mui/material";
import {NotFoundBlock} from "../../components/NotFoundBlock";
import {connect} from "react-redux";
import {actionFullOrderFind, actionOrderCount} from "../../actions/ActionOrderFind";
import {actionMyOrderClear} from "../../reducers/MyOrdersReducer";
import {AccordionItem} from "./AccordionItem";
const MainOrders = ({itemsPerPage=100,
orders,
ordersPreload,
orderCount,
onFindOrders,
onOrdersClear,
onGetCountOrder}) => {
const [page, setPage] = useState(1)
const [count, setCount] = useState(1)
const handleChange = (event, value) => {
onOrdersClear()
setPage(value);
onFindOrders((itemsPerPage * value)-itemsPerPage, itemsPerPage);
}
useEffect(() => {
if (Object.entries(orders).length === 0 && page === 1) onFindOrders(null, itemsPerPage)
if (!orderCount) onGetCountOrder()
else {
setCount(Math.ceil(+orderCount?.payload / itemsPerPage))
}
}, [orders, orderCount])
return (
<>
{ordersPreload?.status === "PENDING" || Object.entries(orders).length === 0 ?
:
Object.entries(orders?.orderResult).length > 0 ?
{orderCount?.payload &&
Total orders: {orderCount.payload || 0}
}
{Object.values(orders.orderResult)
.map(item => )
}
:
}
>
)
}
export const CMainOrders = connect(state => ({
orders: state.myorders,
ordersPreload: state.promise['orderFind'],
orderCount: state.promise['orderCount']}),
{
onFindOrders: actionFullOrderFind,
onOrdersClear: actionMyOrderClear,
onGetCountOrder: actionOrderCount})
(MainOrders)