Skip to content

Commit f316a17

Browse files
committed
Fix Custom Date Range Input
1 parent 4e31536 commit f316a17

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

webapp/javascript/components/DateRangePicker.jsx

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,15 @@ function DateRangePicker() {
4646
const from = useSelector((state) => state.from);
4747
const until = useSelector((state) => state.until);
4848

49-
const initialState = {
50-
// so the idea with this is that we don't want to send from and until back to the state
51-
// until the user clicks some button. This is why these are stored in state here.
52-
from,
53-
until,
54-
opened: false,
55-
};
56-
const [state, setState] = useState(initialState);
49+
const [opened, setOpened] = useState(false);
5750
const [presets, setPresets] = useState(defaultPresets);
5851

5952
const updateFrom = (from) => {
60-
setState({ from });
53+
dispatch(setDateRange(from, until));
6154
};
6255

6356
const updateUntil = (until) => {
64-
setState({ until });
57+
dispatch(setDateRange(from, until));
6558
};
6659

6760
const updateDateRange = () => {
@@ -85,27 +78,23 @@ function DateRangePicker() {
8578
// return from + " to " +until;
8679
};
8780

88-
const showDropdown = () => {
89-
setState({
90-
opened: !state.opened,
91-
});
81+
const toggleDropdown = () => {
82+
setOpened(!opened);
9283
};
9384

94-
const selectPreset = ({ from, until }) => {
95-
dispatch(setDateRange(from, until));
96-
hideDropdown();
85+
const hideDropdown = () => {
86+
setOpened(false);
9787
};
9888

99-
const hideDropdown = () => {
100-
setState({
101-
opened: false,
102-
});
89+
const selectPreset = ({ from, until }) => {
90+
dispatch(setDateRange(from, until));
91+
setOpened(false);
10392
};
10493

10594
return (
106-
<div className={state.opened ? "drp-container opened" : "drp-container"}>
95+
<div className={opened ? "drp-container opened" : "drp-container"}>
10796
<OutsideClickHandler onOutsideClick={hideDropdown}>
108-
<button className="btn drp-button" onClick={showDropdown}>
97+
<button className="btn drp-button" onClick={toggleDropdown}>
10998
<FontAwesomeIcon icon={faClock} />
11099
<span>{humanReadableRange()}</span>
111100
</button>

0 commit comments

Comments
 (0)