-
- {[0, 1, 2, 3, 4, 5, 6].map(item => (
+
+ {[0, 1, 2, 3, 4, 5].map(item => (
))}
{[0, 1, 2, 3, 4, 5, 6, 7].map(row => (
-
+
-
@@ -123,9 +80,7 @@ const Products = () => {
totalSold: product.quantitySold,
revenue: product.revenue,
lastPrice: product.lastPrice,
- stock: product.stock,
- firstSaleDate: product.firstSaleDate,
- lastSaleDate: product.lastSaleDate
+ stock: product.stock
}));
const filteredProducts = normalizedSearch
? products.filter(product =>
@@ -139,7 +94,8 @@ const Products = () => {
// Pagination logic
const totalPages = Math.ceil(productsData.length / itemsPerPage);
- const startIndex = (currentPage - 1) * itemsPerPage;
+ const safeCurrentPage = Math.min(currentPage, totalPages || 1);
+ const startIndex = (safeCurrentPage - 1) * itemsPerPage;
const paginatedData = productsData.slice(startIndex, startIndex + itemsPerPage);
const isRefreshing = isLoading && productAnalytics.length > 0;
@@ -185,7 +141,6 @@ const Products = () => {
'Descrição': product.name,
'Preço Atual (R$)': product.lastPrice.toFixed(2).replace('.', ','),
'Total Vendido (un.)': product.totalSold,
- 'Status': getProductHealth(product, dateRange).label,
'Estoque': product.stock,
'Receita Gerada (R$)': product.revenue.toFixed(2).replace('.', ',')
}));
@@ -213,17 +168,13 @@ const Products = () => {
ID Produto |
Descrição |
Total Vendido |
-
Status |
Estoque |
Receita Gerada |
Ações |
- {paginatedData.map((product) => {
- const health = getProductHealth(product, dateRange);
-
- return (
+ {paginatedData.map((product) => (
| #{product.id} |
@@ -236,11 +187,6 @@ const Products = () => {
{product.totalSold} un.
|
-
-
- {health.label}
-
- |
{product.stock} un.
@@ -257,54 +203,27 @@ const Products = () => {
|
- );
- })}
+ ))}
- {/* Pagination Controls */}
-
-
- Mostrar
-
- itens por página
-
-
-
-
- Mostrando {productsData.length > 0 ? startIndex + 1 : 0} a {Math.min(startIndex + itemsPerPage, productsData.length)} de {productsData.length} produtos
-
-
-
-
-
-
-
+
{
+ setItemsPerPage(pageSize);
+ setCurrentPage(1);
+ }}
+ />
)}
diff --git a/src/pages/Rfm.tsx b/src/pages/Rfm.tsx
index 754b763..4840931 100644
--- a/src/pages/Rfm.tsx
+++ b/src/pages/Rfm.tsx
@@ -1,7 +1,8 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Link, useOutletContext } from 'react-router-dom';
-import { ChevronLeft, ChevronRight, Download, Filter, Search, Users } from 'lucide-react';
+import { Download, Filter, Search, Users } from 'lucide-react';
import DateRangePicker from '../components/DateRangePicker';
+import PaginationControls from '../components/PaginationControls';
import RefreshStatus from '../components/RefreshStatus';
import { exportToCSV, fetchRfmAnalytics, getCachedRfmAnalytics } from '../dataService';
import type { DateRange, RfmAnalytics, RfmClient, RfmSegment } from '../types';
@@ -393,7 +394,8 @@ const Rfm = () => {
}, [clients, searchTerm, segmentFilter]);
const totalPages = Math.ceil(filteredClients.length / itemsPerPage);
- const startIndex = (currentPage - 1) * itemsPerPage;
+ const safeCurrentPage = Math.min(currentPage, totalPages || 1);
+ const startIndex = (safeCurrentPage - 1) * itemsPerPage;
const paginatedClients = filteredClients.slice(startIndex, startIndex + itemsPerPage);
const totals = useMemo(() => {
@@ -766,47 +768,23 @@ const Rfm = () => {
-
- Mostrar
-
- clientes por página
-
-
-
-
- Mostrando {filteredClients.length > 0 ? startIndex + 1 : 0} a {Math.min(startIndex + itemsPerPage, filteredClients.length)} de {filteredClients.length} clientes
-
-
-
-
-
-
-