@@ -11,6 +11,7 @@ import {
1111 handleError ,
1212 replaceIdWithOptimisticId ,
1313} from "@web/common/utils/event.util" ;
14+ import { fromUTCOffset } from "@web/common/utils/web.date.util" ;
1415import { EventApi } from "@web/ducks/events/event.api" ;
1516import { selectEventById } from "@web/ducks/events/selectors/event.selectors" ;
1617import { selectPaginatedEventsBySectionType } from "@web/ducks/events/selectors/util.selectors" ;
@@ -161,12 +162,34 @@ function* getEvents(
161162 yield put ( eventsEntitiesSlice . actions . insert ( payload . data ) ) ;
162163 return { data : payload . data } ;
163164 }
164- const res : Response_GetEventsSuccess = ( yield call (
165- EventApi . get ,
166- payload ,
167- ) ) as Response_GetEventsSuccess ;
168165
169- const normalizedEvents = normalize < Schema_Event > ( res . data , [
166+ // Hotfix to address issue where timed events and all-day events fetch
167+ // result does not return the correct events due to inconsistencies.
168+ // in the DB model in terms of how dates are saved.
169+ //
170+ // This hotfix works by sending 2 requests, one to handle timed events (filter is ISO-8601 date string)
171+ // and one to handle all-day events (filter is YYYY-MM-DD date string).
172+ //
173+ // The drawback is that we now send 2 requests instead of 1.
174+ //
175+ // See https://github.com/SwitchbackTech/compass/pull/440 for more details.
176+ const res : Response_GetEventsSuccess = ( yield call ( EventApi . get , {
177+ startDate : payload . startDate ,
178+ endDate : payload . endDate ,
179+ } ) ) as Response_GetEventsSuccess ;
180+ const alldayRes : Response_GetEventsSuccess = ( yield call ( EventApi . get , {
181+ startDate : fromUTCOffset ( payload . startDate as string ) ,
182+ endDate : fromUTCOffset ( payload . endDate as string ) ,
183+ } ) ) as Response_GetEventsSuccess ;
184+
185+ // Separating timed and all-day events removes duplicates
186+ const timedEvents = res . data . filter ( ( event ) => event . isAllDay === false ) ;
187+ const alldayEvents = alldayRes . data . filter (
188+ ( event ) => event . isAllDay === true ,
189+ ) ;
190+ const events = [ ...timedEvents , ...alldayEvents ] ;
191+
192+ const normalizedEvents = normalize < Schema_Event > ( events , [
170193 normalizedEventsSchema ( ) ,
171194 ] ) ;
172195
0 commit comments