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,
|
emptyLine,
|
||||||
lineFromApi,
|
lineFromApi,
|
||||||
buildManifestBody,
|
buildManifestBody,
|
||||||
|
dateInputValue,
|
||||||
} from './manifestConfig';
|
} from './manifestConfig';
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
import { PureComponent } from 'react';
|
import { withManifestId } from '../../components/manifest';
|
||||||
import { ManifestForm, withManifestId } from '../../components/manifest';
|
import LieferungNeuPage from './neu';
|
||||||
|
|
||||||
class LieferungEditPage extends PureComponent {
|
export default withManifestId('deliveryId', LieferungNeuPage);
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<ManifestForm
|
|
||||||
kind="delivery"
|
|
||||||
mode="edit"
|
|
||||||
docId={this.props.docId}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default withManifestId('deliveryId', LieferungEditPage);
|
|
||||||
|
|||||||
@@ -14,12 +14,15 @@ import {
|
|||||||
ManifestLines,
|
ManifestLines,
|
||||||
DELIVERY_LINE_COLUMNS,
|
DELIVERY_LINE_COLUMNS,
|
||||||
buildManifestBody,
|
buildManifestBody,
|
||||||
|
dateInputValue,
|
||||||
|
emptyLine,
|
||||||
|
lineFromApi,
|
||||||
manifestConfig,
|
manifestConfig,
|
||||||
} from '../../components/manifest';
|
} from '../../components/manifest';
|
||||||
import ManifestPdfDialog from '../../components/manifest/ManifestPdfDialog';
|
import ManifestPdfDialog from '../../components/manifest/ManifestPdfDialog';
|
||||||
import { loadParties } from '../../components/manifest/manifestConfig';
|
import { loadParties } from '../../components/manifest/manifestConfig';
|
||||||
import { StorageManagerContext } from '../../api/storageManagerContext';
|
import { StorageManagerContext } from '../../api/storageManagerContext';
|
||||||
import { requireDefined, requireObject } from '../../utils/apiShape';
|
import { requireArray, requireDefined, requireObject } from '../../utils/apiShape';
|
||||||
import { backendErrorFrom } from '../../utils/backendError';
|
import { backendErrorFrom } from '../../utils/backendError';
|
||||||
import { notifyError } from '../../utils/notify';
|
import { notifyError } from '../../utils/notify';
|
||||||
import {
|
import {
|
||||||
@@ -76,7 +79,22 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this._cancelled = false;
|
this._cancelled = false;
|
||||||
void this.loadPartiesOnly();
|
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() {
|
componentWillUnmount() {
|
||||||
@@ -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() {
|
handleRetry() {
|
||||||
void this.loadPartiesOnly();
|
if (this.props.docId != null) void this.loadEdit();
|
||||||
|
else void this.loadPartiesOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePartyChange(partyId) {
|
handlePartyChange(partyId) {
|
||||||
@@ -290,9 +357,11 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleSave() {
|
async handleSave() {
|
||||||
|
const { docId } = this.props;
|
||||||
const cfg = this.cfg;
|
const cfg = this.cfg;
|
||||||
if (this.state.saving) return;
|
if (this.state.saving) return;
|
||||||
|
|
||||||
|
const isCreate = docId == null;
|
||||||
let body;
|
let body;
|
||||||
try {
|
try {
|
||||||
body = buildManifestBody(
|
body = buildManifestBody(
|
||||||
@@ -305,7 +374,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
partyField: cfg.partyField,
|
partyField: cfg.partyField,
|
||||||
requireAtLeastOne: true,
|
requireAtLeastOne: isCreate,
|
||||||
externalNumber: cfg.externalNumber,
|
externalNumber: cfg.externalNumber,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -316,15 +385,36 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
|
|
||||||
this.setState({ saving: true });
|
this.setState({ saving: true });
|
||||||
try {
|
try {
|
||||||
const data = await this.context[cfg.api].create(body);
|
if (isCreate) {
|
||||||
requireObject(data, cfg.postPathLabel);
|
const data = await this.context[cfg.api].create(body);
|
||||||
requireObject(data[cfg.docField], cfg.docField);
|
requireObject(data, cfg.postPathLabel);
|
||||||
requireDefined(data[cfg.docField].id, `${cfg.docField}.id`);
|
requireObject(data[cfg.docField], cfg.docField);
|
||||||
await this.context[cfg.updateCache]();
|
requireDefined(data[cfg.docField].id, `${cfg.docField}.id`);
|
||||||
if (this._cancelled) return;
|
await this.context[cfg.updateCache]();
|
||||||
enqueueSnackbar(cfg.createdMsg, { variant: 'success' });
|
if (this._cancelled) return;
|
||||||
this.props.resetDelivery();
|
enqueueSnackbar(cfg.createdMsg, { variant: 'success' });
|
||||||
this.props.navigate(cfg.editPath(data[cfg.docField].id));
|
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) {
|
} catch (err) {
|
||||||
if (this._cancelled) return;
|
if (this._cancelled) return;
|
||||||
notifyError(err);
|
notifyError(err);
|
||||||
@@ -354,7 +444,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
notes,
|
notes,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (status === 'loadingParties') {
|
if (status === 'loadingParties' || status === 'loading') {
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: 'flex', justifyContent: 'center', py: 6 }}>
|
<Box sx={{ display: 'flex', justifyContent: 'center', py: 6 }}>
|
||||||
<CircularProgress />
|
<CircularProgress />
|
||||||
|
|||||||
Reference in New Issue
Block a user