From 0453680c5920d17e0350d7c98db4e338281d6ec9 Mon Sep 17 00:00:00 2001 From: seb Date: Wed, 28 Oct 2026 00:41:31 +0100 Subject: [PATCH] u --- .../article/ArticleStockAdjustDialog.jsx | 2 - .../article/tabs/ArticleSupplierTab.jsx | 24 +++---- .../manifest/BookDeliveryDialog.jsx | 5 +- src/components/manifest/ManifestForm.jsx | 4 -- .../settings/CompanySettingsPanel.jsx | 6 +- .../settings/PosTerminalSettingsPanel.jsx | 4 +- src/routes/artikel.jsx | 4 -- src/routes/artikel/_sku.jsx | 2 +- src/routes/artikel/kategorien.jsx | 1 - src/routes/artikel/lager.jsx | 4 +- src/routes/auftrag/versandarten.jsx | 4 +- src/routes/kunde/gruppen.jsx | 4 +- src/routes/lieferung/lieferanten.jsx | 65 +++++++------------ src/routes/lieferung/neu.jsx | 1 - 14 files changed, 47 insertions(+), 83 deletions(-) diff --git a/src/components/article/ArticleStockAdjustDialog.jsx b/src/components/article/ArticleStockAdjustDialog.jsx index 5c00da0..5dafd76 100644 --- a/src/components/article/ArticleStockAdjustDialog.jsx +++ b/src/components/article/ArticleStockAdjustDialog.jsx @@ -86,7 +86,6 @@ export default class ArticleStockAdjustDialog extends PureComponent { warehouseId: prev.warehouseId || (warehouses.length > 0 ? warehouses[0].id : ''), })); }, ['warehouses']); - void companyAutomat.actions.loadWarehouses().catch(() => {}); } componentWillUnmount() { @@ -95,7 +94,6 @@ export default class ArticleStockAdjustDialog extends PureComponent { componentDidUpdate(prevProps) { if (this.props.open && !prevProps.open) { - void companyAutomat.actions.loadWarehouses().catch(() => {}); const initialWhId = this.resolveInitialWarehouseId(this.props); const isTrackStock = this.props.article?.track_stock !== false && this.props.article?.track_stock !== 0; diff --git a/src/components/article/tabs/ArticleSupplierTab.jsx b/src/components/article/tabs/ArticleSupplierTab.jsx index 7cbde5f..52ea12b 100644 --- a/src/components/article/tabs/ArticleSupplierTab.jsx +++ b/src/components/article/tabs/ArticleSupplierTab.jsx @@ -38,8 +38,8 @@ export default class ArticleSupplierTab extends PureComponent { this.state = { loading: true, assignedSuppliers: [], - companySuppliers: [], - company: null, + companySuppliers: companyAutomat.state.suppliers ?? [], + company: companyAutomat.state.current ?? null, dialogOpen: false, editItem: null, busyId: null, @@ -47,9 +47,14 @@ export default class ArticleSupplierTab extends PureComponent { } componentDidMount() { - this.unsubCompany = companyAutomat.subscribe(this, (state) => ({ - company: state.current ?? null, - })); + this.unsubCompany = companyAutomat.subscribe( + this, + (state) => ({ + company: state.current ?? null, + companySuppliers: state.suppliers ?? [], + }), + ['current', 'suppliers'], + ); this.initData(); } @@ -89,15 +94,6 @@ export default class ArticleSupplierTab extends PureComponent { this.unwatchSignal = sseAutomat.actions.watchArticle(String(sku), () => { void articleSupplierAutomat.reload(String(sku)).catch(() => {}); }); - - // 2. Fetch available company suppliers - try { - const companySuppliers = await companyAutomat.actions.loadSuppliers(); - this.setState({ companySuppliers: companySuppliers ?? [] }); - } catch (err) { - notifyError(err); - this.setState({ loading: false }); - } } /** Re-fetches the assigned suppliers for the current article. */ diff --git a/src/components/manifest/BookDeliveryDialog.jsx b/src/components/manifest/BookDeliveryDialog.jsx index 1edcc88..fe5d4d1 100644 --- a/src/components/manifest/BookDeliveryDialog.jsx +++ b/src/components/manifest/BookDeliveryDialog.jsx @@ -98,8 +98,7 @@ export default class BookDeliveryDialog extends PureComponent { loadSupplierArticlesIfNeeded() { const supplierId = this.props.delivery?.supplierId ?? this.props.delivery?.partyId; if (supplierId && Object.keys(this.state.supplierArticlesMap).length === 0) { - void supplierApi.getArticles(supplierId).then((res) => { - const articles = res?.articles || res?.supplier?.articles || []; + void companyAutomat.actions.loadArticlesForSupplier(supplierId).then((articles) => { const map = buildSupplierArticlesMap(articles); this.setState({ supplierArticlesMap: map }); }).catch(() => { }); @@ -122,7 +121,6 @@ export default class BookDeliveryDialog extends PureComponent { this.unsubArticle = artikelAutomat.subscribe(() => { this.forceUpdate(); }); - void companyAutomat.actions.loadWarehouses().catch(() => { }); this.loadSupplierArticlesIfNeeded(); if (this.props.open) { @@ -225,7 +223,6 @@ export default class BookDeliveryDialog extends PureComponent { supplierArticlesMap: currentSupplierMap, }, () => { - void companyAutomat.actions.loadWarehouses().catch(() => { }); this.loadSupplierArticlesIfNeeded(); if (this.props.summary) { this.initAmountsFromSummary(this.props.summary, this.props.prefillLineId); diff --git a/src/components/manifest/ManifestForm.jsx b/src/components/manifest/ManifestForm.jsx index cd79911..4109063 100644 --- a/src/components/manifest/ManifestForm.jsx +++ b/src/components/manifest/ManifestForm.jsx @@ -242,10 +242,6 @@ class ManifestForm extends PureComponent { ['current', 'suppliers', 'suppliersStatus', 'customergroups', 'customergroupsStatus'], ); - if (companyAutomat.state.warehousesStatus === 'idle') { - void companyAutomat.actions.loadWarehouses(); - } - if (this.props.mode === 'edit') { void this.loadEdit(); if (this.props.kind === 'order' || this.props.kind === 'retoure') { diff --git a/src/components/settings/CompanySettingsPanel.jsx b/src/components/settings/CompanySettingsPanel.jsx index d0be55b..c8ce721 100644 --- a/src/components/settings/CompanySettingsPanel.jsx +++ b/src/components/settings/CompanySettingsPanel.jsx @@ -43,7 +43,11 @@ export default class CompanySettingsPanel extends Component { this.syncFormFromCompany(state.current); } }); - void this.loadCompany(); + if (companyAutomat.state.current) { + this.syncFormFromCompany(companyAutomat.state.current); + } else { + void this.loadCompany(); + } } componentWillUnmount() { diff --git a/src/components/settings/PosTerminalSettingsPanel.jsx b/src/components/settings/PosTerminalSettingsPanel.jsx index 445df6f..c0720ce 100644 --- a/src/components/settings/PosTerminalSettingsPanel.jsx +++ b/src/components/settings/PosTerminalSettingsPanel.jsx @@ -78,7 +78,9 @@ export default class PosTerminalSettingsPanel extends Component { if (categoryAutomat.state.treeStatus === 'idle') { void categoryAutomat.actions.loadTree(); } - void this.loadTerminals(); + if (companyAutomat.state.terminalsStatus !== 'succeeded') { + void this.loadTerminals(); + } } componentWillUnmount() { diff --git a/src/routes/artikel.jsx b/src/routes/artikel.jsx index 4878d3d..3e4961f 100644 --- a/src/routes/artikel.jsx +++ b/src/routes/artikel.jsx @@ -360,10 +360,6 @@ class ArtikelSearchPage extends Component { _suppliers: state.suppliers, })); - void companyAutomat.actions.loadBrands().catch(() => {}); - void companyAutomat.actions.loadSuppliers().catch(() => {}); - void companyAutomat.actions.loadAllSupplierArticles().catch(() => {}); - // Initial search: kicks off index loading if idle and derives current items const { filter: urlFilter, diff --git a/src/routes/artikel/_sku.jsx b/src/routes/artikel/_sku.jsx index d45b7fd..8247977 100644 --- a/src/routes/artikel/_sku.jsx +++ b/src/routes/artikel/_sku.jsx @@ -72,7 +72,7 @@ class ArtikelSkuPage extends Component { await Promise.all([ artikelAutomat.actions.loadArticle(sku), whenCategoryTreeReady(), - companyAutomat.actions.load(), + companyAutomat.state.current ? Promise.resolve(companyAutomat.state.current) : companyAutomat.actions.load(), bootstrapAuthMe(), ]); if (this._mounted) this.setState({ ready: true }); diff --git a/src/routes/artikel/kategorien.jsx b/src/routes/artikel/kategorien.jsx index d7d6f89..a432472 100644 --- a/src/routes/artikel/kategorien.jsx +++ b/src/routes/artikel/kategorien.jsx @@ -104,7 +104,6 @@ class ArtikelKategorienPage extends PureComponent { companyId: s.current?.id ?? null, })); this.ensureTreeLoaded(); - this.ensurePosterminalsLoaded(); this.subscribeViewHandle(); this.syncSortable(); } diff --git a/src/routes/artikel/lager.jsx b/src/routes/artikel/lager.jsx index 8ed4e08..e164a58 100644 --- a/src/routes/artikel/lager.jsx +++ b/src/routes/artikel/lager.jsx @@ -184,9 +184,7 @@ class ArtikelLagerPage extends PureComponent { error: state.warehousesError ? backendErrorFrom(state.warehousesError) : null, })); - if (companyAutomat.state.warehousesStatus !== 'ready') { - void companyAutomat.actions.loadWarehouses().catch((err) => notifyError(err)); - } else { + if (this.state.status === 'ready') { this._initSortable(); } } diff --git a/src/routes/auftrag/versandarten.jsx b/src/routes/auftrag/versandarten.jsx index b12b89d..ba1a8f9 100644 --- a/src/routes/auftrag/versandarten.jsx +++ b/src/routes/auftrag/versandarten.jsx @@ -144,9 +144,7 @@ class AuftragVersandartenPage extends PureComponent { error: state.carriersError ? backendErrorFrom(state.carriersError) : null, })); - if (companyAutomat.state.carriersStatus !== 'ready') { - void companyAutomat.actions.loadCarriers().catch((err) => notifyError(err)); - } else { + if (this.state.status === 'ready') { this._initSortable(); } } diff --git a/src/routes/kunde/gruppen.jsx b/src/routes/kunde/gruppen.jsx index 4b8eb61..fa1a9da 100644 --- a/src/routes/kunde/gruppen.jsx +++ b/src/routes/kunde/gruppen.jsx @@ -183,9 +183,7 @@ class KundeGruppenPage extends PureComponent { error: state.customergroupsError ? backendErrorFrom(state.customergroupsError) : null, })); - if (companyAutomat.state.customergroupsStatus !== 'ready') { - void companyAutomat.actions.loadCustomergroups().catch((err) => notifyError(err)); - } else { + if (this.state.status === 'ready') { this._initSortable(); } } diff --git a/src/routes/lieferung/lieferanten.jsx b/src/routes/lieferung/lieferanten.jsx index a9dca09..bb88387 100644 --- a/src/routes/lieferung/lieferanten.jsx +++ b/src/routes/lieferung/lieferanten.jsx @@ -56,18 +56,20 @@ class LieferungLieferantenPage extends PureComponent { constructor(props) { super(props); const { prefill } = getInitialParams(props); + const initialSuppliers = sortSuppliers(companyAutomat.state.suppliers ?? []); this.state = { - status: 'loading', - error: null, - suppliers: [], - drafts: {}, + status: companyAutomat.state.suppliersStatus, + error: companyAutomat.state.suppliersError + ? backendErrorFrom(companyAutomat.state.suppliersError) + : null, + suppliers: initialSuppliers, + drafts: draftsFrom(initialSuppliers), newName: prefill, busyKey: null, }; this._cancelled = false; this.handleCreate = this.handleCreate.bind(this); this.handleRetry = this.handleRetry.bind(this); - this.loadSuppliers = this.loadSuppliers.bind(this); } componentDidMount() { @@ -79,7 +81,20 @@ class LieferungLieferantenPage extends PureComponent { this.setState({ newName: prefill }); } this._cancelled = false; - void this.loadSuppliers(); + + this.unsub = companyAutomat.subscribe( + this, + (state) => { + const sorted = sortSuppliers(state.suppliers ?? []); + return { + status: state.suppliersStatus, + error: state.suppliersError ? backendErrorFrom(state.suppliersError) : null, + suppliers: sorted, + drafts: draftsFrom(sorted), + }; + }, + ['suppliers', 'suppliersStatus', 'suppliersError'], + ); } componentDidUpdate(prevProps) { @@ -91,41 +106,13 @@ class LieferungLieferantenPage extends PureComponent { } } - componentWillUnmount() { this._cancelled = true; - } - - applySuppliers(suppliers) { - const sorted = sortSuppliers(suppliers); - this.setState({ - status: 'ready', - error: null, - suppliers: sorted, - drafts: draftsFrom(sorted), - }); - } - - async loadSuppliers() { - this.setState({ status: 'loading', error: null }); - try { - const list = await companyAutomat.actions.loadSuppliers(); - if (this._cancelled) return; - this.applySuppliers(list); - } catch (err) { - if (this._cancelled) return; - this.setState({ status: 'failed', error: backendErrorFrom(err) }); - } + this.unsub?.(); } handleRetry() { - void this.loadSuppliers(); - } - - async refreshFromServer() { - const list = await companyAutomat.actions.reloadSuppliers(); - if (this._cancelled) return; - this.applySuppliers(list); + void companyAutomat.actions.loadSuppliers().catch((err) => notifyError(err)); } async handleCreate() { @@ -142,7 +129,6 @@ class LieferungLieferantenPage extends PureComponent { deliveryDraftAutomat.actions.setDeliveryEntity(newSupplier.id); deliveryDraftAutomat.actions.setUnmatchedSupplierName(null); - await this.refreshFromServer(); if (this._cancelled) return; this.setState({ newName: '', busyKey: null }); enqueueSnackbar(`Lieferant „${newSupplier.name || name}“ angelegt.`, { variant: 'success' }); @@ -157,7 +143,6 @@ class LieferungLieferantenPage extends PureComponent { } } - async handleRename(supplier) { const draft = String(this.state.drafts[supplier.id] ?? '').trim(); if (!draft) { @@ -171,7 +156,6 @@ class LieferungLieferantenPage extends PureComponent { this.setState({ busyKey: supplier.id }); try { await companyAutomat.actions.updateSupplier(supplier.id, { name: draft }); - await this.refreshFromServer(); if (this._cancelled) return; this.setState({ busyKey: null }); enqueueSnackbar('Lieferant gespeichert.', { variant: 'success' }); @@ -194,7 +178,6 @@ class LieferungLieferantenPage extends PureComponent { this.setState({ busyKey: supplier.id }); try { await companyAutomat.actions.removeSupplier(supplier.id); - await this.refreshFromServer(); if (this._cancelled) return; this.setState({ busyKey: null }); enqueueSnackbar('Lieferant gelöscht.', { variant: 'success' }); @@ -211,7 +194,7 @@ class LieferungLieferantenPage extends PureComponent { const { returnTo } = getInitialParams(this.props); - if (status === 'loading') { + if (status === 'loading' || status === 'idle') { return ( diff --git a/src/routes/lieferung/neu.jsx b/src/routes/lieferung/neu.jsx index d9bd0c5..d1a4ead 100644 --- a/src/routes/lieferung/neu.jsx +++ b/src/routes/lieferung/neu.jsx @@ -191,7 +191,6 @@ class LieferungNeuPage extends PureComponent { warehouses: state.warehouses, }; }); - void companyAutomat.actions.loadWarehouses().catch(() => { }); this._cancelled = false; if (this.props.docId != null) { setLastDeliveryPath(`/lieferung/${this.props.docId}`);