diff --git a/pages/cart/publishers/stats.tsx b/pages/cart/publishers/stats.tsx index 18ee50e..049706b 100644 --- a/pages/cart/publishers/stats.tsx +++ b/pages/cart/publishers/stats.tsx @@ -13,7 +13,7 @@ import { set } from 'date-fns'; function ContactsPage({ allPublishers }) { const currentMonth = new Date().getMonth(); - const [selectedMonth, setSelectedMonth] = useState(""); + const [selectedMonth, setSelectedMonth] = useState(currentMonth + 1); const isMounted = useRef(false); const [searchQuery, setSearchQuery] = useState(''); @@ -33,9 +33,12 @@ function ContactsPage({ allPublishers }) { index: monthIndex + 1 }; }); - const datesOn15th = Array.from({ length: 7 }, (_, i) => new Date(new Date().getFullYear(), new Date().getMonth() - 3 + i, 15)) - .map(date => date.toISOString().split('T')[0]); + const [hideEmptyFields, setHideEmptyFields] = useState({ + availability: false, + assignments: false, + lastLogin: false + }); function handleSort(field) { const order = sortField === field && sortOrder === 'asc' ? 'desc' : 'asc'; @@ -48,8 +51,11 @@ function ContactsPage({ allPublishers }) { (publisher.firstName.toLowerCase().includes(searchQuery.toLowerCase()) || publisher.lastName.toLowerCase().includes(searchQuery.toLowerCase()) || publisher.email.toLowerCase().includes(searchQuery.toLowerCase()) || - (publisher.phone?.toLowerCase().includes(searchQuery.toLowerCase()))) && - (publisherType ? publisher.type === publisherType : true) + (publisher.phone?.toLowerCase().includes(searchQuery.toLowerCase()))) + && (publisherType ? publisher.type === publisherType : true) + && (!hideEmptyFields.availability || publisher.currentMonthAvailabilityDaysCount > 0) + && (!hideEmptyFields.assignments || publisher.currentMonthAssignments > 0) + && (!hideEmptyFields.lastLogin || publisher.lastLogin) ); if (sortField) { @@ -68,7 +74,7 @@ function ContactsPage({ allPublishers }) { } setFilteredPublishers(filtered); setPubWithAssignmentsCount(filtered.filter(publisher => publisher.currentMonthAvailabilityHoursCount && publisher.currentMonthAvailabilityHoursCount > 0).length); - }, [searchQuery, publisherType, sortField, sortOrder, allPublishers]); + }, [searchQuery, publisherType, sortField, sortOrder, allPublishers, hideEmptyFields]); useEffect(() => { if (isMounted.current) { @@ -141,14 +147,38 @@ function ContactsPage({ allPublishers }) {
handleSort('currentMonthAvailabilityDaysCount')}> + Възможности{renderSortArrow('currentMonthAvailabilityDaysCount')} +
+ setHideEmptyFields({ ...hideEmptyFields, availability: !hideEmptyFields.availability })} + title="Скрий редове без възможности" + />handleSort('currentMonthAssignments')}> + Участия{renderSortArrow('currentMonthAssignments')} +
+ setHideEmptyFields({ ...hideEmptyFields, assignments: !hideEmptyFields.assignments })} + title="Скрий редове без участия" + />handleSort('lastLogin')}> + Последно влизане{renderSortArrow('lastLogin')} +
+ setHideEmptyFields({ ...hideEmptyFields, lastLogin: !hideEmptyFields.lastLogin })} + title="Скрий редове без последно влизане" + />