PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.17
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.17
1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 All 180 releases
disco / backend / views / components / Analytics / features / dateRange / dateRangeSlice.js

dateRangeSlice.js in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.17, at backend/views/components/Analytics/features/dateRange/dateRangeSlice.js

40 lines 876 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { createSelector, createSlice } from '@reduxjs/toolkit';
2 import { format, subDays } from 'date-fns';
3
4 function toApiDate(date) {
5 return format(date, 'yyyy-MM-dd');
6 }
7
8 const today = new Date();
9 const defaultStart = subDays(today, 27);
10
11 const initialState = {
12 startDate: toApiDate(defaultStart),
13 endDate: toApiDate(today),
14 };
15
16 const dateRangeSlice = createSlice({
17 name: 'dateRange',
18 initialState,
19 reducers: {
20 setDateRange(state, action) {
21 state.startDate = action.payload.startDate;
22 state.endDate = action.payload.endDate;
23 },
24 },
25 });
26
27 export const { setDateRange } = dateRangeSlice.actions;
28
29 export const selectDateRange = (state) => state.dateRange;
30
31 export const selectDateRangeParams = createSelector(
32 [selectDateRange],
33 (dateRange) => ({
34 date_from: dateRange.startDate,
35 date_to: dateRange.endDate,
36 })
37 );
38
39 export default dateRangeSlice.reducer;
40