Revert "move daysbooked fetch to context"

This reverts commit 87b38e6d30.
This commit is contained in:
Thomas Ruoff
2020-11-02 23:30:19 +01:00
parent cb9932240d
commit 8715e09563
2 changed files with 15 additions and 21 deletions

View File

@@ -7,18 +7,28 @@ import {
isWithinInterval,
endOfDay,
} from 'date-fns'
import useSWR from 'swr'
import Calendar from 'react-calendar'
import { dateFormatBackend } from '../../helpers/date'
import { getNextBigger, getNextSmaller } from '../../helpers/array'
import { WizardContext } from './context/wizardStore'
const fetcher = (path: string) => fetch(path).then((r) => r.json())
export default function MyCalendar({ ...props }) {
const { onChange, state, daysBooked, daysBookedErrorMessage } = useContext(
WizardContext
)
const { onChange, state } = useContext(WizardContext)
const { startDate: start, endDate: end } = state.formData
const startDate = (start && new Date(start)) || null
const endDate = (end && new Date(end)) || null
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
'/api/daysbooked',
fetcher,
{
revalidateOnFocus: true,
revalidateOnReconnect: true,
focusThrottleInterval: 24 * 60 * 60 * 1000,
}
)
const inSelection = !!start && !end
const prevBooked = inSelection && getNextSmaller(daysBooked, start)
@@ -72,7 +82,7 @@ export default function MyCalendar({ ...props }) {
})
}
if (daysBookedErrorMessage) {
if (fetchBookedOnError) {
return (
<div>
Entschuldigen Sie, aber die Buchungszeiten konnten nicht geladen werden.
@@ -87,7 +97,7 @@ export default function MyCalendar({ ...props }) {
<Calendar
minDate={new Date()}
// @ts-ignore
onClickDay={(date: Date, event: React.MouseEvent<HTMLInputElement>) => {
onClickDay={(date, event: React.MouseEvent<HTMLInputElement>) => {
event.preventDefault()
event.stopPropagation()