u
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
parseNum,
|
||||
} from './manifestConfig';
|
||||
import { ensureDocumentNumber, getNextDocumentNumber } from '../../utils/documentNumber';
|
||||
import { getManifestDraftAutomat } from '../../automats/manifestDraftAutomat';
|
||||
|
||||
class ManifestForm extends PureComponent {
|
||||
constructor(props) {
|
||||
@@ -42,17 +43,20 @@ class ManifestForm extends PureComponent {
|
||||
? supplierAutomat.state.status === 'ready'
|
||||
: entityAutomat.state.status === 'ready';
|
||||
|
||||
this.draftAutomat = props.mode === 'create' ? getManifestDraftAutomat(props.kind) : null;
|
||||
const initialDraft = this.draftAutomat?.state;
|
||||
|
||||
this.state = {
|
||||
status: props.mode === 'edit' ? 'loading' : (partiesReady ? 'ready' : 'loadingParties'),
|
||||
error: null,
|
||||
parties: initialParties,
|
||||
partiesLoading: !partiesReady,
|
||||
date: '',
|
||||
partyId: null,
|
||||
number: '',
|
||||
externalNumber: '',
|
||||
lines: [emptyLine()],
|
||||
attachments: [],
|
||||
date: initialDraft?.date || '',
|
||||
partyId: initialDraft?.partyId ?? null,
|
||||
number: initialDraft?.number || '',
|
||||
externalNumber: initialDraft?.externalNumber || '',
|
||||
lines: initialDraft?.lines?.length > 0 ? initialDraft.lines : [emptyLine()],
|
||||
attachments: initialDraft?.attachments || [],
|
||||
saving: false,
|
||||
pdfUploading: false,
|
||||
pdfDialogOpen: false,
|
||||
@@ -131,19 +135,48 @@ class ManifestForm extends PureComponent {
|
||||
} else {
|
||||
void this.loadPartiesOnly();
|
||||
}
|
||||
|
||||
if (this.draftAutomat) {
|
||||
this.unsubDraft = this.draftAutomat.subscribe(this, (state) => ({
|
||||
date: state.date || '',
|
||||
partyId: state.partyId,
|
||||
externalNumber: state.externalNumber || '',
|
||||
lines: state.lines?.length > 0 ? state.lines : [emptyLine()],
|
||||
attachments: state.attachments || [],
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
if (
|
||||
this.props.mode === 'edit' &&
|
||||
prevProps.docId !== this.props.docId
|
||||
) {
|
||||
void this.loadEdit();
|
||||
}
|
||||
|
||||
if (this.props.mode === 'create' && this.draftAutomat) {
|
||||
if (
|
||||
prevState.date !== this.state.date ||
|
||||
prevState.partyId !== this.state.partyId ||
|
||||
prevState.externalNumber !== this.state.externalNumber ||
|
||||
prevState.lines !== this.state.lines ||
|
||||
prevState.attachments !== this.state.attachments
|
||||
) {
|
||||
this.draftAutomat.setState({
|
||||
date: this.state.date,
|
||||
partyId: this.state.partyId,
|
||||
externalNumber: this.state.externalNumber,
|
||||
lines: this.state.lines,
|
||||
attachments: this.state.attachments,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this._cancelled = true;
|
||||
this.unsubDraft?.();
|
||||
this.unsubParties?.();
|
||||
this.unsubCompany?.();
|
||||
if (this._parseAbortController) {
|
||||
@@ -687,6 +720,7 @@ class ManifestForm extends PureComponent {
|
||||
requireObject(data, cfg.postPathLabel);
|
||||
requireObject(data[cfg.docField], cfg.docField);
|
||||
requireDefined(data[cfg.docField].id, `${cfg.docField}.id`);
|
||||
this.draftAutomat?.actions?.reset();
|
||||
await cfg.listAutomat.actions.reload();
|
||||
if (this._cancelled) return;
|
||||
enqueueSnackbar(cfg.createdMsg, { variant: 'success' });
|
||||
|
||||
Reference in New Issue
Block a user