fix(calendar): prevent adding timeblocks outside of working hours

This commit is contained in:
Matej Glasnák committed 2025-11-13 01:22:53 +01:00
1 parent 128d53788e
commit af6dcfe0b8
1 file changed
+36 -20
+36 -20
View File
@@ -282,31 +282,47 @@ export default {
}, },
onCellClick(DOMEvent, split) { onCellClick(DOMEvent, split) {
const dateFrom = split.date; const allNonWorkingHoursEvents =
dateFrom.setHours(Math.floor(DOMEvent.offsetY / 100), 0, 0, 0); DOMEvent.target.querySelectorAll('.non-working-event');
const dateTo = new Date(dateFrom);
dateTo.setHours(dateFrom.getHours() + 1);
const time = moment(dateFrom).format('HH:mm'); const calendarHeight = DOMEvent.target.offsetHeight;
const isTeamCalendar = this.$route.name === 'Dashboard - Teams'; const morningNonWorkingHoursEventHeight =
const employee = isTeamCalendar allNonWorkingHoursEvents?.[0]?.offsetHeight || 950;
? split.employee_id const afternoonNonWorkingHoursEventHeight =
: Number(localStorage.getItem('selectedEmployee') || this.user.id); allNonWorkingHoursEvents?.[1]?.offsetHeight || 1700;
this.$events.emit('show-menu-modal', { if (
time, // Check if the click is not in the non-working hours events
date: tmUtils.formatDateTimeForBackend(dateFrom), DOMEvent.offsetY > morningNonWorkingHoursEventHeight &&
employee, DOMEvent.offsetY < calendarHeight - afternoonNonWorkingHoursEventHeight
}); ) {
const dateFrom = split.date;
dateFrom.setHours(Math.floor(DOMEvent.offsetY / 100), 0, 0, 0);
const dateTo = new Date(dateFrom);
dateTo.setHours(dateFrom.getHours() + 1);
setTimeout(() => { const time = moment(dateFrom).format('HH:mm');
this.$events.emit('add-timeblock', {
id: null, const isTeamCalendar = this.$route.name === 'Dashboard - Teams';
start: tmUtils.formatDateTimeForBackend(dateFrom), const employee = isTeamCalendar
end: tmUtils.formatDateTimeForBackend(dateTo), ? split.employee_id
: Number(localStorage.getItem('selectedEmployee') || this.user.id);
this.$events.emit('show-menu-modal', {
time,
date: tmUtils.formatDateTimeForBackend(dateFrom),
employee,
}); });
}, 150);
setTimeout(() => {
this.$events.emit('add-timeblock', {
id: null,
start: tmUtils.formatDateTimeForBackend(dateFrom),
end: tmUtils.formatDateTimeForBackend(dateTo),
});
}, 150);
}
if (!this.isDOMElementAnEvent(DOMEvent.target)) this.selectCell(DOMEvent); if (!this.isDOMElementAnEvent(DOMEvent.target)) this.selectCell(DOMEvent);
}, },