Digitale Eingänge und digitale Ausgänge an die Seite anpassen
This commit is contained in:
@@ -1,71 +1,54 @@
|
||||
"use client";
|
||||
import React from "react";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { RootState } from "../../../redux/store";
|
||||
import { setDigitalOutputs } from "../../../redux/slices/digitalOutputsSlice";
|
||||
import { Icon } from "@iconify/react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "../../../redux/store";
|
||||
|
||||
export default function DigitalOutputs({ openOutputModal }) {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
// Redux-Store für digitale Ausgänge nutzen
|
||||
const digitalOutputs = useSelector(
|
||||
(state: RootState) => state.digitalOutputs?.outputs ?? []
|
||||
(state: RootState) => state.digitalOutputsSlice.outputs
|
||||
);
|
||||
|
||||
// Funktion zum Umschalten des Ausgangsstatus
|
||||
const toggleSwitch = (id: number) => {
|
||||
const updatedOutputs = digitalOutputs.map((output) =>
|
||||
output.id === id ? { ...output, status: !output.status } : output
|
||||
);
|
||||
dispatch(setDigitalOutputs(updatedOutputs));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-white shadow-md rounded-lg border border-gray-200 p-4 w-2/5 h-[fit-content]">
|
||||
<h2 className="text-md font-bold mb-4 flex items-center">
|
||||
<Icon icon="mdi:output" className="text-littwin-blue mr-2 text-2xl" />
|
||||
<div className="bg-white shadow-md border border-gray-200 p-3 rounded-lg w-full h-fit max-h-[400px] overflow-auto">
|
||||
<h2 className="text-sm font-bold mb-3 flex items-center">
|
||||
<Icon icon="mdi:output" className="text-littwin-blue mr-2 text-xl" />
|
||||
Digitale Ausgänge
|
||||
</h2>
|
||||
<table className="w-full text-sm border-collapse bg-white rounded-lg">
|
||||
<table className="w-full text-xs border-collapse bg-white rounded-lg">
|
||||
<thead className="bg-gray-100 border-b">
|
||||
<tr>
|
||||
<th className="px-2 py-1 text-left">Ausgang</th>
|
||||
<th className="px-2 py-1 text-left">Bezeichnung</th>
|
||||
<th className="px-2 py-1 text-left">Schalter</th>
|
||||
<th className="px-2 py-1 text-left">Aktion</th>
|
||||
<th className="px-1 py-1 text-left">Ausgang</th>
|
||||
<th className="px-1 py-1 text-left">Bezeichnung</th>
|
||||
<th className="px-1 py-1 text-left">Schalter</th>
|
||||
<th className="px-1 py-1 text-left">Aktion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{digitalOutputs.map((output) => (
|
||||
<tr key={output.id} className="border-b">
|
||||
<td className="flex items-center px-2 py-1">
|
||||
<td className="flex items-center px-1 py-1">
|
||||
<Icon
|
||||
icon="mdi:output"
|
||||
className="text-black-500 mr-2 text-xl"
|
||||
className="text-gray-600 mr-1 text-base"
|
||||
/>
|
||||
{output.id}
|
||||
</td>
|
||||
<td className="px-2 py-1">{output.label}</td>
|
||||
<td className="px-2 py-1">
|
||||
<span
|
||||
title={`Schalter ${output.status ? "EIN" : "AUS"} schalten`}
|
||||
>
|
||||
<Icon
|
||||
icon="ion:switch"
|
||||
onClick={() => toggleSwitch(output.id)}
|
||||
className={`cursor-pointer text-2xl transform ${
|
||||
output.status
|
||||
? "text-littwin-blue scale-x-100"
|
||||
: "text-gray-500 scale-x-[-1]"
|
||||
}`}
|
||||
/>
|
||||
</span>
|
||||
<td className="px-1 py-1">{output.label}</td>
|
||||
<td className="px-1 py-1">
|
||||
<Icon
|
||||
icon="ion:switch"
|
||||
className={`text-base ${
|
||||
output.status
|
||||
? "text-littwin-blue"
|
||||
: "text-gray-500 scale-x-[-1]"
|
||||
}`}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-2 py-1">
|
||||
<td className="px-1 py-1">
|
||||
<Icon
|
||||
icon="mdi:settings"
|
||||
className="text-gray-400 text-lg cursor-pointer"
|
||||
className="text-gray-400 text-base cursor-pointer"
|
||||
onClick={() => openOutputModal(output)}
|
||||
/>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user