fix: buttons not working
This commit is contained in:
82
src/App.js
82
src/App.js
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { startOfDay } from 'date-fns';
|
||||
import './App.css';
|
||||
@@ -40,6 +40,10 @@ function App() {
|
||||
const [activeRangePicker, setActiveRangePicker] = useState(null);
|
||||
const [notificationPanelOpen, setNotificationPanelOpen] = useState(false);
|
||||
const [focusedStoreId, setFocusedStoreId] = useState(null);
|
||||
const configRef = useRef(config);
|
||||
useEffect(() => {
|
||||
configRef.current = config;
|
||||
}, [config]);
|
||||
const minSelectableDate = useMemo(() => startOfDay(new Date()), []);
|
||||
|
||||
const weekdays = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
|
||||
@@ -681,47 +685,49 @@ function App() {
|
||||
};
|
||||
}, [isDirty]);
|
||||
|
||||
const persistConfigUpdate = async (updater, successMessage, { autoCommit = false } = {}) => {
|
||||
if (!session?.token) {
|
||||
return;
|
||||
}
|
||||
let nextConfigState;
|
||||
setConfig((prev) => {
|
||||
nextConfigState = typeof updater === 'function' ? updater(prev) : updater;
|
||||
return nextConfigState;
|
||||
});
|
||||
if (!nextConfigState) {
|
||||
return;
|
||||
}
|
||||
if (!autoCommit) {
|
||||
setIsDirty(true);
|
||||
}
|
||||
setStatus('Speichere...');
|
||||
setError('');
|
||||
try {
|
||||
const response = await authorizedFetch('/api/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(nextConfigState)
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
const persistConfigUpdate = useCallback(
|
||||
async (updater, successMessage, { autoCommit = false } = {}) => {
|
||||
const baseConfig = configRef.current;
|
||||
const nextConfigState = typeof updater === 'function' ? updater(baseConfig) : updater;
|
||||
if (!nextConfigState) {
|
||||
return;
|
||||
}
|
||||
const result = await response.json();
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Unbekannter Fehler beim Speichern');
|
||||
setConfig(nextConfigState);
|
||||
if (!session?.token) {
|
||||
setIsDirty(true);
|
||||
return;
|
||||
}
|
||||
const message = successMessage || 'Konfiguration gespeichert.';
|
||||
setStatus(message);
|
||||
setTimeout(() => setStatus(''), 3000);
|
||||
setIsDirty(false);
|
||||
} catch (err) {
|
||||
setError(`Fehler beim Speichern: ${err.message}`);
|
||||
if (autoCommit) {
|
||||
if (!autoCommit) {
|
||||
setIsDirty(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
setStatus('Speichere...');
|
||||
setError('');
|
||||
try {
|
||||
const response = await authorizedFetch('/api/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(nextConfigState)
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
const result = await response.json();
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Unbekannter Fehler beim Speichern');
|
||||
}
|
||||
const message = successMessage || 'Konfiguration gespeichert.';
|
||||
setStatus(message);
|
||||
setTimeout(() => setStatus(''), 3000);
|
||||
setIsDirty(false);
|
||||
} catch (err) {
|
||||
setError(`Fehler beim Speichern: ${err.message}`);
|
||||
if (autoCommit) {
|
||||
setIsDirty(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
[authorizedFetch, session?.token]
|
||||
);
|
||||
|
||||
const deleteEntry = async (entryId) => {
|
||||
const confirmed = await askConfirmation({
|
||||
|
||||
Reference in New Issue
Block a user