Show relevant advertisements on the calendar based on store participation

Update client-side filtering logic to correctly display advertisements based on selected store or user group affiliations, and adjust backend query to fetch participation data.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/ByygiiM
This commit is contained in:
michaelschal committed 2025-08-11 21:56:18 +00:00
1 parent 745ddc6805
commit e627ff650d
2 files changed
+41 -6

No files matched your search

+22 -3
View File
@@ -178,6 +178,17 @@ export default function CalendarGrid({
const getPublicitiesForDate = (date: Date) => {
const dateStr = format(date, 'yyyy-MM-dd');
console.log('🔍 CalendarGrid getPublicitiesForDate:', {
date: dateStr,
totalPublicities: publicities.length,
selectedStoreId,
userGroups: userGroups.length
});
if (publicities.length > 0) {
console.log('📄 Sample publicity structure:', publicities[0]);
}
return publicities.filter(pub => {
// Check if the date is within the publicity period
const pubStart = pub.startDate;
@@ -194,14 +205,22 @@ export default function CalendarGrid({
// If a specific store is selected, check if that store participates
if (selectedStoreId) {
return pub.participatingGroups?.some((pg: any) => pg.groupId === selectedStoreId);
const matches = pub.participations?.some((pg: any) => pg.groupId === selectedStoreId);
if (matches) {
console.log('🎯 Publicity matches selected store:', { pubNumber: pub.pubNumber, selectedStoreId });
}
return matches;
}
// If no specific store selected but user has assigned stores,
// show publicities where any of user's stores participate
if (userGroups && userGroups.length > 0) {
const userGroupIds = userGroups.map((ug: any) => ug.groupId);
return pub.participatingGroups?.some((pg: any) => userGroupIds.includes(pg.groupId));
const matches = pub.participations?.some((pg: any) => userGroupIds.includes(pg.groupId));
if (matches) {
console.log('👥 Publicity matches user groups:', { pubNumber: pub.pubNumber, userGroupIds });
}
return matches;
}
return true;
@@ -358,7 +377,7 @@ export default function CalendarGrid({
<div
key={`${pub.id}-${idx}`}
className="bg-purple-100 text-purple-800 text-xs px-1.5 py-0.5 rounded-sm border border-purple-200 font-medium shadow-sm cursor-help"
title={`Pub ${pub.pubNumber}: ${pub.designation}${pub.participatingGroups ? ` - Magasins: ${pub.participatingGroups.map((pg: any) => pg.group?.name).join(', ')}` : ''}`}
title={`Pub ${pub.pubNumber}: ${pub.designation}${pub.participations ? ` - Magasins: ${pub.participations.map((pg: any) => pg.group?.name).join(', ')}` : ''}`}
>
{pub.pubNumber}
</div>