- Handler-Funktionen (handleClearDatabase, handleReboot, handleSetDateTime, handleSubmit) in separate Dateien ausgelagert, um die Übersichtlichkeit zu verbessern und Wartbarkeit zu erleichtern - `use client`-Anweisung am Anfang von SettingsModal.jsx hinzugefügt, um clientseitige Funktionen wie `window`-basierte Aufrufe korrekt zu verwenden - Redux- und lokale State-Werte optimiert und an handleSubmit als Parameter übergeben - Konsolen-Logs für URL-Bildung und Debugging-Zwecke in den Handlern hinzugefügt
33 lines
1013 B
JavaScript
33 lines
1013 B
JavaScript
// components/modales/handlers/handleClearDatabase.js
|
|
const handleClearDatabase = async () => {
|
|
const confirmClear = window.confirm(
|
|
"Sind Sie sicher, dass Sie die Datenbank leeren möchten?"
|
|
);
|
|
if (!confirmClear) return;
|
|
|
|
// Get the current path and ensure it ends with ".html"
|
|
let currentPath = window.location.pathname;
|
|
if (!currentPath.endsWith(".html")) {
|
|
currentPath += ".html";
|
|
}
|
|
|
|
// Full URL with host, current path, and clear database command
|
|
const url = `${window.location.origin}/CPL?${currentPath}&DEDB=1`;
|
|
|
|
// Log the full URL to the console for debugging
|
|
console.log(url);
|
|
|
|
// Send the clear database command to the server using fetch and GET method
|
|
try {
|
|
const response = await fetch(url, { method: "GET" });
|
|
if (response.ok) {
|
|
alert("Datenbank erfolgreich geleert!");
|
|
} else {
|
|
alert("Fehler beim Leeren der Datenbank!");
|
|
}
|
|
} catch (error) {
|
|
console.error("Fehler:", error);
|
|
alert("Fehler beim Leeren der Datenbank!");
|
|
}
|
|
};
|