import { PureComponent, createRef } from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; import InputAdornment from '@mui/material/InputAdornment'; 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 FillSpace from 'dashgui/FillSpace'; import { PanelTile, PanelTileGrid } from 'dashgui/panels'; import { backendErrorFrom } from '../../utils/backendError'; import { notifyError } from '../../utils/notify'; import { setLastArticleSku } from '../../automats'; import brandAutomat from '../../automats/brandAutomat'; import { ArtikelMarke, ArtikelMarkeNew, } from '../../components/brand'; import { PURPLE_PANEL, } from '../../colors'; class ArtikelMarkenSearchField extends PureComponent { constructor(props) { super(props); this.state = { input: '' }; } onInputChange(input) { this.setState({ input }); } clearInput() { this.setState({ input: '' }); } render() { const { inputRef } = this.props; return ( this.onInputChange(e.target.value)} slotProps={{ htmlInput: { autoCapitalize: 'off', autoCorrect: 'off', }, input: { sx: { height: 40 }, startAdornment: ( ), endAdornment: ( this.clearInput()} onMouseDown={(e) => e.preventDefault()} aria-label="Suche löschen" > ), }, }} /> ); } } class ArtikelMarkenPage extends PureComponent { constructor(props) { super(props); this.state = { status: brandAutomat.state.status, error: brandAutomat.state.error ? backendErrorFrom({ message: brandAutomat.state.error }) : null, brands: brandAutomat.state.brands, }; this.searchRef = createRef(); this.createRowRef = createRef(); this.handleRetry = this.handleRetry.bind(this); } componentDidMount() { setLastArticleSku(null); this.unsub = brandAutomat.subscribe(this, (state) => ({ brands: state.brands, status: state.status, error: state.error ? backendErrorFrom({ message: state.error }) : null, })); } componentWillUnmount() { this.unsub?.(); } handleRetry() { // The automat owns fetching; just ask it to load again. void brandAutomat.actions.load().catch((err) => notifyError(err)); } render() { const { status, error, brands } = this.state; if (status === 'loading' || status === 'idle') { return ( ); } if (status === 'failed') { return ; } return ( <> ); } } export { ArtikelMarke, ArtikelMarkeNew, ArtikelMarkenSearchField }; export default ArtikelMarkenPage;