fix uset notice list

This commit is contained in:
Patryk
2025-06-11 21:11:07 +02:00
parent 3c042d2cfb
commit 2630b35afd
2 changed files with 20 additions and 19 deletions

View File

@@ -10,26 +10,26 @@ export function UserSection({ notices, title }) {
const [users, setUsers] = useState([]);
const { token } = useAuthStore.getState();
useEffect(() => {
const fetchUsers = async () => {
try {
const data = await getAllUsers();
setUsers(data);
} catch (error) {
console.error("Ошибка при загрузке пользователей:", error);
setUsers([]);
}
};
useEffect(() => {
const fetchUsers = async () => {
try {
const data = await getAllUsers();
setUsers(data);
} catch (error) {
setUsers([]);
}
};
fetchUsers();
}, [token]);
fetchUsers();
}, [token]);
const usersWithNoticeCount = users && users.length > 0
? users.map((user) => {
const count = notices.filter((n) => n.clientId === user.id).length;
return { ...user, noticeCount: count };
const usersWithNoticeCount =
users && users.length > 0
? users.map((user) => {
const count = notices.filter((n) => n.clientId === user.id).length;
return { ...user, noticeCount: count };
})
: [];
: [];
const topUsers = usersWithNoticeCount
.sort((a, b) => b.noticeCount - a.noticeCount)