This commit is contained in:
seb
2026-10-04 21:04:40 +02:00
parent 669954b496
commit f765b87336
59 changed files with 1491 additions and 2045 deletions

View File

@@ -6,7 +6,9 @@ import Typography from '@mui/material/Typography';
import { EditablePanelTile, PanelTile } from 'dashgui/panels';
import ArticlePriceTiersDialog from '../ArticlePriceTiersDialog';
import ArticleUnitEditorDialog from '../ArticleUnitEditorDialog';
import { StorageManagerContext } from '../../../api/storageManagerContext';
import unitAutomat from '../../../automats/unitAutomat';
import companyAutomat from '../../../automats/companyAutomat';
import artikelAutomat from '../../../automats/artikelAutomat';
import { requireDefined, requireObject } from '../../../utils/apiShape';
import {
buildPosPricesPutBody,
@@ -169,9 +171,8 @@ function priceDraftValid(draft) {
return true;
}
function companyFromStore(store) {
if (!store) return null;
return store.company ?? null;
function companyFromStore() {
return companyAutomat.state.current ?? null;
}
class PriceAmountField extends Component {
@@ -361,13 +362,10 @@ class PriceEdit extends Component {
}
export default class ArticleViewPrice extends PureComponent {
static contextType = StorageManagerContext;
constructor(props) {
super(props);
const store = this.context;
const company = companyFromStore(store);
const units = store?.units;
const company = companyFromStore();
const units = unitAutomat.state.units;
this.state = {
tiersDialogOpen: false,
unitEditorOpen: false,
@@ -375,37 +373,28 @@ export default class ArticleViewPrice extends PureComponent {
company,
};
this._cancelled = false;
this._ready = company != null && units != null;
}
componentDidMount() {
this._cancelled = false;
if (this._ready) return;
void this.load();
this.unsubUnits = unitAutomat.subscribe(this, (state) => ({
units: state.units ?? [],
}));
this.unsubCompany = companyAutomat.subscribe(this, (state) => ({
company: state.current ?? null,
}));
}
componentWillUnmount() {
this._cancelled = true;
}
async load() {
const store = this.context;
try {
const [unitList, company] = await Promise.all([
store.unitPromise,
store.companyPromise,
]);
if (!this._cancelled) {
this.setState({ units: unitList, company: company ?? null });
}
} catch (err) {
if (!this._cancelled) notifyError(err);
}
this.unsubUnits?.();
this.unsubUnits = null;
this.unsubCompany?.();
this.unsubCompany = null;
}
handleSave = async (draft) => {
const { article: articleData, onArticleUpdated } = this.props;
const store = this.context;
const { company } = this.state;
const saved = priceDraftValue(articleData, company);
let nextArticle = articleData;
@@ -426,12 +415,12 @@ export default class ArticleViewPrice extends PureComponent {
if (isNoPackUnit(unitSi, unitamount)) {
throw new Error('Einheit pc × 1 ist keine Packungseinheit');
}
const res = await store.article.update(articleData.sku, { unitamount, unitSi });
const res = await artikelAutomat.actions.update(articleData.sku, { unitamount, unitSi });
requireObject(res, 'PATCH /api/article/:sku');
requireObject(res.article, 'article');
nextArticle = res.article;
} else {
const res = await store.article.update(articleData.sku, {
const res = await artikelAutomat.actions.update(articleData.sku, {
unitamount: 1,
unitSi: 'pc',
});
@@ -456,7 +445,7 @@ export default class ArticleViewPrice extends PureComponent {
taxRate,
tiers: draft.tiers ?? [],
});
const res = await store.article.setPrices(articleData.sku, { prices });
const res = await artikelAutomat.actions.setPrices(articleData.sku, prices);
requireObject(res, 'PUT /api/article/:sku/prices');
requireObject(res.article, 'article');
nextArticle = res.article;
@@ -480,7 +469,8 @@ export default class ArticleViewPrice extends PureComponent {
}
refreshUnits = async () => {
this.setState({ units: await this.context.unitPromise });
const units = await unitAutomat.actions.load();
this.setState({ units });
};
render() {