diff --git a/client/src/components/CalendarGrid.tsx b/client/src/components/CalendarGrid.tsx index bdbf99d..d705b8c 100644 --- a/client/src/components/CalendarGrid.tsx +++ b/client/src/components/CalendarGrid.tsx @@ -11,6 +11,9 @@ interface CalendarGridProps { currentDate: Date; orders: OrderWithRelations[]; deliveries: DeliveryWithRelations[]; + publicities: any[]; + selectedStoreId: number | null; + userGroups: any[]; onDateClick: (date: Date) => void; onItemClick: (item: any, type: 'order' | 'delivery') => void; } @@ -162,12 +165,49 @@ export default function CalendarGrid({ currentDate, orders, deliveries, + publicities, + selectedStoreId, + userGroups, onDateClick, onItemClick, }: CalendarGridProps) { const monthStart = startOfMonth(currentDate); const monthEnd = endOfMonth(currentDate); + // Helper function to filter publicities based on user's assigned stores + const getPublicitiesForDate = (date: Date) => { + const dateStr = format(date, 'yyyy-MM-dd'); + + return publicities.filter(pub => { + // Check if the date is within the publicity period + const pubStart = pub.startDate; + const pubEnd = pub.endDate; + + if (dateStr < pubStart || dateStr > pubEnd) { + return false; + } + + // If no store is selected and user has no assigned groups, show all publicities + if (!selectedStoreId && (!userGroups || userGroups.length === 0)) { + return true; + } + + // If a specific store is selected, check if that store participates + if (selectedStoreId) { + return pub.participatingGroups?.some((pg: any) => pg.groupId === selectedStoreId); + } + + // 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)); + } + + return true; + }); + }; + // Get all days in the month const monthDays = eachDayOfInterval({ start: monthStart, @@ -280,6 +320,7 @@ export default function CalendarGrid({ const isCurrentMonth = isSameMonth(date, currentDate); const isTodayDate = isToday(date); const { orders: dayOrders, deliveries: dayDeliveries } = getItemsForDate(date); + const dayPublicities = getPublicitiesForDate(date); return (
+ {/* Publicities in top-right corner */} + {dayPublicities.length > 0 && ( +