Skip to content

Commit

Permalink
dayjs optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
prv-proton committed Jan 7, 2025
1 parent 204c85b commit 6b06ffa
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export const BCDateFloatingFilter = ({
const handleChange = useCallback((newDate) => {
setSelectedDate(newDate)

if (newDate && isValid(newDate)) {
if (newDate && newDate.isValid()) {
// Validate with dayjs
onModelChange({
type: initialFilterType,
dateFrom: format(newDate, 'yyyy-MM-dd'),
dateFrom: newDate.format('YYYY-MM-DD'),
dateTo: null,
filterType: 'date'
})
Expand Down Expand Up @@ -58,8 +59,8 @@ export const BCDateFloatingFilter = ({
}

if (model?.dateFrom) {
const date = new Date(model.dateFrom)
setSelectedDate(isValid(date) ? date : null)
const date = dayjs(model.dateFrom)
setSelectedDate(date.isValid() ? date : null)
}
}, [model])

Expand All @@ -86,7 +87,7 @@ export const BCDateFloatingFilter = ({
aria-describedby="date-picker-description"
sx={{
border: 'none',
borderBottom: '4px solid #495057',
borderBottom: '4px solid #495057'
}}
value={selectedDate}
minDate={dayjs(minDate)}
Expand Down

0 comments on commit 6b06ffa

Please sign in to comment.