umami/redux/actions/websites.js

36 lines
862 B
JavaScript

import { createSlice } from '@reduxjs/toolkit';
const websites = createSlice({
name: 'websites',
initialState: {},
reducers: {
updateWebsites(state, action) {
state = action.payload;
return state;
},
updateWebsite(state, action) {
const { websiteId, ...data } = action.payload;
state[websiteId] = { ...state[websiteId], ...data };
return state;
},
},
});
export const { updateWebsites, updateWebsite } = websites.actions;
export default websites.reducer;
export function setDateRange(websiteId, dateRange) {
return dispatch => {
return dispatch(
updateWebsite({ websiteId, dateRange: { ...dateRange, modified: Date.now() } }),
);
};
}
export function setWebsiteCreated(websiteId, createdAt) {
return dispatch => {
return dispatch(updateWebsite({ websiteId, createdAt }));
};
}