PregaoLista.jsx
import { makeStyles } from '@material-ui/styles'; import { Page } from 'components'; import React, { useEffect } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { pesquisarPregao } from '../../reducers/acoes/PregaoAcoes'; import { SearchBarPregao } from './componentes'; import Resultado from './componentes/ResultadoPregao/Resultado'; const useStyles = makeStyles(theme => ({ root: { padding: theme.spacing(3) }, results: { marginTop: theme.spacing(3) } }) ); const PregaoLista = props => { useEffect(() => { props.pesquisarPregao(0, 10, 'id', 'ASC') }, []); const classes = useStyles(); const onSearch = () => { console.log(props.paginacao) } return ( <Page className={classes.root} title="Pregões" > <SearchBarPregao onSearch={onSearch} /> <Resultado className={classes.results} pregoesLista={props.pregoes} paginacao={props.paginacao} /> </Page> ) } const mapStateToProps = state => ({ pregoes: state.pregao.pregoesPesquisa, paginacao: state.pregao.paginacao }) const mapDispatchToProps = dispatch => bindActionCreators({pesquisarPregao}, dispatch) export default connect(mapStateToProps, mapDispatchToProps)(PregaoLista)
Resultado.jsx
import { Card, CardActions, CardContent, CardHeader, Checkbox, colors, Divider, Table, TableBody, TableCell, TableHead, TablePagination, TableRow, Typography } from '@material-ui/core'; import { makeStyles } from '@material-ui/styles'; import clsx from 'clsx'; import { Label, GenericMoreButton, TableEditBar } from 'components'; import PropTypes from 'prop-types'; import React, { useState } from 'react'; import PerfectScrollbar from 'react-perfect-scrollbar'; const useStyles = makeStyles(theme => ({ root: {}, filterButton: { marginRight: theme.spacing(2) }, content: { padding: 0 }, inner: { minWidth: 1150 }, actions: { padding: theme.spacing(0, 1), justifyContent: 'flex-end' } })); const Resultado = props => { const { className, pregoesLista, paginacao, ...rest } = props; const classes = useStyles(); const [selectedOrders, setSelectedOrders] = useState([]); const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(10); const handleSelectAll = event => { const selectedOrders = event.target.checked ? pregoesLista.map(order => order.id) : []; setSelectedOrders(selectedOrders); }; const handleSelectOne = (event, id) => { const selectedIndex = selectedOrders.indexOf(id); let newSelectedOrders = []; if (selectedIndex === -1) { newSelectedOrders = newSelectedOrders.concat(selectedOrders, id); } else if (selectedIndex === 0) { newSelectedOrders = newSelectedOrders.concat(selectedOrders.slice(1)); } else if (selectedIndex === selectedOrders.length - 1) { newSelectedOrders = newSelectedOrders.concat(selectedOrders.slice(0, -1)); } else if (selectedIndex > 0) { newSelectedOrders = newSelectedOrders.concat( selectedOrders.slice(0, selectedIndex), selectedOrders.slice(selectedIndex + 1) ); } setSelectedOrders(newSelectedOrders); }; const handleChangePage = (event, page) => { setPage(page); }; const handleChangeRowsPerPage = event => { setRowsPerPage(event.target.value); }; const paymentStatusColors = { MENOR_PRECO_POR_ITEM: colors.orange[600], MENOR_PRECO_POR_LOTE: colors.green[600], MENOR_PRECO_GLOBAL: colors.red[600] }; return ( <div {...rest} className={clsx(classes.root, className)} > <Typography color="textSecondary" gutterBottom variant="body2" > {pregoesLista.length} Registros encontrados. Página {page + 1} de {' '} {Math.ceil(pregoesLista.length / rowsPerPage)} </Typography> <Card> <CardHeader action={<GenericMoreButton />} title="Resultado de pregões" /> <Divider /> <CardContent className={classes.content}> <PerfectScrollbar> <div className={classes.inner}> <Table> <TableHead> <TableRow> <TableCell padding="checkbox"> <Checkbox checked={selectedOrders.length === pregoesLista.length} color="primary" indeterminate={ selectedOrders.length > 0 && selectedOrders.length < pregoesLista.length } onChange={handleSelectAll} /> </TableCell> <TableCell>Licitação</TableCell> <TableCell>Competência</TableCell> <TableCell>Fase</TableCell> <TableCell>Regime</TableCell> <TableCell>Valor Estimado - R$</TableCell> <TableCell>Quantidade de itens</TableCell> <TableCell>Valor Minimo por Lance - R$</TableCell> <TableCell>Quantidade de fornecedor</TableCell> <TableCell>Abertura</TableCell> <TableCell>Fechamento</TableCell> <TableCell></TableCell> </TableRow> </TableHead> <TableBody> {pregoesLista.slice(0, rowsPerPage).map(pregao => ( <TableRow key={pregao.id} selected={selectedOrders.indexOf(pregao.id) !== -1} > <TableCell padding="checkbox"> <Checkbox checked={selectedOrders.indexOf(pregao.id) !== -1} color="primary" onChange={event => handleSelectOne(event, pregao.id)} value={selectedOrders.indexOf(pregao.id) !== -1} /> </TableCell> <TableCell>{pregao.licitacao}</TableCell> <TableCell>{pregao.competencia}</TableCell> <TableCell>{pregao.fase}</TableCell> <TableCell> <Label color={paymentStatusColors[pregao.codRegime]} variant="outlined" > {pregao.regime} </Label> </TableCell> <TableCell>{pregao.valorEstimado}</TableCell> <TableCell>{pregao.quantidadeItens}</TableCell> <TableCell>{pregao.valorPorLance}</TableCell> <TableCell>{pregao.quantidadeFornecedor}</TableCell> <TableCell>{pregao.abertura}</TableCell> <TableCell>{pregao.fechamento}</TableCell> <TableCell>Ações</TableCell> </TableRow> ))} </TableBody> </Table> </div> </PerfectScrollbar> </CardContent> <CardActions className={classes.actions}> <TablePagination component="div" count={pregoesLista.length} onChangePage={handleChangePage} onChangeRowsPerPage={handleChangeRowsPerPage} page={page} rowsPerPage={rowsPerPage} rowsPerPageOptions={[10, 25, 100]} /> </CardActions> </Card> <TableEditBar selected={selectedOrders} /> </div> ); }; Resultado.propTypes = { className: PropTypes.string, pregoesLista: PropTypes.array.isRequired, paginacao: PropTypes.any }; Resultado.defaultProps = { pregoesLista: [] }; export default Resultado;
Se no Resultado coloco assim
return ( <div {...rest} className={clsx(classes.root, className)} > <Typography color="textSecondary" gutterBottom variant="body2" > {paginacao.tamanhoRegistros} {pregoesLista.length} Registros encontrados. Página {page + 1} de {' '} {Math.ceil(pregoesLista.length / rowsPerPage)} </Typography>
Erro
O que pode ser ?