diff --git a/zmsadmin/js/page/availabilityDay/form/datepicker.js b/zmsadmin/js/page/availabilityDay/form/datepicker.js index 22b13c683..b2c180149 100644 --- a/zmsadmin/js/page/availabilityDay/form/datepicker.js +++ b/zmsadmin/js/page/availabilityDay/form/datepicker.js @@ -256,13 +256,19 @@ class AvailabilityDatePicker extends Component return className; } - /* const filterPassedTime = (time) => { - const currentDate = this.state.selectedDate; - const selectedDate = new Date(time); - return currentDate.getTime() < selectedDate.getTime(); - }; + if (!moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) { + return true; + } + + const currentTime = moment(); + const timeToCheck = moment(time); + + return timeToCheck.hour() > currentTime.hour() || + (timeToCheck.hour() === currentTime.hour() && timeToCheck.minute() > currentTime.minute()); + }; + /* const isWeekday = date => { const day = date.getDay(); return day !== 0 && day !== 6; @@ -337,7 +343,7 @@ class AvailabilityDatePicker extends Component minTime={this.state.minTime} maxTime={this.state.maxTime} excludeTimes={this.state.excludeTimeList} - //filterTime={filterPassedTime} + filterTime={filterPassedTime} disabled={this.props.attributes.disabled} onInputClick={this.openTimePicker} onKeyDown={this.tpKeyDownHandler} diff --git a/zmsadmin/js/page/availabilityDay/form/formButtons.js b/zmsadmin/js/page/availabilityDay/form/formButtons.js index d7892ac74..d1a17a6bd 100644 --- a/zmsadmin/js/page/availabilityDay/form/formButtons.js +++ b/zmsadmin/js/page/availabilityDay/form/formButtons.js @@ -21,7 +21,7 @@ const FormButtons = (props) => { className="button button--diamond" disabled={disabled || data.startDate == selectedDate}>Ab diesem Tag ändern</button> <button onClick={onUpdateSingle} title="Öffnungszeit aktualisieren" - className="button button--diamond" disabled={(data && !data.id) || hasConflicts || hasSlotCountError || props.isCreatingExclusion}>Aktualisieren</button> + className="button button--diamond" disabled={disabled || props.isCreatingExclusion}>Aktualisieren</button> </div> </div> ) diff --git a/zmsadmin/js/page/availabilityDay/helpers.js b/zmsadmin/js/page/availabilityDay/helpers.js index 69dce5f8a..52faa8804 100644 --- a/zmsadmin/js/page/availabilityDay/helpers.js +++ b/zmsadmin/js/page/availabilityDay/helpers.js @@ -102,13 +102,22 @@ export const getNewAvailability = (timestamp, tempId, scope, existingAvailabilit }) const currentTime = moment() - let startTime = moment('05:00:00', 'HH:mm:ss') - if (currentTime.isAfter(startTime)) { + const dayEndTime = moment('22:00:00', 'HH:mm:ss') + let startTime = moment('07:00:00', 'HH:mm:ss') + + // Only use current time if the selected date is today + if (now.format('YYYY-MM-DD') === currentTime.format('YYYY-MM-DD') && currentTime.isAfter(startTime)) { // Round up to next half hour startTime = moment(currentTime).add(30 - (currentTime.minutes() % 30), 'minutes') } let endTime = moment(startTime).add(1, 'hour') + // Adjust if end time would exceed 22:00 + if (endTime.isAfter(dayEndTime)) { + startTime = moment(dayEndTime).subtract(1, 'hour') + endTime = moment(dayEndTime) + } + const hasOverlap = (start, end) => { return todayAvailabilities.some(availability => { const availStart = moment(availability.startTime, 'HH:mm:ss') @@ -125,10 +134,17 @@ export const getNewAvailability = (timestamp, tempId, scope, existingAvailabilit } else { const lastAvail = todayAvailabilities[todayAvailabilities.length - 1] startTime = moment(lastAvail.endTime, 'HH:mm:ss') - if (startTime.isBefore(currentTime)) { + // Only check current time if it's today + if (now.format('YYYY-MM-DD') === currentTime.format('YYYY-MM-DD') && startTime.isBefore(currentTime)) { startTime = moment(currentTime).add(30 - (currentTime.minutes() % 30), 'minutes') } endTime = moment(startTime).add(1, 'hour') + + // Check end time limit again after adjusting for overlaps + if (endTime.isAfter(dayEndTime)) { + startTime = moment(dayEndTime).subtract(1, 'hour') + endTime = moment(dayEndTime) + } } }