make form just simple

This commit is contained in:
Thomas Ruoff
2020-07-29 00:01:54 +02:00
parent a26e58b43e
commit 526c625a57
7 changed files with 116 additions and 119 deletions

View File

@@ -9,11 +9,13 @@ import moment from 'moment'
import 'react-dates/initialize'
import { DateRangePicker, SingleDatePicker } from 'react-dates'
import { dateFormat } from '../lib/dateHelper'
const fetcher = (path) => fetch(path).then((r) => r.json())
export default function DateSelect() {
const [focusedInput, setFocusedInput] = useState(null)
const { state, dispatch } = useContext(WizardContext)
const { state, onChange, onChangeEvent } = useContext(WizardContext)
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
'/api/daysbooked',
fetcher
@@ -49,13 +51,10 @@ export default function DateSelect() {
checked={multipleDays === false}
onChange={() => {
setFocusedInput(null)
dispatch({
type: ACTIONS.SET_FORM_DATA,
payload: {
multipleDays: false,
startDate: null,
endDate: null,
},
onChange({
multipleDays: false,
startDate: null,
endDate: null,
})
}}
/>
@@ -68,13 +67,10 @@ export default function DateSelect() {
checked={multipleDays === true}
onChange={() => {
setFocusedInput(null)
dispatch({
type: ACTIONS.SET_FORM_DATA,
payload: {
multipleDays: true,
startDate: null,
endDate: null,
},
onChange({
multipleDays: true,
startDate: null,
endDate: null,
})
}}
/>
@@ -91,11 +87,8 @@ export default function DateSelect() {
placeholder="Datum"
numberOfMonths={1}
onDateChange={(date) =>
dispatch({
type: ACTIONS.SET_FORM_DATA,
payload: {
startDate: date && date.toISOString(),
},
onChange({
startDate: date && dateFormat(date),
})
}
focused={typeof focusedInput === 'boolean' && focusedInput}
@@ -115,12 +108,9 @@ export default function DateSelect() {
endDate={endDate && moment(endDate)}
endDateId="endDate"
onDatesChange={({ startDate, endDate }) => {
dispatch({
type: ACTIONS.SET_FORM_DATA,
payload: {
startDate: startDate && startDate.toISOString(),
endDate: endDate && endDate.toISOString(),
},
onChange({
startDate: startDate && dateFormat(startDate),
endDate: endDate && dateFormat(endDate),
})
}}
focusedInput={focusedInput}