From 78994730d1ba1fa4dc50ff7fb9fd7cc01b4bc111 Mon Sep 17 00:00:00 2001 From: seb Date: Sat, 10 Oct 2026 22:58:46 +0200 Subject: [PATCH] u --- src/routes/artikel/marken.jsx | 60 +++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/routes/artikel/marken.jsx b/src/routes/artikel/marken.jsx index 7a0f5fa..188f3a6 100644 --- a/src/routes/artikel/marken.jsx +++ b/src/routes/artikel/marken.jsx @@ -1,12 +1,8 @@ import { PureComponent, createRef } from 'react'; import Box from '@mui/material/Box'; -import TextField from '@mui/material/TextField'; -import InputAdornment from '@mui/material/InputAdornment'; +import Button from '@mui/material/Button'; import CircularProgress from '@mui/material/CircularProgress'; import BackendError from '../../components/BackendError'; -import SearchIcon from '@mui/icons-material/Search'; -import IconButton from '@mui/material/IconButton'; -import ClearIcon from '@mui/icons-material/Clear'; import SingleLineTextEdit from 'dashgui/SingleLineTextEdit'; import FillSpace from 'dashgui/FillSpace'; import { PanelTile, PanelTileGrid } from 'dashgui/panels'; @@ -14,6 +10,7 @@ import { backendErrorFrom } from '../../utils/backendError'; import { notifyError } from '../../utils/notify'; import { setLastArticleSku } from '../../automats'; import brandAutomat from '../../automats/brandAutomat'; +import { enqueueSnackbar } from 'notistack'; import { ArtikelMarke, ArtikelMarkeNew, @@ -25,19 +22,44 @@ import { class ArtikelMarkenSearchField extends PureComponent { constructor(props) { super(props); - this.state = { input: '' }; + this.state = { + input: props.value ?? '', + submitting: false, + }; + this.handleSubmit = this.handleSubmit.bind(this); + } + + componentDidUpdate(prevProps) { + if (prevProps.value !== this.props.value && this.props.value !== this.state.input) { + this.setState({ input: this.props.value ?? '' }); + } } onInputChange(input) { this.setState({ input }); + this.props.onChange?.(input); } - clearInput() { - this.setState({ input: '' }); + async handleSubmit() { + const name = this.state.input.trim(); + if (!name || this.state.submitting) return; + + this.setState({ submitting: true }); + try { + const row = await brandAutomat.actions.create({ name }); + enqueueSnackbar(`Marke „${row.name || name}“ angelegt.`, { variant: 'success' }); + this.setState({ input: '', submitting: false }); + this.props.onChange?.(''); + } catch (err) { + this.setState({ submitting: false }); + notifyError(err); + } } render() { const { inputRef } = this.props; + const { input, submitting } = this.state; + const canSubmit = Boolean(input.trim()) && !submitting; return ( @@ -50,16 +72,27 @@ class ArtikelMarkenSearchField extends PureComponent { md: 'span 2', }, display: 'flex', - flexDirection: 'column', + alignItems: 'center', + gap: 1, + pb: 2, }} > this.onInputChange(next)} /> - + ); @@ -72,7 +105,7 @@ class ArtikelMarkenPage extends PureComponent { this.state = { status: brandAutomat.state.status, error: brandAutomat.state.error ? backendErrorFrom({ message: brandAutomat.state.error }) : null, - brands: brandAutomat.state.brands, + brands: brandAutomat.state.brands }; this.searchRef = createRef(); this.handleRetry = this.handleRetry.bind(this); @@ -93,7 +126,6 @@ class ArtikelMarkenPage extends PureComponent { } handleRetry() { - // The automat owns fetching; just ask it to load again. void brandAutomat.actions.load().catch((err) => notifyError(err)); }