@@ -910,6 +910,20 @@ export const checkConflicts = (values: {
910910 values . sourceMode === "SCHEDULE_SINGLE" ||
911911 values . sourceMode === "SCHEDULE_MULTIPLE"
912912 ) {
913+ if ( values . sourceMode === "SCHEDULE_MULTIPLE" ) {
914+ const isRepeatOnValid = validateRepeatOnInRange ( values ) ;
915+ if ( ! isRepeatOnValid ) {
916+ dispatch (
917+ addNotification ( {
918+ type : "error" ,
919+ key : "CONFLICT_RANGE_DAYS" ,
920+ duration : - 1 ,
921+ context : NOTIFICATION_CONTEXT ,
922+ } ) ,
923+ ) ;
924+ return false ; // Exit early if repeatOn is invalid
925+ }
926+ }
913927 // Get timezone offset; Checks should be performed on UTC times
914928 // let offset = getTimezoneOffset();
915929
@@ -924,7 +938,7 @@ export const checkConflicts = (values: {
924938 ) ;
925939
926940 // If start date of event is smaller than today --> Event is in past
927- if ( values . sourceMode === "SCHEDULE_SINGLE" && startDate < new Date ( ) ) {
941+ if ( ( values . sourceMode === "SCHEDULE_SINGLE" && startDate < new Date ( ) ) || ( values . sourceMode === "SCHEDULE_MULTIPLE" && startDate < new Date ( ) ) ) {
928942 dispatch (
929943 addNotification ( {
930944 type : "error" ,
@@ -1107,6 +1121,42 @@ export const checkForSchedulingConflicts = (events: EditedEvents[]) => (dispatch
11071121 return data ;
11081122} ;
11091123
1124+ export const validateRepeatOnInRange = ( values : {
1125+ repeatOn : string [ ] , // e.g. ["MO", "TU"]
1126+ scheduleStartDate : string , // e.g. "2025-08-11"
1127+ scheduleEndDate : string // e.g. "2025-08-13"
1128+ } ) => {
1129+ if ( ! values . repeatOn || values . repeatOn . length === 0 ) {
1130+ return true ;
1131+ }
1132+
1133+ const start = new Date ( values . scheduleStartDate ) ;
1134+ const end = new Date ( values . scheduleEndDate ) ;
1135+
1136+ // Map day codes to numbers: Sunday=0, Monday=1, ..., Saturday=6
1137+ const dayMap : Record < string , number > = {
1138+ SU : 0 ,
1139+ MO : 1 ,
1140+ TU : 2 ,
1141+ WE : 3 ,
1142+ TH : 4 ,
1143+ FR : 5 ,
1144+ SA : 6 ,
1145+ } ;
1146+ const repeatDays = values . repeatOn . map ( day => dayMap [ day ] ) ;
1147+ // Check if **at least one** date in the [start..end] range matches repeatOn days
1148+ const current = new Date ( start ) ;
1149+ while ( current <= end ) {
1150+ if ( repeatDays . includes ( current . getDay ( ) ) ) {
1151+ return true ; // Valid because this repeat day is in range
1152+ }
1153+ current . setDate ( current . getDate ( ) + 1 ) ; // next day
1154+ }
1155+
1156+ // If no repeat days fall within the range, return false
1157+ return false ;
1158+ } ;
1159+
11101160const eventSlice = createSlice ( {
11111161 name : "events" ,
11121162 initialState,
0 commit comments