import { DataGrid, GridColDef, GridRenderCellParams } from "@mui/x-data-grid"; import { ruRU } from "@mui/x-data-grid/locales"; import { articlesStore, languageStore } from "@shared"; import { useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { Trash2, Eye, Minus } from "lucide-react"; import { useNavigate } from "react-router-dom"; import { DeleteModal, LanguageSwitcher } from "@widgets"; import { Box, CircularProgress } from "@mui/material"; export const ArticleListPage = observer(() => { const { articleList, getArticleList, deleteArticles } = articlesStore; const navigate = useNavigate(); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [isBulkDeleteModalOpen, setIsBulkDeleteModalOpen] = useState(false); const [rowId, setRowId] = useState(null); const { language } = languageStore; const [ids, setIds] = useState([]); const [isLoading, setIsLoading] = useState(false); useEffect(() => { const fetchArticles = async () => { setIsLoading(true); await getArticleList(); setIsLoading(false); }; fetchArticles(); }, [language]); const columns: GridColDef[] = [ { field: "heading", headerName: "Название", flex: 1, renderCell: (params: GridRenderCellParams) => { return params.value ? ( params.value ) : (
); }, }, { field: "actions", headerName: "Действия", renderCell: (params: GridRenderCellParams) => { return (
); }, }, ]; const rows = articleList[language].data.map((article) => ({ id: article.id, heading: article.heading, body: article.body, })); return ( <>

Статьи

0 ? 1 : 0 }} >
{ setIds(Array.from(newSelection.ids) as number[]); }} hideFooter slots={{ noRowsOverlay: () => ( {isLoading ? : "Нет статей"} ), }} />
{ if (rowId) { await deleteArticles([parseInt(rowId)]); getArticleList(); } setIsDeleteModalOpen(false); setRowId(null); }} onCancel={() => { setIsDeleteModalOpen(false); setRowId(null); }} /> { await deleteArticles(ids); getArticleList(); setIsBulkDeleteModalOpen(false); setIds([]); }} onCancel={() => { setIsBulkDeleteModalOpen(false); }} /> ); });