This commit is contained in:
seb
2026-10-28 00:41:31 +01:00
parent 23e4a0951c
commit 0453680c59
14 changed files with 47 additions and 83 deletions

View File

@@ -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;

View File

@@ -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. */

View File

@@ -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);

View File

@@ -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') {

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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,

View File

@@ -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 });

View File

@@ -104,7 +104,6 @@ class ArtikelKategorienPage extends PureComponent {
companyId: s.current?.id ?? null,
}));
this.ensureTreeLoaded();
this.ensurePosterminalsLoaded();
this.subscribeViewHandle();
this.syncSortable();
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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 (
<Box sx={{ display: 'flex', justifyContent: 'center', py: 6 }}>
<CircularProgress />

View File

@@ -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}`);