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

@@ -50,6 +50,7 @@ export default class ImportExportSettingsPanel extends Component {
constructor(props) {
super(props);
this.state = {
isAdmin: companyAutomat.state.current?.role === 'admin',
// Export state
downloading: false,
downloadProgress: null, // null = unknown, number 0-100
@@ -84,7 +85,14 @@ export default class ImportExportSettingsPanel extends Component {
this.handleCancelUpload = this.handleCancelUpload.bind(this);
}
componentDidMount() {
this.unsub = companyAutomat.subscribe(this, (state) => ({
isAdmin: state.current?.role === 'admin',
}));
}
componentWillUnmount() {
this.unsub?.();
if (this.uploadAbortController) {
this.uploadAbortController.abort();
}
@@ -147,6 +155,7 @@ export default class ImportExportSettingsPanel extends Component {
}
handleFileChange(event) {
if (!this.state.isAdmin) return;
const file = event.target.files?.[0];
if (file) {
if (!isZipFile(file)) {
@@ -169,6 +178,7 @@ export default class ImportExportSettingsPanel extends Component {
}
async handleStartUpload() {
if (!this.state.isAdmin) return;
const { selectedFile } = this.state;
if (!selectedFile) return;
@@ -282,6 +292,7 @@ export default class ImportExportSettingsPanel extends Component {
render() {
const {
isAdmin,
downloading,
downloadProgress,
downloadStatus,
@@ -583,7 +594,7 @@ export default class ImportExportSettingsPanel extends Component {
accept=".zip,application/zip,application/x-zip-compressed"
style={{ display: 'none' }}
onChange={this.handleFileChange}
disabled={uploading}
disabled={!isAdmin || uploading}
/>
{!selectedFile ? (
@@ -592,7 +603,7 @@ export default class ImportExportSettingsPanel extends Component {
variant="outlined"
startIcon={<InsertDriveFileOutlinedIcon />}
onClick={() => this.fileInputRef.current?.click()}
disabled={uploading}
disabled={!isAdmin || uploading}
>
ZIP-Datei auswählen
</Button>
@@ -625,6 +636,7 @@ export default class ImportExportSettingsPanel extends Component {
{!uploading && (
<IconButton
size="small"
disabled={!isAdmin}
onClick={() => {
this.setState({ selectedFile: null });
if (this.fileInputRef.current) this.fileInputRef.current.value = '';
@@ -760,7 +772,7 @@ export default class ImportExportSettingsPanel extends Component {
<CloudUploadOutlinedIcon />
)
}
disabled={uploading || !selectedFile}
disabled={!isAdmin || uploading || !selectedFile}
onClick={this.handleStartUpload}
>
{uploading ? 'Import läuft…' : 'Upload & Import starten'}