fix: date picker

This commit is contained in:
Nikola Ubavic 2022-04-14 19:07:26 +02:00
parent 913e617d1b
commit bc8335adee
2 changed files with 11 additions and 23 deletions

View file

@ -178,9 +178,7 @@ const Calendar = ({ minDate, maxDate, handleSelect, ...props }) => {
{R.range(1, 8).map((row, key) => ( {R.range(1, 8).map((row, key) => (
<tr key={key}> <tr key={key}>
{getRow(currentDisplayedMonth, row).map((day, key) => ( {getRow(currentDisplayedMonth, row).map((day, key) => (
<td <td key={key} onClick={() => handleSelect(day)}>
key={key}
onClick={() => handleSelect(day, minDate, maxDate)}>
<Tile <Tile
isDisabled={ isDisabled={
(maxDate && isAfter(maxDate, day)) || (maxDate && isAfter(maxDate, day)) ||

View file

@ -1,11 +1,6 @@
import { makeStyles } from '@material-ui/core/styles' import { makeStyles } from '@material-ui/core/styles'
import classnames from 'classnames' import classnames from 'classnames'
import { import { differenceInDays, set } from 'date-fns/fp'
differenceInDays,
differenceInMonths,
isSameMonth,
set
} from 'date-fns/fp'
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import Calendar from './Calendar' import Calendar from './Calendar'
@ -36,20 +31,15 @@ const DateRangePicker = ({ minDate, maxDate, className, onRangeChange }) => {
) )
return return
if (from && !to && differenceInDays(day, from) > 0) { if (from && !to) {
setTo(from) if (differenceInDays(from, day) >= 0) {
setFrom(day) setTo(
return set({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 }, day)
} )
} else {
if ( setTo(from)
from && setFrom(day)
!to && }
(isSameMonth(from, day) || differenceInMonths(from, day) > 0)
) {
setTo(
set({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 }, day)
)
return return
} }