u
This commit is contained in:
@@ -14,6 +14,7 @@ import { backendErrorFrom } from '../utils/backendError';
|
||||
import { notifyError } from '../utils/notify';
|
||||
import entityAutomat from '../automats/entityAutomat';
|
||||
import customergroupAutomat from '../automats/customergroupAutomat';
|
||||
import { getLowestSortNonSupplierCustomerGroup } from '../components/manifest/manifestConfig';
|
||||
import { Kunde } from '../components/kunde';
|
||||
import { BLUE_PANEL } from '../colors';
|
||||
|
||||
@@ -70,7 +71,7 @@ class KundeSearchField extends PureComponent {
|
||||
try {
|
||||
await customergroupAutomat.actions.ensureLoaded();
|
||||
const groups = customergroupAutomat.state.items ?? [];
|
||||
const defaultGroup = groups.find((g) => g.editable !== false) ?? groups[0];
|
||||
const defaultGroup = getLowestSortNonSupplierCustomerGroup(groups) ?? groups[0];
|
||||
if (!defaultGroup) {
|
||||
throw new Error('Keine Kundengruppe vorhanden.');
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { PanelTile, PanelTileGrid } from 'dashgui/panels';
|
||||
import { entity as entityApi } from '../../api';
|
||||
import entityAutomat from '../../automats/entityAutomat';
|
||||
import customergroupAutomat from '../../automats/customergroupAutomat';
|
||||
import { getLowestSortNonSupplierCustomerGroup } from '../../components/manifest/manifestConfig';
|
||||
import { router } from '../../appRouter';
|
||||
import { requireDefined, requireObject } from '../../utils/apiShape';
|
||||
import { notifyError } from '../../utils/notify';
|
||||
@@ -45,9 +46,10 @@ class KundeNeuPage extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const groups = customergroupAutomat.state.items ?? [];
|
||||
const defaultGroup = getLowestSortNonSupplierCustomerGroup(groups) ?? groups[0];
|
||||
const prefill = getInitialPrefill(props);
|
||||
this.state = {
|
||||
customergroupId: groups.length > 0 ? groups[0].id : null,
|
||||
customergroupId: defaultGroup ? defaultGroup.id : null,
|
||||
number: '',
|
||||
name: prefill.name,
|
||||
firstName: prefill.firstName,
|
||||
@@ -59,6 +61,14 @@ class KundeNeuPage extends PureComponent {
|
||||
|
||||
componentDidMount() {
|
||||
void this.loadNumber();
|
||||
if (this.state.customergroupId == null) {
|
||||
void customergroupAutomat.actions.ensureLoaded().then((groups) => {
|
||||
const defaultGroup = getLowestSortNonSupplierCustomerGroup(groups) ?? groups?.[0];
|
||||
if (defaultGroup && this.state.customergroupId == null) {
|
||||
this.setState({ customergroupId: defaultGroup.id });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async loadNumber() {
|
||||
|
||||
@@ -37,7 +37,8 @@ import {
|
||||
ArticleSearchDialog,
|
||||
BookDeliveryDialog,
|
||||
} from '../../components/manifest';
|
||||
import { loadParties, apiFor, resolveLineSkus } from '../../components/manifest/manifestConfig';
|
||||
import { loadParties, apiFor, resolveLineSkus, sortSuppliers } from '../../components/manifest/manifestConfig';
|
||||
import supplierAutomat from '../../automats/supplierAutomat';
|
||||
import warehouseAutomat from '../../automats/warehouseAutomat';
|
||||
import { article as articleApi, delivery as deliveryApi } from '../../api';
|
||||
import { getCategoryState } from '../../automats/categoryAutomat';
|
||||
@@ -108,6 +109,12 @@ class LieferungNeuPage extends PureComponent {
|
||||
super(props);
|
||||
this.cfg = manifestConfig('delivery');
|
||||
this.automat = getDeliveryEditorAutomat(props.docId);
|
||||
if (
|
||||
supplierAutomat.state.status === 'ready' &&
|
||||
(!this.automat.state.deliveryEntities || this.automat.state.deliveryEntities.length === 0)
|
||||
) {
|
||||
this.automat.actions.setDeliveryEntities(sortSuppliers(supplierAutomat.state.suppliers));
|
||||
}
|
||||
const initialDate = this.automat.state.date || (props.docId == null ? todayInputValue() : null);
|
||||
if (props.docId == null && !this.automat.state.date) {
|
||||
this.automat.actions.setDate(initialDate);
|
||||
@@ -181,6 +188,11 @@ class LieferungNeuPage extends PureComponent {
|
||||
this._warehouseUnsub = warehouseAutomat.subscribe(this, (state) => ({
|
||||
warehouses: state.warehouses,
|
||||
}));
|
||||
this._supplierUnsub = supplierAutomat.subscribe(this, (state) => {
|
||||
if (state.status === 'ready' && Array.isArray(state.suppliers)) {
|
||||
this.automat.actions.setDeliveryEntities(sortSuppliers(state.suppliers));
|
||||
}
|
||||
});
|
||||
void warehouseAutomat.actions.load().catch(() => { });
|
||||
this._cancelled = false;
|
||||
if (this.props.docId != null) {
|
||||
@@ -225,6 +237,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
this.unsubscribe?.();
|
||||
this._settingsUnsub?.();
|
||||
this._warehouseUnsub?.();
|
||||
this._supplierUnsub?.();
|
||||
}
|
||||
|
||||
async loadPartiesOnly() {
|
||||
|
||||
Reference in New Issue
Block a user