supplierAutomat
This commit is contained in:
@@ -16,11 +16,10 @@ import BackendError from '../../components/BackendError';
|
||||
import SingleLineTextEdit from 'dashgui/SingleLineTextEdit';
|
||||
import { PanelTile, PanelTileGrid } from 'dashgui/panels';
|
||||
import withNavigate from '../../components/withNavigate';
|
||||
import { StorageManagerContext } from '../../api/storageManagerContext';
|
||||
import { requireDefined, requireObject } from '../../utils/apiShape';
|
||||
import { backendErrorFrom } from '../../utils/backendError';
|
||||
import { notifyError } from '../../utils/notify';
|
||||
import { setLastDeliveryPath } from '../../automats';
|
||||
import supplierAutomat from '../../automats/supplierAutomat';
|
||||
import { deliveryDraftAutomat } from '../../automats/deliveryEditorAutomat';
|
||||
|
||||
|
||||
@@ -51,8 +50,6 @@ function getInitialParams(props) {
|
||||
}
|
||||
|
||||
class LieferungLieferantenPage extends PureComponent {
|
||||
static contextType = StorageManagerContext;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const { prefill } = getInitialParams(props);
|
||||
@@ -109,7 +106,7 @@ class LieferungLieferantenPage extends PureComponent {
|
||||
async loadSuppliers() {
|
||||
this.setState({ status: 'loading', error: null });
|
||||
try {
|
||||
const list = this.context.suppliers ?? (await this.context.supplierPromise);
|
||||
const list = await supplierAutomat.actions.load();
|
||||
if (this._cancelled) return;
|
||||
this.applySuppliers(list);
|
||||
} catch (err) {
|
||||
@@ -123,7 +120,7 @@ class LieferungLieferantenPage extends PureComponent {
|
||||
}
|
||||
|
||||
async refreshFromServer() {
|
||||
const list = await this.context.updateSupplier();
|
||||
const list = await supplierAutomat.actions.reload();
|
||||
if (this._cancelled) return;
|
||||
this.applySuppliers(list);
|
||||
}
|
||||
@@ -136,11 +133,7 @@ class LieferungLieferantenPage extends PureComponent {
|
||||
|
||||
this.setState({ busyKey: 'new' });
|
||||
try {
|
||||
const data = await this.context.supplier.create({ name });
|
||||
requireObject(data, 'POST /api/supplier');
|
||||
requireObject(data.supplier, 'supplier');
|
||||
requireDefined(data.supplier.id, 'supplier.id');
|
||||
const newSupplier = data.supplier;
|
||||
const newSupplier = await supplierAutomat.actions.create({ name });
|
||||
|
||||
// Assign the new supplier to the active delivery draft & clear unmatched name
|
||||
deliveryDraftAutomat.actions.setDeliveryEntity(newSupplier.id);
|
||||
@@ -174,10 +167,7 @@ class LieferungLieferantenPage extends PureComponent {
|
||||
|
||||
this.setState({ busyKey: supplier.id });
|
||||
try {
|
||||
const data = await this.context.supplier.update(supplier.id, { name: draft });
|
||||
requireObject(data, 'PATCH /api/supplier/:id');
|
||||
requireObject(data.supplier, 'supplier');
|
||||
requireDefined(data.supplier.id, 'supplier.id');
|
||||
await supplierAutomat.actions.update(supplier.id, { name: draft });
|
||||
await this.refreshFromServer();
|
||||
if (this._cancelled) return;
|
||||
this.setState({ busyKey: null });
|
||||
@@ -200,7 +190,7 @@ class LieferungLieferantenPage extends PureComponent {
|
||||
|
||||
this.setState({ busyKey: supplier.id });
|
||||
try {
|
||||
await this.context.supplier.delete(supplier.id);
|
||||
await supplierAutomat.actions.remove(supplier.id);
|
||||
await this.refreshFromServer();
|
||||
if (this._cancelled) return;
|
||||
this.setState({ busyKey: null });
|
||||
|
||||
Reference in New Issue
Block a user