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

@@ -16,6 +16,7 @@ import SaveOutlinedIcon from '@mui/icons-material/SaveOutlined';
import { enqueueSnackbar } from 'notistack';
import BackendError from '../BackendError';
import { setting as settingApi } from '../../api';
import companyAutomat from '../../automats/companyAutomat';
import { requireArray, requireDefined, requireObject } from '../../utils/apiShape';
import { backendErrorFrom } from '../../utils/backendError';
import { notifyError } from '../../utils/notify';
@@ -68,6 +69,7 @@ export default class SettingsKeysPanel extends Component {
constructor(props) {
super(props);
this.state = {
isAdmin: companyAutomat.state.current?.role === 'admin',
status: 'loading',
error: null,
settings: [],
@@ -79,6 +81,9 @@ export default class SettingsKeysPanel extends Component {
}
componentDidMount() {
this.unsub = companyAutomat.subscribe(this, (state) => ({
isAdmin: state.current?.role === 'admin',
}));
void this.load();
}
@@ -124,6 +129,7 @@ export default class SettingsKeysPanel extends Component {
}
async handleSave(key) {
if (!this.state.isAdmin) return;
const draft = this.state.drafts[key];
if (!draft || draft.busy) return;
const row = this.state.settings.find((s) => s.key === key);
@@ -172,10 +178,11 @@ export default class SettingsKeysPanel extends Component {
componentWillUnmount() {
this._unmounted = true;
this.unsub?.();
}
render() {
const { status, error, settings, drafts } = this.state;
const { isAdmin, status, error, settings, drafts } = this.state;
if (status === 'loading') {
return (
@@ -224,7 +231,7 @@ export default class SettingsKeysPanel extends Component {
size="small"
fullWidth
value={draft.value !== undefined && draft.value !== null ? draft.value : (DEFAULT_SETTINGS[row.key] ?? '')}
disabled={draft.busy}
disabled={!isAdmin || draft.busy}
onChange={(e) => this.handleChange(row.key, 'value', e.target.value)}
slotProps={{ htmlInput: { spellCheck: false } }}
>
@@ -247,7 +254,7 @@ export default class SettingsKeysPanel extends Component {
maxRows={isMultiline ? 6 : undefined}
placeholder={DEFAULT_SETTINGS[row.key] ?? undefined}
value={draft.value}
disabled={draft.busy}
disabled={!isAdmin || draft.busy}
onChange={(e) => this.handleChange(row.key, 'value', e.target.value)}
onKeyDown={(e) => {
if (!isMultiline && e.key === 'Enter') {
@@ -279,7 +286,7 @@ export default class SettingsKeysPanel extends Component {
size="small"
aria-label="Speichern"
color="primary"
disabled={draft.busy}
disabled={!isAdmin || draft.busy}
onClick={() => void this.handleSave(row.key)}
>
<SaveOutlinedIcon fontSize="small" />