feat: role system fix

This commit is contained in:
2026-03-18 21:38:50 +03:00
parent c3127b8d47
commit 591ca8104d
14 changed files with 267 additions and 183 deletions

View File

@@ -21,6 +21,7 @@ export const ArticleListPage = observer(() => {
page: 0,
pageSize: 50,
});
const canWriteArticles = authStore.canWrite("sights");
useEffect(() => {
const fetchArticles = async () => {
@@ -56,7 +57,7 @@ export const ArticleListPage = observer(() => {
<button onClick={() => navigate(`/article/${params.row.id}`)}>
<Eye size={20} className="text-green-500" />
</button>
{authStore.canWrite("sights") && (
{canWriteArticles && (
<button
onClick={() => {
setIsDeleteModalOpen(true);
@@ -86,7 +87,7 @@ export const ArticleListPage = observer(() => {
<h1 className="text-2xl">Статьи</h1>
</div>
{ids.length > 0 && (
{canWriteArticles && ids.length > 0 && (
<div className="flex justify-end mb-5 duration-300">
<button
className="px-4 py-2 bg-red-500 text-white rounded flex gap-2 items-center"
@@ -102,25 +103,37 @@ export const ArticleListPage = observer(() => {
<DataGrid
rows={rows}
columns={columns}
checkboxSelection
checkboxSelection={canWriteArticles}
disableRowSelectionExcludeModel
loading={isLoading}
paginationModel={paginationModel}
onPaginationModelChange={setPaginationModel}
pageSizeOptions={[50]}
localeText={ruRU.components.MuiDataGrid.defaultProps.localeText}
onRowSelectionModelChange={(newSelection: any) => {
if (Array.isArray(newSelection)) {
const selectedIds = newSelection.map((id: string | number) => Number(id));
setIds(selectedIds);
} else if (newSelection && typeof newSelection === 'object' && 'ids' in newSelection) {
const idsSet = newSelection.ids as Set<string | number>;
const selectedIds = Array.from(idsSet).map((id: string | number) => Number(id));
setIds(selectedIds);
} else {
setIds([]);
}
}}
onRowSelectionModelChange={
canWriteArticles
? (newSelection: any) => {
if (Array.isArray(newSelection)) {
const selectedIds = newSelection.map(
(id: string | number) => Number(id)
);
setIds(selectedIds);
} else if (
newSelection &&
typeof newSelection === "object" &&
"ids" in newSelection
) {
const idsSet = newSelection.ids as Set<string | number>;
const selectedIds = Array.from(idsSet).map(
(id: string | number) => Number(id)
);
setIds(selectedIds);
} else {
setIds([]);
}
}
: undefined
}
slots={{
noRowsOverlay: () => (
<Box