mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
34 lines
755 B
JavaScript
34 lines
755 B
JavaScript
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] = {};
|
|
}
|
|
draft[websiteId].dateRange = { ...dateRange, modified: Date.now() };
|
|
});
|
|
|
|
return dispatch(updateWebsites(websites));
|
|
};
|
|
}
|