diff --git a/src/pages/Clients.tsx b/src/pages/Clients.tsx index cf75098..8c2043e 100644 --- a/src/pages/Clients.tsx +++ b/src/pages/Clients.tsx @@ -1,6 +1,6 @@ -import { useMemo, useState } from 'react'; +import { useMemo, useState, useEffect } from 'react'; import { Link, useOutletContext } from 'react-router-dom'; -import { Search, ChevronRight, Filter } from 'lucide-react'; +import { Search, ChevronRight, Filter, ChevronLeft } from 'lucide-react'; import type { OrderData } from '../types'; import { parseOrderDate } from '../dataService'; @@ -10,6 +10,15 @@ const Clients = () => { const { ordersData } = useOutletContext<{ ordersData: OrderData[] }>(); const [searchTerm, setSearchTerm] = useState(''); const [sortBy, setSortBy] = useState('recent'); + + // Pagination state + const [currentPage, setCurrentPage] = useState(1); + const [itemsPerPage, setItemsPerPage] = useState(10); + + // Reset to first page when search or sort changes + useEffect(() => { + setCurrentPage(1); + }, [searchTerm, sortBy]); const clientsData = useMemo(() => { const orders = ordersData; @@ -58,6 +67,11 @@ const Clients = () => { }); }, [searchTerm, sortBy, ordersData]); + // Pagination logic + const totalPages = Math.ceil(clientsData.length / itemsPerPage); + const startIndex = (currentPage - 1) * itemsPerPage; + const paginatedData = clientsData.slice(startIndex, startIndex + itemsPerPage); + const formatCurrency = (value: number) => { return new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(value); }; @@ -112,11 +126,11 @@ const Clients = () => { - {clientsData.map((client, index) => ( + {paginatedData.map((client, index) => ( - {index + 1} + {startIndex + index + 1} {client.name} @@ -138,6 +152,49 @@ const Clients = () => { + + {/* Pagination Controls */} +
+
+ Mostrar + + itens por página +
+ +
+ + Mostrando {clientsData.length > 0 ? startIndex + 1 : 0} a {Math.min(startIndex + itemsPerPage, clientsData.length)} de {clientsData.length} clientes + +
+ + +
+
+
); diff --git a/src/pages/Products.tsx b/src/pages/Products.tsx index 7889ca7..c955e79 100644 --- a/src/pages/Products.tsx +++ b/src/pages/Products.tsx @@ -1,6 +1,6 @@ -import { useMemo, useState } from 'react'; +import { useMemo, useState, useEffect } from 'react'; import { Link, useOutletContext } from 'react-router-dom'; -import { Search, Package, TrendingUp } from 'lucide-react'; +import { Search, Package, TrendingUp, ChevronLeft, ChevronRight } from 'lucide-react'; import DateRangePicker from '../components/DateRangePicker'; import type { OrderData, DateRange } from '../types'; import { parseOrderDate } from '../dataService'; @@ -9,6 +9,15 @@ const Products = () => { const { dateRange, setDateRange, ordersData } = useOutletContext<{ dateRange: DateRange, setDateRange: (range: DateRange) => void, ordersData: OrderData[] }>(); const [searchTerm, setSearchTerm] = useState(''); + // Pagination state + const [currentPage, setCurrentPage] = useState(1); + const [itemsPerPage, setItemsPerPage] = useState(10); + + // Reset to first page when search or date range changes + useEffect(() => { + setCurrentPage(1); + }, [searchTerm, dateRange]); + const productsData = useMemo(() => { const orders = ordersData; const productMap: Record = {}; @@ -40,6 +49,11 @@ const Products = () => { return result.sort((a, b) => b.totalSold - a.totalSold); }, [dateRange, searchTerm, ordersData]); + // Pagination logic + const totalPages = Math.ceil(productsData.length / itemsPerPage); + const startIndex = (currentPage - 1) * itemsPerPage; + const paginatedData = productsData.slice(startIndex, startIndex + itemsPerPage); + const formatCurrency = (value: number) => { return new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(value); }; @@ -81,7 +95,7 @@ const Products = () => { - {productsData.map((product) => ( + {paginatedData.map((product) => ( #{product.id} @@ -109,6 +123,49 @@ 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 + +
+ + +
+
+
);