Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions website/components/kiosks/admin/statistics/CheckoutTrend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,29 @@ export default function CheckoutTrend({
dayCounts[dayKey].count += 1;
});

return Object.entries(dayCounts)
.sort(([a], [b]) => a.localeCompare(b))
.map(([, value]) => value);
const sortedKeys = Object.keys(dayCounts).sort();
if (sortedKeys.length === 0) return [];

const filled: { date: string; count: number }[] = [];
const cursor = new Date(sortedKeys[0]);
const end = new Date(sortedKeys[sortedKeys.length - 1]);

while (cursor <= end) {
const dayKey = cursor.toISOString().slice(0, 10); // "YYYY-MM-DD"

if (dayCounts[dayKey]) {
filled.push(dayCounts[dayKey]);
} else {
// Format the label the same way, but from a plain JS Date
const label = dateFormatter
? dateFormatter.format(new Date(cursor))
: `${cursor.getMonth() + 1}/${cursor.getDate()}/${cursor.getFullYear()}`;
filled.push({ date: label, count: 0 });
}

cursor.setDate(cursor.getDate() + 1);
}
return filled;
}, [checkouts, config?.schedule.locale, config?.schedule.timezone]);

//just in case there is no data at all, display this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ export default function TopCheckedOutItems({

checkouts.forEach((checkout) => {
checkout.items.forEach((checkoutItem) => {
itemCounts[checkoutItem.item_uuid] =
(itemCounts[checkoutItem.item_uuid] || 0) +
checkoutItem.quantity;
const name =
inventoryMap.get(checkoutItem.item_uuid)?.name || "Unknown Item";
itemCounts[name] = (itemCounts[name] || 0) + checkoutItem.quantity;
});
});

return Object.entries(itemCounts)
.map(([uuid, count]) => ({
name: inventoryMap.get(uuid)?.name || "Unknown Item",
count,
}))
.map(([name, count]) => ({name, count}))
.sort((a, b) => b.count - a.count);
}, [checkouts, inventoryMap]);

Expand Down