fix most type errors

still have a few things outstanding
This commit is contained in:
Thomas Ruoff
2020-08-28 00:29:20 +02:00
committed by Thomas Ruoff
parent c3d8c6f3e0
commit 90ac05a907
16 changed files with 279 additions and 96 deletions

View File

@@ -1,33 +1,27 @@
import React, { useContext, useState, useRef, useEffect } from 'react'
import * as React from 'react'
import { useEffect, useContext, useState, useRef } from 'react'
import useSWR from 'swr'
import { WizardContext } from './context/wizardStore'
import { DateUtils } from 'react-day-picker'
import { DateUtils, RangeModifier } from 'react-day-picker'
import DayPickerInput from 'react-day-picker/DayPickerInput'
import Required from './required'
import { dateFormatBackend } from '../../helpers/date'
import { getNextSmaller, getNextBigger } from '../../helpers/array'
import MomentLocaleUtils, {
// @ts-expect-error ts-migrate(2614) FIXME: Module '"../../node_modules/react-day-picker/types... Remove this comment to see the full error message
formatDate,
// @ts-expect-error ts-migrate(2614) FIXME: Module '"../../node_modules/react-day-picker/types... Remove this comment to see the full error message
parseDate,
} from 'react-day-picker/moment'
import MomentLocaleUtils from 'react-day-picker/moment'
import 'moment/locale/de'
const fetcher = (path) => fetch(path).then((r) => r.json())
const fetcher = (path: string) => fetch(path).then((r) => r.json())
export default function DateSelect() {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'state' does not exist on type '{}'.
const { state, onChange } = useContext(WizardContext)
const [range, setRange] = useState({
form: state.startDate && new Date(state.startDate),
to: state.endDate && new Date(state.endDate),
const { onChange } = useContext(WizardContext)
const [range, setRange] = useState<RangeModifier>({
from: undefined, //state.startDate && new Date(state.startDate),
to: undefined, //state.endDate && new Date(state.endDate),
})
// @ts-expect-error ts-migrate(2339) FIXME: Property 'from' does not exist on type '{ form: Da... Remove this comment to see the full error message
const { from, to } = range
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
'/api/daysbooked',
@@ -39,14 +33,14 @@ export default function DateSelect() {
)
const nextBookedDay = getNextBigger(daysBooked, dateFormatBackend(from || to))
const fromRef = useRef()
const toRef = useRef()
const fromRef = useRef<DayPickerInput>()
const toRef = useRef<DayPickerInput>()
function dayBooked(day) {
function dayBooked(day: Date) {
return daysBooked && daysBooked.includes(dateFormatBackend(day))
}
function dayDisabled(day) {
function dayDisabled(day: Date) {
return (
DateUtils.isPastDay(day) ||
dayBooked(day) ||
@@ -57,7 +51,6 @@ export default function DateSelect() {
}
useEffect(() => {
// @ts-expect-error ts-migrate(2532) FIXME: Object is possibly 'undefined'.
toRef.current?.getInput().focus()
}, [from])
@@ -92,8 +85,8 @@ export default function DateSelect() {
inputProps={{ className: 'input-text' }}
value={from}
placeholder="Von"
formatDate={formatDate}
parseDate={parseDate}
formatDate={MomentLocaleUtils.formatDate}
parseDate={MomentLocaleUtils.parseDate}
dayPickerProps={{
locale: 'de',
localeUtils: MomentLocaleUtils,
@@ -102,7 +95,6 @@ export default function DateSelect() {
modifiers,
numberOfMonths: 1,
}}
// @ts-expect-error ts-migrate(2345) FIXME: Object literal may only specify known properties, ... Remove this comment to see the full error message
onDayChange={(from) => setRange({ ...range, from })}
/>
{' - '}
@@ -111,8 +103,8 @@ export default function DateSelect() {
inputProps={{ className: 'input-text', disabled: !from }}
value={to}
placeholder="Bis"
formatDate={formatDate}
parseDate={parseDate}
formatDate={MomentLocaleUtils.formatDate}
parseDate={MomentLocaleUtils.parseDate}
dayPickerProps={{
locale: 'de',
localeUtils: MomentLocaleUtils,
@@ -126,8 +118,10 @@ export default function DateSelect() {
}}
onDayChange={(to) => setRange({ ...range, to })}
/>
{/* @ts-expect-error ts-migrate(2345) FIXME: Type '{}' provides no match for the signature '(pr... Remove this comment to see the full error message */}
<button onClick={() => setRange({})} className="ibtn">
<button
onClick={() => setRange({ from: undefined, to: undefined })}
className="ibtn"
>
<svg className="w-full" viewBox="0 0 352 512">
<path
fill="currentColor"