From 5a5b9a035f17bd591e5f6c3d718d34d54f45a9e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Tue, 7 Jul 2026 12:37:00 -0300 Subject: [PATCH] Align products controls with replenishment layout --- src/pages/Products.tsx | 492 ++++++++++++++++------------------------- 1 file changed, 193 insertions(+), 299 deletions(-) diff --git a/src/pages/Products.tsx b/src/pages/Products.tsx index a380676..17f43bf 100644 --- a/src/pages/Products.tsx +++ b/src/pages/Products.tsx @@ -1,11 +1,11 @@ import { useEffect, useMemo, useRef, useState } from 'react'; import { Link, useOutletContext } from 'react-router-dom'; -import { Download, Filter, Package, PackageCheck, PackagePlus, Search, TrendingDown, TrendingUp, X } from 'lucide-react'; +import { Download, Filter, Package, PackageCheck, Search, TrendingDown, TrendingUp, X } from 'lucide-react'; +import DateRangePicker from '../components/DateRangePicker'; import PaginationControls from '../components/PaginationControls'; import RefreshStatus from '../components/RefreshStatus'; import type { DateRange, ProductAnalyticsItem } from '../types'; import { exportToCSV, fetchProductAnalytics } from '../dataService'; -import { endOfLocalDay, formatDateParam, parseLocalDateInput, rangeForDay, rangeForLastDays, rangeForPreviousDay, startOfLocalDay } from '../dateRanges'; import { encodeProductGroupKey, parseProductName, sortProductSizes } from '../productParsing'; type StockRisk = 'rupture' | 'critical' | 'attention' | 'monitor' | 'healthy' | 'no_sales'; @@ -85,33 +85,6 @@ const stockPriority: Record = { no_sales: 5 }; -const dateFilterPresets = [ - { value: 'today', label: 'Hoje', getRange: () => rangeForDay(new Date()) }, - { value: 'yesterday', label: 'Ontem', getRange: () => rangeForPreviousDay() }, - { value: '7d', label: 'Últimos 7 dias', getRange: () => rangeForLastDays(7) }, - { value: '30d', label: 'Últimos 30 dias', getRange: () => rangeForLastDays(30) }, - { value: 'month', label: 'Este mês', getRange: () => { - const end = endOfLocalDay(new Date()); - return { start: startOfLocalDay(new Date(end.getFullYear(), end.getMonth(), 1)), end }; - } }, - { value: 'previous-month', label: 'Mês passado', getRange: () => { - const today = new Date(); - return { - start: startOfLocalDay(new Date(today.getFullYear(), today.getMonth() - 1, 1)), - end: endOfLocalDay(new Date(today.getFullYear(), today.getMonth(), 0)) - }; - } }, - { value: '90d', label: 'Últimos 90 dias', getRange: () => rangeForLastDays(90) }, - { value: 'year', label: 'Este ano', getRange: () => { - const end = endOfLocalDay(new Date()); - return { start: startOfLocalDay(new Date(end.getFullYear(), 0, 1)), end }; - } }, - { value: 'all', label: 'Todo o período', getRange: () => ({ - start: startOfLocalDay(new Date(2000, 0, 1)), - end: endOfLocalDay(new Date()) - }) } -]; - const filterSelectClassName = "w-full h-9 bg-dark-input border border-dark-border text-dark-text text-sm rounded-lg px-3 focus:outline-none focus:border-brand-primary transition-colors cursor-pointer"; const getRangeDays = (range: DateRange) => { @@ -384,7 +357,6 @@ const Products = () => { }, [coverageFilter, dateRange, productAnalytics, salesFilter, searchTerm, sortBy, stockQuantityFilter, stockStatusFilter, viewMode]); const activeFilterCount = - (sortBy === 'sold_desc' ? 0 : 1) + (stockStatusFilter === 'all' ? 0 : 1) + (stockQuantityFilter === 'all' ? 0 : 1) + (salesFilter === 'all' ? 0 : 1) + @@ -392,7 +364,6 @@ const Products = () => { const hasActiveFilters = activeFilterCount > 0; const resetProductFilters = () => { - setSortBy('sold_desc'); setStockStatusFilter('all'); setStockQuantityFilter('all'); setSalesFilter('all'); @@ -400,47 +371,6 @@ const Products = () => { setCurrentPage(1); }; - const datePresetValue = useMemo(() => { - const currentStart = formatDateParam(dateRange.start); - const currentEnd = formatDateParam(dateRange.end); - const preset = dateFilterPresets.find(option => { - const range = option.getRange(); - return formatDateParam(range.start) === currentStart && formatDateParam(range.end) === currentEnd; - }); - - return preset?.value || 'custom'; - }, [dateRange]); - - const updateDatePreset = (value: string) => { - if (value === 'custom') return; - - const preset = dateFilterPresets.find(option => option.value === value); - if (!preset) return; - - setDateRange(preset.getRange()); - setCurrentPage(1); - }; - - const updateDateStart = (value: string) => { - const nextStart = parseLocalDateInput(value); - if (!nextStart) return; - - const start = startOfLocalDay(nextStart); - const end = dateRange.end < start ? endOfLocalDay(start) : dateRange.end; - setDateRange({ start, end }); - setCurrentPage(1); - }; - - const updateDateEnd = (value: string) => { - const nextEnd = parseLocalDateInput(value); - if (!nextEnd) return; - - const end = endOfLocalDay(nextEnd); - const start = dateRange.start > end ? startOfLocalDay(end) : dateRange.start; - setDateRange({ start, end }); - setCurrentPage(1); - }; - const totalPages = Math.ceil(productsData.length / itemsPerPage); const safeCurrentPage = Math.min(currentPage, totalPages || 1); const startIndex = (safeCurrentPage - 1) * itemsPerPage; @@ -460,233 +390,13 @@ const Products = () => {
-
- {[ - { key: 'sku' as const, label: 'SKU' }, - { key: 'group' as const, label: 'Grupo' } - ].map(view => ( - - ))} -
- -
- - { - setSearchTerm(e.target.value); - setCurrentPage(1); - }} - className="w-full bg-dark-card border border-dark-border text-dark-text rounded-xl pl-10 pr-4 py-2.5 focus:outline-none focus:border-brand-primary hover:border-brand-primary transition-colors shadow-sm" - /> -
- -
- - - {isFilterMenuOpen && ( -
-
-

Filtros

- -
- -
- - - - - - - - - - - - - - - -
- -
- - -
-
- )} -
- - - - Reposição - + { + setDateRange(range); + setCurrentPage(1); + }} + /> + ))} +
+ +
+ + { + setSearchTerm(e.target.value); + setCurrentPage(1); + }} + className="w-full bg-dark-input border border-dark-border text-dark-text rounded-xl pl-10 pr-4 py-2.5 focus:outline-none focus:border-brand-primary hover:border-brand-primary transition-colors" + /> +
+ +
+ + + {isFilterMenuOpen && ( +
+
+

Filtros

+ +
+ +
+ + + + + + + +
+ +
+ + +
+
+ )} +
+ + + + {isLoading && productAnalytics.length === 0 ? ( ) : (