Skip to content

Commit

Permalink
Updated to use the new util formatAsOBject()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayoub Baàli authored Feb 5, 2021
1 parent 1e758cf commit b59744a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions webapp/javascript/components/CustomDatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import React, { useState, useEffect } from "react";
import moment from "moment";
import { useSelector } from "react-redux";
import DatePicker from "react-datepicker";
import {
readableRange,
fromConverter,
untilConverter,
} from "../util/formatDate";
import { readableRange, formatAsOBject } from "../util/formatDate";

function CustomDatePicker({ setRange, dispatch, setDateRange }) {
const from = useSelector((state) => state.from);
const until = useSelector((state) => state.until);
const [warning, setWarning] = useState(false);
const [selectedDate, setSelectedDate] = useState({
from: fromConverter(from).from,
until: untilConverter(until).until,
from: formatAsOBject(from),
until: formatAsOBject(until),
});
const [warning, setWarning] = useState(false);

const updateDateRange = () => {
if (moment(selectedDate.from).isSameOrAfter(selectedDate.until)) {
return setWarning(true);
Expand All @@ -32,11 +29,12 @@ function CustomDatePicker({ setRange, dispatch, setDateRange }) {
useEffect(() => {
setSelectedDate({
...selectedDate,
from: fromConverter(from).from,
until: untilConverter(until).until,
from: formatAsOBject(from),
until: formatAsOBject(until),
});
setRange(readableRange(from, until));
}, [from, until]);

return (
<div>
<h4>Custom Date Range</h4>
Expand Down

0 comments on commit b59744a

Please sign in to comment.