diff --git a/src/components/PlannedSession.tsx b/src/components/PlannedSession.tsx index 17aef5f3..bf450178 100644 --- a/src/components/PlannedSession.tsx +++ b/src/components/PlannedSession.tsx @@ -67,6 +67,7 @@ interface Session { // sessionType?: string; selectedWeekDays?: string[]; DaysOfWeek?: number[]; + recurringStartDate?: string; startDatetime?: string; endDatetime?: string; endDateValue?: string; @@ -398,7 +399,12 @@ const PlannedSession: React.FC = ({ time: Dayjs | null ): Dayjs | null => { if (date && time) { - return date.hour(time.hour()).minute(time.minute()).second(time.second()); + const dateTime = date + .hour(time.hour()) + .minute(time.minute()) + .second(time.second()); + console.log('dateTime', dateTime); + return dateTime; } return null; }; @@ -417,25 +423,39 @@ const PlannedSession: React.FC = ({ if (type === 'start' && field === 'date') { setStartDate((prev) => { const combinedStartDateTime = combineDateAndTime(newValue, startTime); - updateSessionBlock(id, combinedStartDateTime, endDate, endTime, type); + const combinedEndDateTime = combineDateAndTime(newValue, endTime); + updateSessionBlock( + id, + combinedStartDateTime, + combinedEndDateTime, + endDate, + type + ); return newValue; }); } else if (type === 'start' && field === 'time') { setStartTime((prev) => { const combinedStartDateTime = combineDateAndTime(startDate, newValue); - updateSessionBlock(id, combinedStartDateTime, endDate, endTime, type); + updateSessionBlock(id, combinedStartDateTime, endTime, endDate, type); return newValue; }); } else if (type === 'end' && field === 'date') { setEndDate((prev) => { const combinedEndDateTime = combineDateAndTime(newValue, endTime); - updateSessionBlock(id, startDate, combinedEndDateTime, endTime, type); + updateSessionBlock(id, startDate, endTime, combinedEndDateTime, type); return newValue; }); } else if (type === 'end' && field === 'time') { setEndTime((prev) => { const combinedEndDateTime = combineDateAndTime(startDate, newValue); - updateSessionBlock(id, startDate, combinedEndDateTime, endTime, type); + const combinedEndDateValue = combineDateAndTime(endDate, newValue); + updateSessionBlock( + id, + startDate, + combinedEndDateTime, + combinedEndDateValue, + type + ); return newValue; }); } @@ -450,12 +470,43 @@ const PlannedSession: React.FC = ({ type: 'start' | 'end' ) => { // const EndDateTime = combineDateAndTime(startDate, endTime); - const startDatetime = convertToUTC(combinedStartDateTime); - const endDatetime = convertToUTC(combinedEndDateTime); - const endDateValue = - clickedBox === 'EXTRA_SESSION' - ? endDatetime - : convertToUTC(combinedEndDateValue); + let endDatetime: any; + let startDatetime: any; + let recurringStartDate: any; + let endDateValue: any; + if (type === 'start') { + const combinedStartDate = combineDateAndTime( + startDate, + combinedStartDateTime + ); + const combinedEndDate = combineDateAndTime( + startDate, + combinedEndDateTime + ); + endDatetime = convertToUTC(combinedEndDate); + startDatetime = convertToUTC(combinedStartDate); + + recurringStartDate = convertToUTC(combinedStartDateTime); + const endValue = combineDateAndTime( + combinedEndDateValue, + combinedEndDateTime + ); + endDateValue = + clickedBox === 'EXTRA_SESSION' ? endDatetime : convertToUTC(endValue); + } else if (type === 'end') { + const startDatetimeValue = combineDateAndTime( + combinedEndDateTime, + startTime + ); + startDatetime = convertToUTC(startDatetimeValue); + endDatetime = convertToUTC(combinedEndDateTime); + const combinedStartDate = combineDateAndTime(startDate, startTime); + recurringStartDate = convertToUTC(combinedStartDate); + endDateValue = + clickedBox === 'EXTRA_SESSION' + ? endDatetime + : convertToUTC(combinedEndDateValue); + } if (startDatetime && endDatetime && endDateValue) { const isRecurringEvent = endDatetime !== endDateValue ? true : false; @@ -464,6 +515,7 @@ const PlannedSession: React.FC = ({ block?.id === id ? { ...block, + recurringStartDate: recurringStartDate, startDatetime: startDatetime, endDatetime: endDatetime, endDateValue: endDateValue, @@ -476,6 +528,7 @@ const PlannedSession: React.FC = ({ : block ) ); + console.log('sessionBlocks updated', sessionBlocks); } }; @@ -510,6 +563,7 @@ const PlannedSession: React.FC = ({ : block ) ); + console.log('sessionBlocks initially', sessionBlocks); } }, [startDate, endDate, startTime, endTime, selectedBlockId]); @@ -746,6 +800,7 @@ const PlannedSession: React.FC = ({ type: 'endDate', value: block?.endDateValue || '', }, + recurringStartDate: block?.startDatetime || '', }; } @@ -867,24 +922,27 @@ const PlannedSession: React.FC = ({ }; if (editSelection === t('CENTER_SESSION.EDIT_FOLLOWING_SESSIONS')) { + console.log('sessionBlocks edit call', sessionBlocks); const DaysOfWeek = sessionBlocks?.[0]?.DaysOfWeek; - const endDate = sessionBlocks?.[0]?.endDatetime; - const startDate = sessionBlocks?.[0]?.startDatetime; - const endDateTime = sessionBlocks?.[0]?.endDateValue; - apiBody['endDateTime'] = endDateTime; + const RecurringEndDate = sessionBlocks?.[0]?.endDateValue; + const RecurringstartDate = + sessionBlocks?.[0]?.recurringStartDate ?? + sessionBlocks?.[0]?.startDatetime; + const endDateTime = sessionBlocks?.[0]?.endDatetime; + apiBody['endDatetime'] = sessionBlocks?.[0]?.endDatetime; const datePart = sessionBlocks?.[0]?.endDateValue?.split('T')[0]; const timePart = sessionBlocks?.[0]?.startDatetime?.split('T')[1]; const startDateValue = `${datePart}T${timePart}`; - apiBody['startDateTime'] = startDateValue; + apiBody['startDatetime'] = sessionBlocks?.[0]?.startDatetime; apiBody['recurrencePattern'] = { interval: 1, frequency: 'weekly', daysOfWeek: DaysOfWeek, endCondition: { type: 'endDate', - value: endDate, + value: RecurringEndDate, }, - recurringStartDate: startDate, + recurringStartDate: RecurringstartDate, }; } else if (editSelection === t('CENTER_SESSION.EDIT_THIS_SESSION')) { const startDateTime = sessionBlocks?.[0]?.startDatetime; diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 1d36dfbc..a00c6e7f 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -583,6 +583,7 @@ export interface RecurrencePattern { interval: number; endCondition: EndCondtion; daysOfWeek: number[]; + recurringStartDate: string; } export interface EndCondtion {