Directly patch posterminalIds in Redux instead of reloading the category tree
After toggling a POS category, update the category's posterminalIds array in-place rather than re-fetching the entire tree. This keeps the settings cycle open on the same terminal. Also fix off-by-one in terminal cycling and ensure posterminals load on category page mount.
This commit is contained in:
@@ -291,6 +291,17 @@ const categorySlice = createSlice({
|
||||
resetCategoryState() {
|
||||
return initialState;
|
||||
},
|
||||
patchCategoryPosterminalIds(state, action) {
|
||||
const { categoryId, terminalId, enabled } = action.payload;
|
||||
const cat = state.categories?.[String(categoryId)];
|
||||
if (!cat) return;
|
||||
if (!Array.isArray(cat.posterminalIds)) cat.posterminalIds = [];
|
||||
if (enabled && !cat.posterminalIds.includes(terminalId)) {
|
||||
cat.posterminalIds.push(terminalId);
|
||||
} else if (!enabled) {
|
||||
cat.posterminalIds = cat.posterminalIds.filter((id) => id !== terminalId);
|
||||
}
|
||||
},
|
||||
setRenameMode(state, action) {
|
||||
state.renameMode = Boolean(action.payload);
|
||||
},
|
||||
@@ -451,6 +462,7 @@ export const {
|
||||
setRenameMode,
|
||||
removeArticleBySku,
|
||||
patchArticleInLists,
|
||||
patchCategoryPosterminalIds,
|
||||
} = categorySlice.actions;
|
||||
|
||||
export const selectRenameMode = (state) => state.category.renameMode;
|
||||
|
||||
Reference in New Issue
Block a user