Files
CPLv4.0/components/main/settingsPageComponents/OPCUAInterfaceSettings.tsx
ISA 20e20dec30 feat(redux): Rename all Redux slices and store keys to match file names for clarity
- Renamed all slice names (createSlice `name` attribute) to match their file names (e.g. loopChartSlice, authSlice, kueDataSlice etc.)
- Updated `store.ts` to register each reducer with consistent key names (e.g. state.loopChartSlice instead of state.loopChart)
- Adjusted all `useSelector` and Redux state accesses across the codebase
- Improves maintainability, searchability and consistency across files and Redux DevTools
2025-04-01 12:26:41 +02:00

150 lines
4.8 KiB
TypeScript

"use client"; // /components/main/settingsPageComponents/OPCUAInterfaceSettings.tsx
import React, { useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import { RootState } from "../../../redux/store";
import {
setOpcUaEncryption,
toggleOpcUaServer,
setOpcUaNodesetName,
addOpcUaUser,
removeOpcUaUser,
} from "../../../redux/slices/opcuaSettingsSlice";
export default function OPCUAInterfaceSettings() {
const dispatch = useDispatch();
const opcuaSettings = useSelector(
(state: RootState) => state.opcuaSettingsSlice
);
// Lokale Zustände für das neue Benutzerformular
const [newUsername, setNewUsername] = useState("");
const [newPassword, setNewPassword] = useState("");
const [nodesetName, setNodesetName] = useState(
opcuaSettings.opcUaNodesetName
);
const handleAddUser = () => {
if (newUsername.trim() && newPassword.trim()) {
dispatch(addOpcUaUser({ username: newUsername, password: newPassword }));
setNewUsername("");
setNewPassword("");
}
};
const handleNodesetUpdate = () => {
dispatch(setOpcUaNodesetName(nodesetName));
};
return (
<div className="max-w-lg mx-auto p-2 bg-gray-100 shadow-md rounded-lg">
<h2 className="text-base font-semibold mb-3">
OPCUA Server Einstellungen
</h2>
{/* ✅ Server Aktivierung */}
<div className="mb-3 flex flex-wrap items-center">
<label className="mr-3 font-medium text-sm">Server Status:</label>
<button
onClick={() => dispatch(toggleOpcUaServer())}
className={`px-3 py-1 rounded text-sm ${
opcuaSettings.isEnabled ? "bg-littwin-blue" : "bg-gray-300"
} text-white`}
>
{opcuaSettings.isEnabled ? "Aktiviert" : "Deaktiviert"}
</button>
</div>
{/* ✅ Verschlüsselung */}
{/*
<div className="mb-3">
<label className="block font-medium text-sm mb-1">
Verschlüsselung
</label>
<select
value={opcuaSettings.encryption}
onChange={(e) => dispatch(setOpcUaEncryption(e.target.value))}
className="w-full p-1 border border-gray-300 rounded-md text-sm"
>
<option value="None">Keine</option>
<option value="Basic256">Basic256</option>
<option value="Basic256Sha256">Basic256Sha256</option>
</select>
</div>
*/}
{/* ✅ OPCUA Zustand */}
<div className="mb-3">
<label className="block font-medium text-sm mb-1">OPCUA Zustand</label>
<div className="p-1 border border-gray-300 rounded-md bg-white text-sm">
{opcuaSettings.opcUaZustand}
</div>
</div>
{/* ✅ Nodeset Name */}
<div className="mb-3">
<label className="block font-medium text-sm mb-1">Nodeset Name</label>
<div className="flex">
<input
type="text"
className="flex-grow p-1 border border-gray-300 rounded-l-md text-sm"
value={nodesetName}
onChange={(e) => setNodesetName(e.target.value)}
/>
<button
onClick={handleNodesetUpdate}
className="px-3 py-1 bg-littwin-blue text-white rounded-r-md text-sm"
>
Übernehmen
</button>
</div>
</div>
{/* ✅ Benutzerverwaltung */}
<div className="mb-3">
<h3 className="text-base font-semibold mb-2">Benutzer</h3>
<ul className="space-y-1">
{opcuaSettings.users.map((user) => (
<li
key={user.id}
className="p-1 bg-white shadow-sm rounded-md flex justify-between items-center text-sm"
>
<span className="font-medium">{user.username}</span>
<button
onClick={() => dispatch(removeOpcUaUser(user.id))}
className="text-red-500"
>
Löschen
</button>
</li>
))}
</ul>
{/* ✅ Neuen Benutzer hinzufügen */}
<div className="mt-2 flex flex-wrap gap-2">
<input
type="text"
placeholder="Benutzername"
value={newUsername}
onChange={(e) => setNewUsername(e.target.value)}
className="p-1 border rounded flex-grow text-sm"
/>
<input
type="password"
placeholder="Passwort"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
className="p-1 border rounded flex-grow text-sm"
/>
<button
onClick={handleAddUser}
className="bg-littwin-blue text-white p-1 rounded text-sm"
>
Hinzufügen
</button>
</div>
</div>
</div>
);
}