Skip to content

Commit

Permalink
Issue #PS-2013 feat: recurring event edit- done
Browse files Browse the repository at this point in the history
  • Loading branch information
suvarnakale committed Sep 19, 2024
1 parent a6955db commit 4021cdd
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 18 deletions.
94 changes: 76 additions & 18 deletions src/components/PlannedSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ interface Session {
// sessionType?: string;
selectedWeekDays?: string[];
DaysOfWeek?: number[];
recurringStartDate?: string;
startDatetime?: string;
endDatetime?: string;
endDateValue?: string;
Expand Down Expand Up @@ -398,7 +399,12 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
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;
};
Expand All @@ -417,25 +423,39 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
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;
});
}
Expand All @@ -450,12 +470,43 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
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;
Expand All @@ -464,6 +515,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
block?.id === id
? {
...block,
recurringStartDate: recurringStartDate,
startDatetime: startDatetime,
endDatetime: endDatetime,
endDateValue: endDateValue,
Expand All @@ -476,6 +528,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
: block
)
);
console.log('sessionBlocks updated', sessionBlocks);
}
};

Expand Down Expand Up @@ -510,6 +563,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
: block
)
);
console.log('sessionBlocks initially', sessionBlocks);
}
}, [startDate, endDate, startTime, endTime, selectedBlockId]);

Expand Down Expand Up @@ -746,6 +800,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
type: 'endDate',
value: block?.endDateValue || '',
},
recurringStartDate: block?.startDatetime || '',
};
}

Expand Down Expand Up @@ -867,24 +922,27 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
};

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;
Expand Down
1 change: 1 addition & 0 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export interface RecurrencePattern {
interval: number;
endCondition: EndCondtion;
daysOfWeek: number[];
recurringStartDate: string;
}

export interface EndCondtion {
Expand Down

0 comments on commit 4021cdd

Please sign in to comment.