mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
Revert "move daysbooked fetch to context"
This reverts commit 87b38e6d30.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user