This commit is contained in:
seb
2026-10-13 22:05:30 +02:00
parent bc583a180f
commit bf7ff349f3
14 changed files with 82 additions and 47 deletions

View File

@@ -14,6 +14,8 @@ import ManifestLines from './ManifestLines';
import ManifestPdfDialog from './ManifestPdfDialog';
import ArticleSearchDialog from './ArticleSearchDialog';
import artikelAutomat, { getArticle } from '../../automats/artikelAutomat';
import entityAutomat from '../../automats/entityAutomat';
import supplierAutomat from '../../automats/supplierAutomat';
import { netFromGross, getArticleGross } from '../../utils/price';
import {
buildManifestBody,
@@ -31,11 +33,18 @@ class ManifestForm extends PureComponent {
constructor(props) {
super(props);
this.cfg = manifestConfig(props.kind);
const initialParties = props.kind === 'delivery'
? (supplierAutomat.state.status === 'ready' ? (supplierAutomat.state.suppliers ?? []) : [])
: (entityAutomat.state.status === 'ready' ? (entityAutomat.state.items ?? []) : []);
const partiesReady = props.kind === 'delivery'
? supplierAutomat.state.status === 'ready'
: entityAutomat.state.status === 'ready';
this.state = {
status: props.mode === 'edit' ? 'loading' : 'loadingParties',
status: props.mode === 'edit' ? 'loading' : (partiesReady ? 'ready' : 'loadingParties'),
error: null,
parties: [],
partiesLoading: true,
parties: initialParties,
partiesLoading: !partiesReady,
date: '',
partyId: null,
number: '',
@@ -74,6 +83,18 @@ class ManifestForm extends PureComponent {
componentDidMount() {
this._cancelled = false;
if (this.props.kind === 'delivery') {
this.unsubParties = supplierAutomat.subscribe(this, (state) => ({
parties: state.status === 'ready' ? (state.suppliers ?? []) : [],
partiesLoading: state.status === 'loading',
}));
} else {
this.unsubParties = entityAutomat.subscribe(this, (state) => ({
parties: state.items ?? [],
partiesLoading: state.status === 'loading',
}));
}
if (this.props.mode === 'edit') void this.loadEdit();
else void this.loadPartiesOnly();
}
@@ -89,6 +110,7 @@ class ManifestForm extends PureComponent {
componentWillUnmount() {
this._cancelled = true;
this.unsubParties?.();
if (this._parseAbortController) {
this._parseAbortController.abort();
this._parseAbortController = null;
@@ -96,7 +118,9 @@ class ManifestForm extends PureComponent {
}
async loadPartiesOnly() {
this.setState({ status: 'loadingParties', error: null, partiesLoading: true });
if (this.state.parties.length === 0) {
this.setState({ status: 'loadingParties', error: null, partiesLoading: true });
}
try {
const parties = await loadParties(this.props.kind);
if (this._cancelled) return;
@@ -107,11 +131,13 @@ class ManifestForm extends PureComponent {
});
} catch (err) {
if (this._cancelled) return;
this.setState({
status: 'failed',
error: backendErrorFrom(err),
partiesLoading: false,
});
if (this.state.parties.length === 0) {
this.setState({
status: 'failed',
error: backendErrorFrom(err),
partiesLoading: false,
});
}
notifyError(err);
}
}