-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ZMS-3253 ZMS-3466 ZMS-3415 ZMS-1891): Replicate frontend validation in the backend for the availability opening hours to improve data integrity and frontend validation messaging #812
fix(ZMS-3253 ZMS-3466 ZMS-3415 ZMS-1891): Replicate frontend validation in the backend for the availability opening hours to improve data integrity and frontend validation messaging #812
Conversation
…orm error messaging
This reverts commit ce5d795.
Now the intervals are 90 minutes again and why is 19:30 disabled and 21:00 enabled? @coderabbitai
|
Oops, something went wrong! Please try again later. 🐰 💔 |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's the fix for the DatePicker component: <DatePicker
name={this.props.name + "_time"}
locale="de"
className="form-control form-input"
ariaDescribedBy={"help_" + this.props.attributes.id + "_time"}
id={this.props.attributes.id + "_time"}
selected={this.state.selectedDate}
onChange={date => { this.handleTimeChange(this.props.name, date) }}
showTimeSelect
showTimeSelectOnly
dateFormat="HH:mm"
timeFormat="HH:mm"
timeIntervals={30} // Always use 30-minute intervals for better UX
timeCaption="Uhrzeit"
excludeTimes={this.state.excludeTimeList}
filterTime={(time) => {
const hour = time.getHours();
const minutes = time.getMinutes();
// Block maintenance window (22:00-01:00)
if (hour >= 22 || hour < 1 || (hour === 22 && minutes > 0)) {
return false;
}
// Check buffer only for current day
if (moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) {
const currentTime = moment();
const timeToCheck = moment(time);
const minutesDiff = timeToCheck.diff(currentTime, 'minutes');
if (minutesDiff < this.state.availability.slotTimeInMinutes) {
return false;
}
}
// Ensure time aligns with slot size
const totalMinutes = hour * 60 + minutes;
return totalMinutes % this.state.availability.slotTimeInMinutes === 0;
}}
disabled={this.props.attributes.disabled}
onInputClick={this.openTimePicker}
onKeyDown={this.tpKeyDownHandler}
onClickOutside={this.closeTimePicker}
strictParsing={true}
open={this.state.timePickerIsOpen}
ref={(timepicker) => { this.timepicker = timepicker }}
/> Key changes:
This will:
✏️ Learnings added
🧠 Learnings used
|
@coderabbitai the 30 minute timeslots are there but I can't select 18:30 19:00 19:30 20:30 21:30 and 22:00. They'Re still disabled but shouldn't be. fix it |
Oops, something went wrong! Please try again later. 🐰 💔 |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's the fix for the DatePicker component: <DatePicker
name={this.props.name + "_time"}
locale="de"
className="form-control form-input"
ariaDescribedBy={"help_" + this.props.attributes.id + "_time"}
id={this.props.attributes.id + "_time"}
selected={this.state.selectedDate}
onChange={date => { this.handleTimeChange(this.props.name, date) }}
showTimeSelect
showTimeSelectOnly
dateFormat="HH:mm"
timeFormat="HH:mm"
timeIntervals={30} // Always use 30-minute intervals for better UX
timeCaption="Uhrzeit"
excludeTimes={this.state.excludeTimeList}
filterTime={(time) => {
const hour = time.getHours();
const minutes = time.getMinutes();
// Block maintenance window (22:00-01:00)
if (hour >= 22 || hour < 1 || (hour === 22 && minutes > 0)) {
return false;
}
// Check buffer only for current day
if (moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) {
const currentTime = moment();
const timeToCheck = moment(time);
const minutesDiff = timeToCheck.diff(currentTime, 'minutes');
if (minutesDiff < this.state.availability.slotTimeInMinutes) {
return false;
}
}
return true; // Remove slot alignment check to enable all valid slots
}}
disabled={this.props.attributes.disabled}
onInputClick={this.openTimePicker}
onKeyDown={this.tpKeyDownHandler}
onClickOutside={this.closeTimePicker}
strictParsing={true}
open={this.state.timePickerIsOpen}
ref={(timepicker) => { this.timepicker = timepicker }}
/> Key changes:
This will enable all 30-minute slots except those in:
✏️ Learnings added
|
@coderabbitai now only 20:30 21:00 and 21:30 are enabled 19:00 19:30 are still disabled. current time is 18:50 |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Let's check how the excludeTimes list is being populated. Can you add a console.log to print out the excludeTimeList in setExcludeTimesForDay? Add this line just before setting the state: console.log('Excluded times:', times.map(t => moment(t).format('HH:mm'))); This will help us understand why those specific time slots are being disabled. The issue is likely in how we're calculating the excluded times rather than in the filterTime function. |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Let's fix the setExcludeTimesForDay method. Here's the corrected version: setExcludeTimesForDay() {
if (this.state.kind === 'exclusion') {
return;
}
var times = [];
// Add maintenance window times (22:00-01:00)
const selectedDate = moment(this.state.selectedDate);
for (let minute = 1; minute < 60; minute++) {
times.push(selectedDate.clone().hour(22).minute(minute).toDate());
times.push(selectedDate.clone().hour(0).minute(minute).toDate());
}
times.push(selectedDate.clone().hour(23).minute(0).toDate());
times.push(selectedDate.clone().hour(23).minute(30).toDate());
// Filter and sort availabilities
const availabilities = [...this.state.availabilityList]
.filter(availability =>
availability.id !== this.state.availability.id &&
availability.type == this.state.availability.type &&
this.isWeekDaySelected(this.state.selectedDate, availability)
)
.sort((a, b) => {
const timeA = moment(a.startTime, 'HH:mm');
const timeB = moment(b.startTime, 'HH:mm');
return timeA.diff(timeB);
});
// Add times from existing availabilities
availabilities.forEach(availability => {
const startTime = moment(availability.startTime, 'HH:mm');
const endTime = moment(availability.endTime, 'HH:mm');
let currentTime = startTime.clone();
while (currentTime.isBefore(endTime)) {
times.push(selectedDate.clone()
.hour(currentTime.hour())
.minute(currentTime.minute())
.toDate()
);
currentTime.add(30, 'minutes');
}
});
console.log('Excluded times:', times.map(t => moment(t).format('HH:mm')));
this.setState({excludeTimeList: times});
} Key changes:
This should properly enable all valid time slots while only excluding:
✏️ Learnings added
|
@coderabbitai didn'T work 19:00 19:30 and 20:00 are still disabled
|
Oops, something went wrong! Please try again later. 🐰 💔 |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's the fix for setExcludeTimesForDay: setExcludeTimesForDay() {
if (this.state.kind === 'exclusion') {
return;
}
var times = [];
// Add maintenance window times (22:00-01:00)
const selectedDate = moment(this.state.selectedDate);
for (let minute = 1; minute < 60; minute++) {
times.push(selectedDate.clone().hour(22).minute(minute).toDate());
times.push(selectedDate.clone().hour(0).minute(minute).toDate());
}
times.push(selectedDate.clone().hour(23).minute(0).toDate());
times.push(selectedDate.clone().hour(23).minute(30).toDate());
// Filter and sort availabilities
const availabilities = [...this.state.availabilityList]
.filter(availability =>
availability.id !== this.state.availability.id &&
availability.type == this.state.availability.type &&
this.isWeekDaySelected(this.state.selectedDate, availability)
)
.sort((a, b) => {
const timeA = moment(a.startTime, 'HH:mm');
const timeB = moment(b.startTime, 'HH:mm');
return timeA.diff(timeB);
});
// Add times from existing availabilities
availabilities.forEach(availability => {
const startTime = moment(availability.startTime, 'HH:mm');
const endTime = moment(availability.endTime, 'HH:mm');
// Only exclude times that are actually within the availability
let currentTime = startTime.clone();
while (currentTime.isBefore(endTime) || currentTime.isSame(endTime)) {
times.push(selectedDate.clone()
.hour(currentTime.hour())
.minute(currentTime.minute())
.toDate()
);
currentTime.add(30, 'minutes');
}
});
console.log('Excluded times:', times.map(t => moment(t).format('HH:mm')).sort());
this.setState({excludeTimeList: times});
} Key changes:
This should now correctly enable all valid time slots while only excluding:
✏️ Learnings added
|
@coderabbitai setExcludeTimesForDay is not the problem here. Removing it doesn't change anything for example. |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink You're right - I found the issue. The problem is with the minTime/maxTime props that are still being passed to the DatePicker. Remove these props as they're redundant and causing additional time slots to be disabled: <DatePicker
name={this.props.name + "_time"}
locale="de"
className="form-control form-input"
ariaDescribedBy={"help_" + this.props.attributes.id + "_time"}
id={this.props.attributes.id + "_time"}
selected={this.state.selectedDate}
onChange={date => { this.handleTimeChange(this.props.name, date) }}
showTimeSelect
showTimeSelectOnly
dateFormat="HH:mm"
timeFormat="HH:mm"
timeIntervals={30}
timeCaption="Uhrzeit"
// Remove these props
// minTime={this.state.minTime}
// maxTime={this.state.maxTime}
excludeTimes={this.state.excludeTimeList}
filterTime={(time) => {
const hour = time.getHours();
const minutes = time.getMinutes();
// Block maintenance window (22:00-01:00)
if (hour >= 22 || hour < 1 || (hour === 22 && minutes > 0)) {
return false;
}
// Check buffer only for current day
if (moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) {
const currentTime = moment();
const timeToCheck = moment(time);
const minutesDiff = timeToCheck.diff(currentTime, 'minutes');
if (minutesDiff < this.state.availability.slotTimeInMinutes) {
return false;
}
}
return true;
}}
disabled={this.props.attributes.disabled}
onInputClick={this.openTimePicker}
onKeyDown={this.tpKeyDownHandler}
onClickOutside={this.closeTimePicker}
strictParsing={true}
open={this.state.timePickerIsOpen}
ref={(timepicker) => { this.timepicker = timepicker }}
/> This should now correctly enable all time slots except:
✏️ Learnings added
🧠 Learnings used
|
Tip For best results, initiate chat on the files or code changes. @ThomasAFink I found the issue! The problem is with the minTime/maxTime props that are still being passed to the DatePicker component. Remove these lines from the constructor: minTime: setHours(setMinutes(new Date(), 1), 0),
maxTime: setHours(setMinutes(new Date(), 59), 22), And remove these props from the DatePicker component: minTime={this.state.minTime}
maxTime={this.state.maxTime} These props are overriding both excludeTimes and filterTime, causing time slots to be incorrectly disabled. The maintenance window and buffer checks in filterTime will handle all the necessary time restrictions. ✏️ Learnings added
|
@coderabbitai I think the problem are the buffer minutes
|
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's the fix. Replace the const filterPassedTime = (time) => {
// For future dates, only check maintenance window
if (!moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) {
const hour = time.getHours();
const minutes = time.getMinutes();
// Block maintenance window (22:00-01:00)
return !(hour >= 22 || hour < 1 || (hour === 22 && minutes > 0));
}
// For today, check both maintenance window and use fixed 30-minute buffer
const currentTime = moment();
const timeToCheck = moment(time);
const minutesDiff = timeToCheck.diff(currentTime, 'minutes');
return minutesDiff >= 30; // Fixed 30-minute buffer
}; This will:
✏️ Learnings added
|
@coderabbitai no buffer |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's the fix. Replace the const filterPassedTime = (time) => {
const hour = time.getHours();
const minutes = time.getMinutes();
// Block maintenance window (22:00-01:00)
return !(hour >= 22 || hour < 1 || (hour === 22 && minutes > 0));
}; This will:
(`・ω・)ゞ Thoughtfully removed buffer to enable all valid time slots. ✏️ Learnings added
🧠 Learnings used
|
now for over 60 minutes, the 30 minute time slots are not showing in the selection @coderabbitai add them. for example 90 minutes I'm still getting 90 interval selections
|
Oops, something went wrong! Please try again later. 🐰 💔 |
@coderabbitai for past opening hours the checkboxes are not disabled but should be Wochentage and Die Dienstleistungen dürfen mehr als einen Zeitschlitz beanspruchen
|
Oops, something went wrong! Please try again later. 🐰 💔 |
3 similar comments
Oops, something went wrong! Please try again later. 🐰 💔 |
Oops, something went wrong! Please try again later. 🐰 💔 |
Oops, something went wrong! Please try again later. 🐰 💔 |
Pull Request Checklist (Feature Branch to
next
):next
Branch in meinen Feature-Branch gemergt.Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
User Experience
Technical Enhancements