fix stats calculation - include repeating avs.

This commit is contained in:
Dobromir Popov
2024-05-12 12:13:12 +03:00
parent a392022499
commit 8e69e3b933
2 changed files with 26 additions and 8 deletions

View File

@ -22,11 +22,11 @@ function ContactsPage({ allPublishers }) {
const [pubWithAssignmentsCount, setPubWithAssignmentsCount] = useState(0);
const [filteredPublishers, setFilteredPublishers] = useState(allPublishers);
const [sortField, setSortField] = useState('firstName');
const [sortField, setSortField] = useState('name');
const [sortOrder, setSortOrder] = useState('asc');
const months = common.getMonthNames();
const subsetMonths = Array.from({ length: 7 }, (_, i) => {
const subsetMonths = Array.from({ length: 9 }, (_, i) => {
const monthIndex = (currentMonth - 3 + i + 12) % 12; // Adjust for year wrap-around
return {
name: months[monthIndex],
@ -104,7 +104,7 @@ function ContactsPage({ allPublishers }) {
<h1 className="text-xl font-semibold mb-4">Статистика </h1>
<h5 className="text-lg font-semibold mb-4">{pubWithAssignmentsCount} участника с предпочитания за месеца (от {filteredPublishers.length} )</h5>
<div className="mb-4 flex justify-between items-center">
<input
<input name="filterText"
type="text"
placeholder="Търси по име, имейл или телефон..."
value={searchQuery}
@ -112,7 +112,7 @@ function ContactsPage({ allPublishers }) {
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm flex-grow mr-2"
/>
{/* Month dropdown */}
<select
<select name="filterMonth"
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm"
value={selectedMonth}
onChange={(e) => setSelectedMonth(e.target.value)}
@ -123,7 +123,7 @@ function ContactsPage({ allPublishers }) {
))}
</select>
{/* Publisher type dropdown */}
<select
<select name="filterType"
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm"
value={publisherType}
onChange={(e) => setPublisherType(e.target.value)}
@ -138,8 +138,8 @@ function ContactsPage({ allPublishers }) {
<table className="w-full text-left border-collapse">
<thead>
<tr>
<th className="border-b font-medium p-4 pl-8 pt-0 pb-3 cursor-pointer" onClick={() => handleSort('firstName')}>
Име{renderSortArrow('firstName')}
<th className="border-b font-medium p-4 pl-8 pt-0 pb-3 cursor-pointer" onClick={() => handleSort('name')}>
Име{renderSortArrow('name')}
</th>
<th className="border-b font-medium p-4 pt-0 pb-3 cursor-pointer" onClick={() => handleSort('currentMonthAvailabilityDaysCount')}>
Възможности{renderSortArrow('currentMonthAvailabilityDaysCount')}
@ -217,6 +217,10 @@ export default ContactsPage;
export const getServerSideProps = async (context) => {
const allPublishers = await data.getAllPublishersWithStatistics(new Date());
//merge first and last name
allPublishers.forEach(publisher => {
publisher.name = `${publisher.firstName} ${publisher.lastName}`;
});
return {
props: {
allPublishers