All clients get api
This commit is contained in:
@@ -12,10 +12,28 @@ export async function getUserById(userId) {
|
|||||||
});
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// console.error(
|
console.error(
|
||||||
// `Nie udało się pobrać danych użytkownika o ID ${userId}.`,
|
`Nie udało się pobrać danych użytkownika o ID ${userId}.`,
|
||||||
// err.response.status
|
err.response.status
|
||||||
// );
|
);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAllUsers() {
|
||||||
|
const { token } = useAuthStore.getState();
|
||||||
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${API_URL}/clients/get/all`, {
|
||||||
|
headers: headers,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
`Nie udało się pobrać danych o użytkownikach`,
|
||||||
|
err.response.status
|
||||||
|
);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import axios from "axios";
|
|||||||
import FormData from "form-data";
|
import FormData from "form-data";
|
||||||
import { useAuthStore } from "@/store/authStore";
|
import { useAuthStore } from "@/store/authStore";
|
||||||
|
|
||||||
// const API_URL = "https://hopp.zikor.pl/api/v1";
|
|
||||||
|
|
||||||
const API_URL = "https://hopp.zikor.pl/api/v1";
|
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||||
|
|
||||||
export async function listNotices() {
|
export async function listNotices() {
|
||||||
|
|||||||
@@ -2,30 +2,34 @@ import { View } from "react-native";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Heading } from "@/components/ui/heading";
|
import { Heading } from "@/components/ui/heading";
|
||||||
import { FlatList } from "react-native";
|
import { FlatList } from "react-native";
|
||||||
import axios from "axios";
|
|
||||||
import UserBlock from "@/components/UserBlock";
|
import UserBlock from "@/components/UserBlock";
|
||||||
|
import { getAllUsers } from "@/api/client";
|
||||||
import { useAuthStore } from "@/store/authStore";
|
import { useAuthStore } from "@/store/authStore";
|
||||||
|
|
||||||
export function UserSection({ notices, title }) {
|
export function UserSection({ notices, title }) {
|
||||||
const token = useAuthStore((state) => state.token);
|
|
||||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
|
||||||
const [users, setUsers] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
|
const { token } = useAuthStore.getState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (token) {
|
const fetchUsers = async () => {
|
||||||
axios
|
try {
|
||||||
.get("https://hopp.zikor.pl/api/v1/clients/get/all", {
|
const data = await getAllUsers();
|
||||||
headers: headers,
|
setUsers(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка при загрузке пользователей:", error);
|
||||||
|
setUsers([]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 };
|
||||||
})
|
})
|
||||||
.then((res) => setUsers(res.data))
|
: [];
|
||||||
.catch(() => setUsers([]));
|
|
||||||
}
|
|
||||||
}, [token]);
|
|
||||||
|
|
||||||
const usersWithNoticeCount = users.map((user) => {
|
|
||||||
const count = notices.filter((n) => n.clientId === user.id).length;
|
|
||||||
return { ...user, noticeCount: count };
|
|
||||||
});
|
|
||||||
|
|
||||||
const topUsers = usersWithNoticeCount
|
const topUsers = usersWithNoticeCount
|
||||||
.sort((a, b) => b.noticeCount - a.noticeCount)
|
.sort((a, b) => b.noticeCount - a.noticeCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user