1- import { createSlice , createAsyncThunk } from '@reduxjs/toolkit' ;
1+ import { createSlice , createAsyncThunk , PayloadAction } from '@reduxjs/toolkit' ;
22
33import { searchDeployments as _searchDeployments } from '../apis' ;
44import { Deployment } from '../models' ;
@@ -7,50 +7,59 @@ export const perPage = 30;
77
88interface ActivitiesState {
99 loading : boolean ;
10+ startDate ?: Date ;
11+ endDate ?: Date ;
12+ productionOnly : boolean ;
1013 deployments : Deployment [ ] ;
1114 page : number ;
1215}
1316
1417const initialState : ActivitiesState = {
1518 loading : false ,
19+ productionOnly : false ,
1620 deployments : [ ] ,
1721 page : 1 ,
1822} ;
1923
2024export const searchDeployments = createAsyncThunk <
2125 Deployment [ ] ,
22- {
23- start ?: Date ;
24- end ?: Date ;
25- productionOnly : boolean ;
26- } ,
26+ void ,
2727 {
2828 state : { activities : ActivitiesState } ;
2929 }
30- > (
31- 'activities/searchDeployments' ,
32- async ( { start, end, productionOnly } , { getState, rejectWithValue } ) => {
33- const { page } = getState ( ) . activities ;
34- try {
35- return await _searchDeployments (
36- [ ] ,
37- false ,
38- productionOnly ,
39- start ,
40- end ,
41- page ,
42- perPage
43- ) ;
44- } catch ( e ) {
45- return rejectWithValue ( e ) ;
46- }
30+ > ( 'activities/searchDeployments' , async ( _ , { getState, rejectWithValue } ) => {
31+ const { startDate, endDate, productionOnly, page } = getState ( ) . activities ;
32+ try {
33+ return await _searchDeployments (
34+ [ ] ,
35+ false ,
36+ productionOnly ,
37+ startDate ,
38+ endDate ,
39+ page ,
40+ perPage
41+ ) ;
42+ } catch ( e ) {
43+ return rejectWithValue ( e ) ;
4744 }
48- ) ;
45+ } ) ;
4946
5047export const activitiesSlice = createSlice ( {
5148 name : 'activities' ,
5249 initialState,
5350 reducers : {
51+ setSearchOptions : (
52+ state : ActivitiesState ,
53+ action : PayloadAction < {
54+ startDate : Date ;
55+ endDate : Date ;
56+ productionOnly : boolean ;
57+ } >
58+ ) => {
59+ state . startDate = action . payload . startDate ;
60+ state . endDate = action . payload . endDate ;
61+ state . productionOnly = action . payload . productionOnly ;
62+ } ,
5463 increasePage : ( state ) => {
5564 state . page = state . page + 1 ;
5665 } ,
0 commit comments