1
1
import React , { useState } from "react" ;
2
- import { connect } from "react-redux" ;
2
+ import { useDispatch , useSelector } from "react-redux" ;
3
3
4
4
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
5
5
import { faClock } from "@fortawesome/free-solid-svg-icons" ;
6
6
7
7
import OutsideClickHandler from "react-outside-click-handler" ;
8
8
import moment from "moment" ;
9
- import { bindActionCreators } from "redux" ;
10
- import { setDateRange , receiveJSON , setFrom , setUntil } from "../redux/actions" ;
9
+ import { setDateRange } from "../redux/actions" ;
11
10
12
11
const defaultPresets = [
13
12
[
@@ -42,8 +41,11 @@ const multiplierMapping = {
42
41
y : "year" ,
43
42
} ;
44
43
45
- function DateRangePicker ( props ) {
46
- const { from, until, actions } = props ;
44
+ function DateRangePicker ( ) {
45
+ const dispatch = useDispatch ( ) ;
46
+ const from = useSelector ( ( state ) => state . from ) ;
47
+ const until = useSelector ( ( state ) => state . until ) ;
48
+
47
49
const initialState = {
48
50
// so the idea with this is that we don't want to send from and until back to the state
49
51
// until the user clicks some button. This is why these are stored in state here.
@@ -63,7 +65,7 @@ function DateRangePicker(props) {
63
65
} ;
64
66
65
67
const updateDateRange = ( ) => {
66
- actions . setDateRange ( state . from , state . until ) ;
68
+ dispatch ( setDateRange ( from , until ) ) ;
67
69
} ;
68
70
69
71
const humanReadableRange = ( ) => {
@@ -90,7 +92,7 @@ function DateRangePicker(props) {
90
92
} ;
91
93
92
94
const selectPreset = ( { from, until } ) => {
93
- actions . setDateRange ( from , until ) ;
95
+ dispatch ( setDateRange ( from , until ) ) ;
94
96
hideDropdown ( ) ;
95
97
} ;
96
98
@@ -132,7 +134,7 @@ function DateRangePicker(props) {
132
134
className = "followed-by-btn"
133
135
onChange = { ( e ) => updateFrom ( e . target . value ) }
134
136
onBlur = { updateDateRange }
135
- value = { state . from }
137
+ value = { from }
136
138
/>
137
139
< button className = "drp-calendar-btn btn" onClick = { updateDateRange } >
138
140
< FontAwesomeIcon icon = { faClock } />
@@ -144,7 +146,7 @@ function DateRangePicker(props) {
144
146
className = "followed-by-btn"
145
147
onChange = { ( e ) => updateUntil ( e . target . value ) }
146
148
onBlur = { updateDateRange }
147
- value = { state . until }
149
+ value = { until }
148
150
/>
149
151
< button className = "drp-calendar-btn btn" onClick = { updateDateRange } >
150
152
< FontAwesomeIcon icon = { faClock } />
@@ -157,20 +159,4 @@ function DateRangePicker(props) {
157
159
) ;
158
160
}
159
161
160
- const mapStateToProps = ( state ) => ( {
161
- ...state ,
162
- } ) ;
163
-
164
- const mapDispatchToProps = ( dispatch ) => ( {
165
- actions : bindActionCreators (
166
- {
167
- setDateRange,
168
- receiveJSON,
169
- setFrom,
170
- setUntil,
171
- } ,
172
- dispatch
173
- ) ,
174
- } ) ;
175
-
176
- export default connect ( mapStateToProps , mapDispatchToProps ) ( DateRangePicker ) ;
162
+ export default DateRangePicker ;
0 commit comments