This commit is contained in:
seb
2026-11-03 06:46:36 +01:00
parent 9841002398
commit 863422df8e
20 changed files with 300 additions and 82 deletions

View File

@@ -21,6 +21,7 @@ class VersandartenSearchField extends PureComponent {
super(props);
const initial = companyAutomat.state.carrierFilter || '';
this.state = {
isAdmin: companyAutomat.state.current?.role === 'admin',
input: initial,
submitting: false,
};
@@ -29,6 +30,7 @@ class VersandartenSearchField extends PureComponent {
componentDidMount() {
this.unsub = companyAutomat.subscribe(this, (state) => ({
isAdmin: state.current?.role === 'admin',
input: state.carrierFilter,
}));
}
@@ -43,6 +45,7 @@ class VersandartenSearchField extends PureComponent {
}
async handleSubmit() {
if (!this.state.isAdmin) return;
const name = this.state.input.trim();
if (!name || this.state.submitting) return;
@@ -64,8 +67,8 @@ class VersandartenSearchField extends PureComponent {
render() {
const { inputRef } = this.props;
const { input, submitting } = this.state;
const canSubmit = Boolean(input.trim()) && !submitting;
const { isAdmin, input, submitting } = this.state;
const canCreate = isAdmin && Boolean(input.trim()) && !submitting;
return (
<PanelTileGrid>
@@ -102,7 +105,7 @@ class VersandartenSearchField extends PureComponent {
/>
<Button
variant="contained"
disabled={!canSubmit}
disabled={!canCreate}
onClick={() => void this.handleSubmit()}
>
Hinzufügen
@@ -120,6 +123,7 @@ class AuftragVersandartenPage extends PureComponent {
const initialCarriers =
companyAutomat.state.filteredCarriers ?? companyAutomat.state.carriers ?? [];
this.state = {
isAdmin: companyAutomat.state.current?.role === 'admin',
status: companyAutomat.state.carriersStatus === 'ready' ? 'ready' : 'loading',
error: companyAutomat.state.carriersError ? backendErrorFrom(companyAutomat.state.carriersError) : null,
carriers: initialCarriers,
@@ -138,6 +142,7 @@ class AuftragVersandartenPage extends PureComponent {
this._cancelled = false;
this.unsub = companyAutomat.subscribe(this, (state) => ({
isAdmin: state.current?.role === 'admin',
carriers: state.filteredCarriers ?? state.carriers,
filter: state.carrierFilter ?? '',
status: state.carriersStatus,
@@ -151,6 +156,7 @@ class AuftragVersandartenPage extends PureComponent {
componentDidUpdate(prevProps, prevState) {
if (
prevState.isAdmin !== this.state.isAdmin ||
prevState.status !== this.state.status ||
prevState.carriers !== this.state.carriers ||
prevState.filter !== this.state.filter
@@ -179,7 +185,7 @@ class AuftragVersandartenPage extends PureComponent {
animation: 150,
ghostClass: 'sortable-ghost',
chosenClass: 'sortable-chosen',
disabled: isFiltered,
disabled: !this.state.isAdmin || isFiltered,
onEnd: (evt) => {
const { oldIndex, newIndex } = evt;
if (oldIndex === newIndex) return;
@@ -220,7 +226,7 @@ class AuftragVersandartenPage extends PureComponent {
}
render() {
const { status, error, carriers, filter } = this.state;
const { isAdmin, status, error, carriers, filter } = this.state;
if (status === 'loading' || status === 'idle') {
return (
@@ -253,6 +259,7 @@ class AuftragVersandartenPage extends PureComponent {
<CarrierItem
key={c.id}
carrier={c}
disabled={!isAdmin}
/>
))
)}