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

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