This commit is contained in:
seb
2026-10-20 02:56:31 +02:00
parent 067207c58e
commit b727e00928
3 changed files with 204 additions and 185 deletions

View File

@@ -27,6 +27,9 @@ import entityAutomat from '../../automats/entityAutomat';
import customergroupAutomat from '../../automats/customergroupAutomat';
import supplierAutomat from '../../automats/supplierAutomat';
import numberAutomat from '../../automats/numberAutomat';
import quoteAutomat from '../../automats/quoteAutomat';
import orderAutomat from '../../automats/orderAutomat';
import deliveryAutomat from '../../automats/deliveryAutomat';
import { getNextDocumentNumber, ensureDocumentNumber } from '../../utils/documentNumber';
import {
SURFACE_RAISED,
@@ -233,11 +236,30 @@ class ManifestHeader extends PureComponent {
this.props.onPdfUpload?.(file);
}
subscribeListAutomat(kind) {
this.unsubList?.();
this.unsubList = null;
const automat =
kind === 'quote'
? quoteAutomat
: kind === 'order'
? orderAutomat
: kind === 'delivery'
? deliveryAutomat
: null;
if (automat) {
this.unsubList = automat.subscribe(this, () => {
if (!this._cancelled) this.forceUpdate();
});
}
}
componentDidMount() {
this._cancelled = false;
this.unsubNumber = numberAutomat.subscribe(this, () => {
this.forceUpdate();
});
this.subscribeListAutomat(this.props.kind);
void numberAutomat.actions.ensureLoaded().catch(() => {});
if (!this.props.number && this.props.docId == null) {
void ensureDocumentNumber(this.props.kind)
@@ -249,6 +271,9 @@ class ManifestHeader extends PureComponent {
}
componentDidUpdate(prevProps) {
if (prevProps.kind !== this.props.kind) {
this.subscribeListAutomat(this.props.kind);
}
if (
!this.props.number &&
this.props.docId == null &&
@@ -265,6 +290,7 @@ class ManifestHeader extends PureComponent {
componentWillUnmount() {
this._cancelled = true;
this.unsubNumber?.();
this.unsubList?.();
}
render() {