u
This commit is contained in:
@@ -11,6 +11,8 @@ import Alert from '@mui/material/Alert';
|
||||
import CloseIcon from '@mui/icons-material/Close';
|
||||
import ArticleSearch from '../article/ArticleSearch';
|
||||
|
||||
import deliveryEditorAutomat from '../../automats/deliveryEditorAutomat';
|
||||
|
||||
export default class ArticleSearchDialog extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -26,6 +28,11 @@ export default class ArticleSearchDialog extends PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
handleClose = () => {
|
||||
this.setState({ assigningSku: null, error: null });
|
||||
this.props.onClose?.();
|
||||
};
|
||||
|
||||
handleSelect = async (article) => {
|
||||
const { onAssign, line, kind = 'delivery' } = this.props;
|
||||
const isDelivery = kind === 'delivery';
|
||||
@@ -41,26 +48,51 @@ export default class ArticleSearchDialog extends PureComponent {
|
||||
await onAssign(article, line);
|
||||
} catch (err) {
|
||||
this.setState({
|
||||
assigningSku: null,
|
||||
error:
|
||||
err?.message ||
|
||||
(isDelivery
|
||||
? 'Fehler beim Verknüpfen des Lieferanten-Artikels.'
|
||||
? (line ? 'Fehler beim Verknüpfen des Lieferanten-Artikels.' : 'Fehler beim Hinzufügen des Artikels.')
|
||||
: 'Fehler beim Zuordnen des Artikels.'),
|
||||
});
|
||||
} finally {
|
||||
this.setState({ assigningSku: null });
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { open, onClose, line, kind = 'delivery' } = this.props;
|
||||
const { open, onClose, line, kind = 'delivery', supplierArticles: propSupplierArticles } = this.props;
|
||||
const { assigningSku, error } = this.state;
|
||||
const isDelivery = kind === 'delivery';
|
||||
const onlySupplierArticles = isDelivery && !line;
|
||||
const rawSku = line?.sku != null ? String(line.sku).trim() : '';
|
||||
|
||||
const supplierArticlesList = onlySupplierArticles
|
||||
? (propSupplierArticles ?? deliveryEditorAutomat.state.supplierArticles ?? [])
|
||||
: null;
|
||||
|
||||
const includeSkus = onlySupplierArticles
|
||||
? supplierArticlesList.map((sa) => sa.article?.sku || sa.sku).filter(Boolean)
|
||||
: null;
|
||||
|
||||
const extraArticles = onlySupplierArticles
|
||||
? supplierArticlesList.map((sa) => ({
|
||||
id: sa.article?.id ?? sa.id,
|
||||
sku: sa.article?.sku || sa.sku,
|
||||
name: sa.article?.name || sa.name || sa.sku || '',
|
||||
brand: sa.article?.brand,
|
||||
brandName: sa.article?.brand?.name || sa.article?.brandName,
|
||||
stock: sa.article?.stock ?? sa.stock,
|
||||
available: sa.article?.available,
|
||||
price: sa.price?.net ?? sa.article?.price ?? sa.article?.vknetto,
|
||||
eans: sa.article?.eans || [sa.sku].filter(Boolean),
|
||||
isParent: false,
|
||||
}))
|
||||
: [];
|
||||
|
||||
return (
|
||||
<AppDialog
|
||||
open={Boolean(open)}
|
||||
onClose={assigningSku ? undefined : onClose}
|
||||
onClose={this.handleClose}
|
||||
maxWidth="md"
|
||||
fullWidth
|
||||
aria-labelledby="article-search-dialog-title"
|
||||
@@ -89,18 +121,29 @@ export default class ArticleSearchDialog extends PureComponent {
|
||||
>
|
||||
<Box>
|
||||
<Typography variant="h6" component="div" fontWeight={600}>
|
||||
{line ? 'Existierenden Artikel zuordnen' : 'Artikel auswählen'}
|
||||
{line
|
||||
? 'Existierenden Artikel zuordnen'
|
||||
: isDelivery
|
||||
? 'Lieferanten-Artikel auswählen'
|
||||
: 'Artikel auswählen'}
|
||||
</Typography>
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
{isDelivery ? 'Lieferanten-SKU' : 'SKU'}: <strong>{rawSku || '–'}</strong>
|
||||
{line?.name ? ` · ${line.name}` : ''}
|
||||
{line ? (
|
||||
<>
|
||||
{isDelivery ? 'Lieferanten-SKU' : 'SKU'}: <strong>{rawSku || '–'}</strong>
|
||||
{line?.name ? ` · ${line.name}` : ''}
|
||||
</>
|
||||
) : isDelivery ? (
|
||||
'Nur mit dem ausgewählten Lieferanten verknüpfte Artikel'
|
||||
) : (
|
||||
'Artikel für Beleg auswählen'
|
||||
)}
|
||||
</Typography>
|
||||
</Box>
|
||||
<IconButton
|
||||
size="small"
|
||||
aria-label="Schließen"
|
||||
disabled={Boolean(assigningSku)}
|
||||
onClick={onClose}
|
||||
onClick={this.handleClose}
|
||||
>
|
||||
<CloseIcon fontSize="small" />
|
||||
</IconButton>
|
||||
@@ -123,12 +166,21 @@ export default class ArticleSearchDialog extends PureComponent {
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{onlySupplierArticles && supplierArticlesList.length === 0 && (
|
||||
<Alert severity="info" sx={{ mb: 2, flexShrink: 0 }}>
|
||||
Für diesen Lieferanten sind noch keine Artikel verknüpft.
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<ArticleSearch
|
||||
mode="list"
|
||||
autoFocus
|
||||
allowParent={false}
|
||||
busySku={assigningSku}
|
||||
actionLabel={assigningSku ? 'Zuordnen…' : 'Zuordnen'}
|
||||
initialQuery={line?.name ? String(line.name) : ''}
|
||||
includeSkus={includeSkus}
|
||||
extraArticles={extraArticles}
|
||||
actionLabel={assigningSku ? (line ? 'Zuordnen…' : 'Hinzufügen…') : (line ? 'Zuordnen' : 'Hinzufügen')}
|
||||
onSelect={this.handleSelect}
|
||||
/>
|
||||
</DialogContent>
|
||||
@@ -136,8 +188,7 @@ export default class ArticleSearchDialog extends PureComponent {
|
||||
<DialogActions sx={{ px: 2, py: 1.5 }}>
|
||||
<Button
|
||||
size="small"
|
||||
disabled={Boolean(assigningSku)}
|
||||
onClick={onClose}
|
||||
onClick={this.handleClose}
|
||||
>
|
||||
Abbrechen
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user