import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { ChevronDown, Trash } from "react-feather"; import { Card, CardHeader, CardTitle, Input, Label, Row, Col, } from "reactstrap"; import DataTable from "react-data-table-component"; import ReactPaginate from "react-paginate"; import { useTranslation } from "react-i18next"; import { getAllNotifications, setNotificationRead, notificationRemove, } from "../redux/actions/notifications"; import { default as SweetAlert } from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; const Swal = withReactContent(SweetAlert); const Notifications = () => { const { t } = useTranslation(); const conditionalRowStyles = [ { when: (row) => row.read === false, style: { backgroundColor: "#028a4a1a", }, }, ]; const serverSideColumns = [ { name: t("Notifications.title"), selector: (row) => row.title, sortable: true, maxWidth: "500px", }, { name: t("Notifications.notificationType"), selector: (row) => row.notificationType, sortable: true, maxWidth: "500px", }, { name: t("Notifications.content"), selector: (row) => row.message, sortable: true, maxWidth: "500px", }, { name: t("Time"), selector: (row) => row.createdDateTime, sortable: true, width: "250px", cell: (row) => ( {new Date(row.createdDateTime).toLocaleString("tr-TR")} ), }, { name: t("Cruds.delete"), allowOverflow: false, maxWidth: "100px", cell: (row) => { return (
); }, }, ]; const dispatch = useDispatch(); const [currentPage, setCurrentPage] = useState(1); const [rowsPerPage, setRowsPerPage] = useState(5); const [searchValue, setSearchValue] = useState(""); const notificationsStore = useSelector((state) => state.notifications); const [notifications, setNotifications] = useState([]); useEffect(() => { dispatch(getAllNotifications({ currentPage, rowsPerPage })); }, [currentPage, rowsPerPage]); useEffect(() => { if (notificationsStore.notifications?.content) { setNotifications(notificationsStore.notifications?.content); } }, [ notificationsStore.notifications?.content?.length, notificationsStore.notifications, ]); const handleFilter = (e) => { setSearchValue(e.target.value); if (e.target.value !== "") { setCurrentPage(1); setRowsPerPage(notificationsStore.notifications?.pageInfo?.totalElements); setNotifications( notificationsStore.notifications?.content.filter((notification) => notification.title .toLowerCase() .includes(e.target.value.toLowerCase()) ) ); } else { setCurrentPage(1); setRowsPerPage(5); setNotifications(notificationsStore.notifications?.content); } }; const handlePagination = (page) => { setCurrentPage(page.selected + 1); setNotifications(notificationsStore.notifications?.content); }; const handlePerPage = (e) => { setCurrentPage(1); setRowsPerPage(parseInt(e.target.value)); setNotifications(notificationsStore.notifications?.content); }; const CustomPagination = () => { const count = Number( ( notificationsStore.notifications?.pageInfo?.totalElements / rowsPerPage ).toFixed(1) ); return ({data?.title} / {data?.notificationType}
{data.message}
{t("Notifications.notification")} {t("Warnings.notFound")}
} />