"use client"; import React, { useState, useEffect } from "react"; import { useSelector, useDispatch } from "react-redux"; import { getMessagesThunk } from "@/redux/thunks/getMessagesThunk"; import type { AppDispatch } from "@/redux/store"; type Meldung = { t: string; s: number; c: string; m: string; i: string; v: string; }; type Props = { className?: string; }; export default function Last20MessagesTable({ className }: Props) { const dispatch = useDispatch(); type RootState = { messages: { data: Meldung[]; }; }; const { data: messages } = useSelector((state: RootState) => state.messages); const [sourceFilter] = useState("Alle"); const today = new Date(); const prior30 = new Date(); prior30.setDate(today.getDate() - 30); const formatDate = (d: Date) => d.toISOString().split("T")[0]; const [fromDate] = useState(formatDate(prior30)); const [toDate] = useState(formatDate(today)); useEffect(() => { dispatch(getMessagesThunk({ fromDate, toDate })); }, [dispatch, fromDate, toDate]); const filteredMessages = sourceFilter === "Alle" ? messages : messages.filter((m: Meldung) => m.i === sourceFilter); return (
{filteredMessages.slice(0, 20).map((msg, index) => ( ))}
Prio Zeitstempel Quelle Meldung Status
{msg.t} {msg.i} {msg.m} {msg.v}
{messages.length === 0 && (
Keine Meldungen im gewählten Zeitraum vorhanden.
)}
); }