fix range selection issue

This commit is contained in:
Thomas Ruoff
2020-08-06 23:29:38 +02:00
parent 7dc8c71852
commit 5dac8f20a3
2 changed files with 22 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ import DayPicker, { DateUtils } from 'react-day-picker'
import Required from './required'
import { dateFormat } from '../helpers/date'
import { getNextSmaller, getNextBigger } from '../helpers/array'
const fetcher = (path) => fetch(path).then((r) => r.json())
@@ -20,21 +21,8 @@ export default function DateSelect() {
'/api/daysbooked',
fetcher
)
const prevBookedDay = range.from
? daysBooked
.reverse()
.find((dayBooked) => dayBooked < dateFormat(range.from))
: null
const nextBookedDay = range.from
? daysBooked.find((dayBooked) => dayBooked > dateFormat(range.from))
: null
console.log('from', dateFormat(range.from), 'to', dateFormat(range.to))
console.log('prev', prevBookedDay, 'next', nextBookedDay)
function dayBeforeToday(day) {
return new Date() > day
}
const prevBookedDay = getNextSmaller(daysBooked, dateFormat(range.from))
const nextBookedDay = getNextBigger(daysBooked, dateFormat(range.from))
function dayBooked(day) {
return daysBooked && daysBooked.includes(dateFormat(day))
@@ -42,7 +30,7 @@ export default function DateSelect() {
function dayDisabled(day) {
return (
dayBeforeToday(day) ||
DateUtils.isPastDay(day) ||
dayBooked(day) ||
(prevBookedDay && day < new Date(prevBookedDay)) ||
(nextBookedDay && day > new Date(nextBookedDay))