u
This commit is contained in:
1
README.quick
Normal file
1
README.quick
Normal file
@@ -0,0 +1 @@
|
||||
src/appRouter.jsx
|
||||
@@ -11,4 +11,5 @@ export {
|
||||
emptyLine,
|
||||
lineFromApi,
|
||||
buildManifestBody,
|
||||
dateInputValue,
|
||||
} from './manifestConfig';
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
import { PureComponent } from 'react';
|
||||
import { ManifestForm, withManifestId } from '../../components/manifest';
|
||||
import { withManifestId } from '../../components/manifest';
|
||||
import LieferungNeuPage from './neu';
|
||||
|
||||
class LieferungEditPage extends PureComponent {
|
||||
render() {
|
||||
return (
|
||||
<ManifestForm
|
||||
kind="delivery"
|
||||
mode="edit"
|
||||
docId={this.props.docId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withManifestId('deliveryId', LieferungEditPage);
|
||||
export default withManifestId('deliveryId', LieferungNeuPage);
|
||||
|
||||
@@ -14,12 +14,15 @@ import {
|
||||
ManifestLines,
|
||||
DELIVERY_LINE_COLUMNS,
|
||||
buildManifestBody,
|
||||
dateInputValue,
|
||||
emptyLine,
|
||||
lineFromApi,
|
||||
manifestConfig,
|
||||
} from '../../components/manifest';
|
||||
import ManifestPdfDialog from '../../components/manifest/ManifestPdfDialog';
|
||||
import { loadParties } from '../../components/manifest/manifestConfig';
|
||||
import { StorageManagerContext } from '../../api/storageManagerContext';
|
||||
import { requireDefined, requireObject } from '../../utils/apiShape';
|
||||
import { requireArray, requireDefined, requireObject } from '../../utils/apiShape';
|
||||
import { backendErrorFrom } from '../../utils/backendError';
|
||||
import { notifyError } from '../../utils/notify';
|
||||
import {
|
||||
@@ -76,8 +79,23 @@ class LieferungNeuPage extends PureComponent {
|
||||
|
||||
componentDidMount() {
|
||||
this._cancelled = false;
|
||||
if (this.props.docId != null) {
|
||||
void this.loadEdit();
|
||||
} else {
|
||||
void this.loadPartiesOnly();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.docId !== prevProps.docId) {
|
||||
if (this.props.docId != null) {
|
||||
void this.loadEdit();
|
||||
} else {
|
||||
this.props.resetDelivery();
|
||||
void this.loadPartiesOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this._cancelled = true;
|
||||
@@ -104,8 +122,57 @@ class LieferungNeuPage extends PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
async loadEdit() {
|
||||
const { docId } = this.props;
|
||||
const cfg = this.cfg;
|
||||
if (docId == null) {
|
||||
this.setState({
|
||||
status: 'failed',
|
||||
error: backendErrorFrom(new Error(cfg.invalidId)),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ status: 'loading', error: null, partiesLoading: true });
|
||||
try {
|
||||
const [docRes, parties] = await Promise.all([
|
||||
this.context[cfg.api].get(docId),
|
||||
loadParties('delivery', this.context),
|
||||
]);
|
||||
if (this._cancelled) return;
|
||||
|
||||
this.props.setDeliveryEntities(parties);
|
||||
|
||||
requireObject(docRes, cfg.getPathLabel);
|
||||
requireObject(docRes[cfg.docField], cfg.docField);
|
||||
const doc = docRes[cfg.docField];
|
||||
const apiLines = requireArray(doc.lines, `${cfg.docField}.lines`);
|
||||
const lines =
|
||||
apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()];
|
||||
|
||||
this.props.setDate(dateInputValue(doc.date));
|
||||
if (doc[cfg.partyField] != null) this.props.setDeliveryEntity(doc[cfg.partyField]);
|
||||
if (doc.number != null) this.props.setNumber(doc.number);
|
||||
if (doc.externalNumber != null) this.props.setExternalNumber(String(doc.externalNumber));
|
||||
this.props.setLineitems(lines);
|
||||
|
||||
this.setState({
|
||||
status: 'ready',
|
||||
partiesLoading: false,
|
||||
});
|
||||
} catch (err) {
|
||||
if (this._cancelled) return;
|
||||
this.setState({
|
||||
status: 'failed',
|
||||
error: backendErrorFrom(err),
|
||||
partiesLoading: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
handleRetry() {
|
||||
void this.loadPartiesOnly();
|
||||
if (this.props.docId != null) void this.loadEdit();
|
||||
else void this.loadPartiesOnly();
|
||||
}
|
||||
|
||||
handlePartyChange(partyId) {
|
||||
@@ -290,9 +357,11 @@ class LieferungNeuPage extends PureComponent {
|
||||
}
|
||||
|
||||
async handleSave() {
|
||||
const { docId } = this.props;
|
||||
const cfg = this.cfg;
|
||||
if (this.state.saving) return;
|
||||
|
||||
const isCreate = docId == null;
|
||||
let body;
|
||||
try {
|
||||
body = buildManifestBody(
|
||||
@@ -305,7 +374,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
},
|
||||
{
|
||||
partyField: cfg.partyField,
|
||||
requireAtLeastOne: true,
|
||||
requireAtLeastOne: isCreate,
|
||||
externalNumber: cfg.externalNumber,
|
||||
},
|
||||
);
|
||||
@@ -316,6 +385,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
|
||||
this.setState({ saving: true });
|
||||
try {
|
||||
if (isCreate) {
|
||||
const data = await this.context[cfg.api].create(body);
|
||||
requireObject(data, cfg.postPathLabel);
|
||||
requireObject(data[cfg.docField], cfg.docField);
|
||||
@@ -325,6 +395,26 @@ class LieferungNeuPage extends PureComponent {
|
||||
enqueueSnackbar(cfg.createdMsg, { variant: 'success' });
|
||||
this.props.resetDelivery();
|
||||
this.props.navigate(cfg.editPath(data[cfg.docField].id));
|
||||
} else {
|
||||
const data = await this.context[cfg.api].update(docId, body);
|
||||
requireObject(data, cfg.patchPathLabel);
|
||||
requireObject(data[cfg.docField], cfg.docField);
|
||||
requireDefined(data[cfg.docField].id, `${cfg.docField}.id`);
|
||||
await this.context[cfg.updateCache]();
|
||||
if (this._cancelled) return;
|
||||
const doc = data[cfg.docField];
|
||||
const apiLines = requireArray(doc.lines, `${cfg.docField}.lines`);
|
||||
const lines = apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()];
|
||||
|
||||
this.props.setDate(dateInputValue(doc.date));
|
||||
if (doc[cfg.partyField] != null) this.props.setDeliveryEntity(doc[cfg.partyField]);
|
||||
if (doc.number != null) this.props.setNumber(doc.number);
|
||||
if (doc.externalNumber != null) this.props.setExternalNumber(String(doc.externalNumber));
|
||||
this.props.setLineitems(lines);
|
||||
|
||||
enqueueSnackbar(cfg.savedMsg, { variant: 'success' });
|
||||
this.setState({ saving: false });
|
||||
}
|
||||
} catch (err) {
|
||||
if (this._cancelled) return;
|
||||
notifyError(err);
|
||||
@@ -354,7 +444,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
notes,
|
||||
} = this.props;
|
||||
|
||||
if (status === 'loadingParties') {
|
||||
if (status === 'loadingParties' || status === 'loading') {
|
||||
return (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', py: 6 }}>
|
||||
<CircularProgress />
|
||||
|
||||
Reference in New Issue
Block a user