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:
@@ -21,7 +21,7 @@ import {
|
||||
import withCategoryRoute from './withCategoryRoute';
|
||||
import { artikelDetailPath, articleSku } from './articleRoute';
|
||||
import { selectCompanyId } from '../../store/companySlice';
|
||||
import { selectHasPosterminals, selectPosterminals } from '../../store/posterminalSlice';
|
||||
import { selectHasPosterminals, selectPosterminals, loadPosterminals } from '../../store/posterminalSlice';
|
||||
import {
|
||||
buildCategoryPath,
|
||||
defaultCategoryPath,
|
||||
@@ -47,6 +47,7 @@ import {
|
||||
selectCategoryTreeStatus,
|
||||
selectChildCategories,
|
||||
selectRenameMode,
|
||||
patchCategoryPosterminalIds,
|
||||
} from '../../store/categorySlice';
|
||||
import {
|
||||
enableTerminalCategory,
|
||||
@@ -72,6 +73,7 @@ class ArtikelKategorienPage extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.ensureTreeLoaded();
|
||||
this.ensurePosterminalsLoaded();
|
||||
this.syncCategoryFromUrl();
|
||||
this.ensureArticlesLoaded();
|
||||
this.syncSortable();
|
||||
@@ -158,6 +160,12 @@ class ArtikelKategorienPage extends Component {
|
||||
this.props.loadCategoryTree();
|
||||
};
|
||||
|
||||
ensurePosterminalsLoaded = () => {
|
||||
const { companyId } = this.props;
|
||||
if (!companyId) return;
|
||||
this.props.loadPosterminals();
|
||||
};
|
||||
|
||||
ensureArticlesLoaded = () => {
|
||||
const { currentCategoryId, articlesStatus, rootCategoryId, treeStatus } = this.props;
|
||||
if (treeStatus !== 'succeeded' || !currentCategoryId || articlesStatus !== 'idle') return;
|
||||
@@ -356,7 +364,13 @@ class ArtikelKategorienPage extends Component {
|
||||
: this.props.disableTerminalCategory;
|
||||
void thunk({ terminalId, categoryId: item.id })
|
||||
.unwrap()
|
||||
.then(() => this.props.loadCategoryTree())
|
||||
.then(() => {
|
||||
this.props.patchCategoryPosterminalIds({
|
||||
categoryId: item.id,
|
||||
terminalId,
|
||||
enabled,
|
||||
});
|
||||
})
|
||||
.catch(notifyError);
|
||||
}}
|
||||
onOpen={() => this.navigateToCategoryById(item.id)}
|
||||
@@ -456,6 +470,7 @@ const mapStateToProps = (state) => ({
|
||||
const mapDispatchToProps = {
|
||||
loadCategoryTree,
|
||||
loadCategoryArticles,
|
||||
loadPosterminals,
|
||||
navigateToCategory,
|
||||
renameCategory,
|
||||
deleteCategory,
|
||||
@@ -464,6 +479,7 @@ const mapDispatchToProps = {
|
||||
toggleCategoryPos,
|
||||
enableTerminalCategory,
|
||||
disableTerminalCategory,
|
||||
patchCategoryPosterminalIds,
|
||||
};
|
||||
|
||||
export default withCategoryRoute(connect(mapStateToProps, mapDispatchToProps)(ArtikelKategorienPage));
|
||||
|
||||
Reference in New Issue
Block a user