File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,12 @@ import FilterModal from './FilterModal';
3030import { DateCalendar } from '@mui/x-date-pickers' ;
3131import { useCurrentUser } from '../../hooks/users.hooks' ;
3232import { useGetUsersTeams } from '../../hooks/teams.hooks' ;
33- import { convertIntToDay , eventsToEventInstances , getOverlapTime } from '../../utils/calendar.utils' ;
33+ import {
34+ convertIntToDay ,
35+ eventsToEventInstances ,
36+ eventsToNextEventInstance ,
37+ getOverlapTime
38+ } from '../../utils/calendar.utils' ;
3439import { filterEventTransformer } from '../../apis/transformers/calendar.transformer' ;
3540import WarningIcon from '@mui/icons-material/Warning' ;
3641import { useHistory } from 'react-router-dom' ;
@@ -233,9 +238,9 @@ const NewCalendarPage: React.FC<NewCalendarPageProps> = ({
233238 teamIds : teamList
234239 } ) ;
235240
236- const upcomingOccurences = eventsToEventInstances ( upcomingEvents ?? [ ] )
237- . filter ( ( event ) => new Date ( event . startTime ) >= new Date ( ) )
238- . sort ( ( a , b ) => new Date ( a . startTime ) . getTime ( ) - new Date ( b . startTime ) . getTime ( ) ) ;
241+ const upcomingOccurences = eventsToNextEventInstance ( upcomingEvents ?? [ ] ) . sort (
242+ ( a , b ) => new Date ( a . startTime ) . getTime ( ) - new Date ( b . startTime ) . getTime ( )
243+ ) ;
239244
240245 const toggleCalendar = ( calendarId : string ) => {
241246 setSelectedCalendarIds ( ( prev ) =>
Original file line number Diff line number Diff line change @@ -169,6 +169,30 @@ export const eventsToEventInstances = (events: Event[]): EventInstance[] => {
169169 } ) ;
170170} ;
171171
172+ // converts events to event instances, but only the next event instance for each event
173+ // If an event has no times in the future it will not be included in the result
174+ // if an event has multiple times in the future it will only include the next schedule slot
175+ export const eventsToNextEventInstance = ( events : Event [ ] ) : EventInstance [ ] => {
176+ const now = new Date ( ) ;
177+
178+ const eventsWithSlotInFuture = events . filter ( ( event ) => {
179+ return event . scheduledTimes . some ( ( scheduleSlot ) => scheduleSlot . endTime > now ) ;
180+ } ) ;
181+
182+ // For each event, find the next schedule slot in the future
183+ const eventsWithOnlyNextSlot = eventsWithSlotInFuture . map ( ( event ) => ( {
184+ ...event ,
185+ scheduledTimes : [
186+ event . scheduledTimes . reduce ( ( acc , current ) => {
187+ if ( current . startTime < acc . startTime ) return acc ;
188+ return current ;
189+ } )
190+ ]
191+ } ) ) ;
192+
193+ return eventsToEventInstances ( eventsWithOnlyNextSlot ) ;
194+ } ;
195+
172196// converts an Event into Event Form Values
173197// Note: Because users can only edit a single instaces time, editModal is always populated with an event instance
174198// representing a single occurrence of the event. However, event edits will effect the entire series for all values
You can’t perform that action at this time.
0 commit comments