| 1 |
import { createSlice } from '@reduxjs/toolkit'; |
| 2 |
|
| 3 |
const initialState = { |
| 4 |
campaign_ids: [], |
| 5 |
campaigns: [], |
| 6 |
searchTerm: '', |
| 7 |
}; |
| 8 |
|
| 9 |
export const campaignSlice = createSlice({ |
| 10 |
name: 'campaign', |
| 11 |
initialState, |
| 12 |
reducers: { |
| 13 |
resetSelectedIDs: (state) => { |
| 14 |
state.campaign_ids = []; |
| 15 |
}, |
| 16 |
toggleCampaignSelect: (state, action) => { |
| 17 |
if (state.campaign_ids.includes(action.payload)) { |
| 18 |
state.campaign_ids = state.campaign_ids.filter( |
| 19 |
(id) => id !== action.payload |
| 20 |
); |
| 21 |
} else { |
| 22 |
state.campaign_ids.push(action.payload); |
| 23 |
} |
| 24 |
}, |
| 25 |
setCampaignsInState: (state, action) => { |
| 26 |
state.campaigns = action.payload; |
| 27 |
}, |
| 28 |
setSearchTerm: (state, action) => { |
| 29 |
state.searchTerm = action.payload; |
| 30 |
}, |
| 31 |
}, |
| 32 |
}); |
| 33 |
|
| 34 |
export const { |
| 35 |
resetSelectedIDs, |
| 36 |
toggleCampaignSelect, |
| 37 |
setCampaignsInState, |
| 38 |
setSearchTerm, |
| 39 |
} = campaignSlice.actions; |
| 40 |
|
| 41 |
export default campaignSlice.reducer; |
| 42 |
|