fix: hide Firmware update button if admin not loged in

This commit is contained in:
ISA
2025-07-01 07:17:40 +02:00
parent b447a80757
commit ecb818e248
11 changed files with 69 additions and 18 deletions

View File

@@ -1,16 +1,24 @@
// /komponents/main/kabelueberwachung/kue705FO/handlers/firmwareUpdate.ts
const firmwareUpdate = (slot: number) => {
const url = `${window.location.origin}/CPL?/kabelueberwachung.html&KSU${slot}=1`;
const isDev =
typeof window !== "undefined" && window.location.hostname === "localhost";
const url = isDev
? `${window.location.origin}/api/cpl/kueSingleModuleUpdateMock?slot=${
slot + 1
}`
: `${window.location.origin}/CPL?/kabelueberwachung.html&KSU${slot}=1`;
fetch(url, { method: "GET" })
.then((response) => {
if (response.ok) {
alert(`Update an ${slot + 1} erfolgreich gestartet!`);
} else {
alert("Fehler beim Update!");
}
.then((response) => response.json())
.then((data) => {
alert(
data.message || `Update an Slot ${slot + 1} erfolgreich gestartet!`
);
})
.catch((error) => {
console.error("Fehler:", error);
alert("Fehler beim Update!");
});
};
export default firmwareUpdate;

View File

@@ -246,7 +246,15 @@ export default function KueEinstellung({
<div className="flex justify-end gap-2 p-0 rounded">
{isAdminLoggedIn && (
<button
onClick={() => firmwareUpdate(slot)}
onClick={() => {
if (
window.confirm(
"Warnung: Das Firmware-Update kann einige Minuten dauern und das Gerät neu starten.\nMöchten Sie wirklich fortfahren?"
)
) {
firmwareUpdate(slot);
}
}}
className="bg-littwin-blue text-white px-4 py-2 rounded flex items-center"
>
Firmware Update

View File

@@ -12,15 +12,15 @@ import { AppDispatch } from "../../../redux/store";
import { getSystemSettingsThunk } from "../../../redux/thunks/getSystemSettingsThunk";
import handleGeneralSubmit from "./handlers/handleGeneralSubmit";
import handleKueFirmwareUpdate from "@/components/main/settingsPageComponents/handlers/handleKueFirmwareUpdate";
import { useAdminAuth } from "@/components/main/settingsPageComponents/hooks/useAdminAuth";
const GeneralSettings: React.FC = () => {
const dispatch = useDispatch<AppDispatch>();
const systemSettings = useSelector(
(state: RootState) => state.systemSettingsSlice
);
const isAdmin = useSelector(
(state: RootState) => state.authSlice?.isAdminLoggedIn
);
const { isAdminLoggedIn } = useAdminAuth(true);
// const [error, setError] = useState("");
@@ -196,10 +196,10 @@ const GeneralSettings: React.FC = () => {
>
Neustart CPL
</button>
{isAdmin && (
{isAdminLoggedIn && (
<button
type="button"
className="bg-red-600 text-white px-4 py-2 h-8 text-xs rounded whitespace-nowrap"
className="bg-littwin-blue text-white px-4 py-2 h-8 text-xs rounded whitespace-nowrap"
onClick={handleKueFirmwareUpdate}
>
Firmwareupdate alle -Module