mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
hook up onChange
This commit is contained in:
@@ -17,19 +17,17 @@ const fetcher = (path) => fetch(path).then((r) => r.json())
|
|||||||
|
|
||||||
export default function DateSelect() {
|
export default function DateSelect() {
|
||||||
const { state, onChange } = useContext(WizardContext)
|
const { state, onChange } = useContext(WizardContext)
|
||||||
const [range, setRange] = useState({ form: null, to: null })
|
const [range, setRange] = useState({
|
||||||
|
form: state.startDate && new Date(state.StartDate),
|
||||||
|
to: state.endDate && new Date(state.endDate),
|
||||||
|
})
|
||||||
|
const { from, to } = range
|
||||||
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
|
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
|
||||||
'/api/daysbooked',
|
'/api/daysbooked',
|
||||||
fetcher
|
fetcher
|
||||||
)
|
)
|
||||||
const prevBookedDay = getNextSmaller(
|
const prevBookedDay = getNextSmaller(daysBooked, dateFormat(from || to))
|
||||||
daysBooked,
|
const nextBookedDay = getNextBigger(daysBooked, dateFormat(from || to))
|
||||||
dateFormat(range.from || range.to)
|
|
||||||
)
|
|
||||||
const nextBookedDay = getNextBigger(
|
|
||||||
daysBooked,
|
|
||||||
dateFormat(range.from || range.to)
|
|
||||||
)
|
|
||||||
|
|
||||||
const fromRef = useRef()
|
const fromRef = useRef()
|
||||||
const toRef = useRef()
|
const toRef = useRef()
|
||||||
@@ -53,9 +51,12 @@ export default function DateSelect() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
toRef.current?.getInput().focus()
|
toRef.current?.getInput().focus()
|
||||||
}, [range.from])
|
}, [from])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onChange({ startDate: from?.toISOString(), endDate: to?.toISOString() })
|
||||||
|
}, [from, to])
|
||||||
|
|
||||||
const { from, to } = range
|
|
||||||
const disabledDays = [dayDisabled]
|
const disabledDays = [dayDisabled]
|
||||||
const modifiers = {
|
const modifiers = {
|
||||||
dayBooked,
|
dayBooked,
|
||||||
|
|||||||
Reference in New Issue
Block a user