umami/redux/actions/websites.js

34 lines
755 B
JavaScript
Raw Normal View History

2020-08-31 23:11:30 +02:00
import { createSlice } from '@reduxjs/toolkit';
import produce from 'immer';
const websites = createSlice({
name: 'user',
initialState: {},
reducers: {
updateWebsites(state, action) {
state = action.payload;
return state;
},
},
});
export const { updateWebsites } = websites.actions;
export default websites.reducer;
export function setDateRange(websiteId, dateRange) {
return (dispatch, getState) => {
const state = getState();
let { websites = {} } = state;
websites = produce(websites, draft => {
if (!draft[websiteId]) {
draft[websiteId] = {};
}
2020-09-01 00:02:32 +02:00
draft[websiteId].dateRange = { ...dateRange, modified: Date.now() };
2020-08-31 23:11:30 +02:00
});
return dispatch(updateWebsites(websites));
};
}