You are overwriting the onBeforeCellRender event handler several times and only the last value is used.
You need to check the dates against the list of highlighted days inside onBeforeCellRender.
This approach is used in the following tutorial:
You can use something like this:
onBeforeCellRender: (args) => {
const startHour = parseInt(formData.startHour.selected.startHour);
const endHour = parseInt(formData.endHour.selected.endHour);
const item = datesArray.find(day => {
const start = new DayPilot.Date(day).addHours(startHour);
const end = new DayPilot.Date(day).addHours(endHour);
return DayPilot.Util.overlaps(start, end, args.cell.start, args.cell.end);
});
if (item) {
args.cell.backColor = 'rgba(223, 242, 227, 0.7)';
}
}
Define the event handler only once and make sure it can read the current values of startHour, endHour and datesArray.