This commit is contained in:
2025-05-25 17:41:07 +02:00
parent 9962dc1e55
commit eb1ebc3464
2 changed files with 87 additions and 3 deletions

View File

@@ -0,0 +1,13 @@
import axios from "axios";
const API_URL = "https://testowe.zikor.pl/api/v1";
export async function getUserById(userId) {
try {
const response = await axios.get(`${API_URL}/clients/get/${userId}`);
return response.data;
} catch (err) {
console.error(`Nie udało się pobrać danych użytkownika o ID ${userId}.`, err.response.status);
throw err;
}
}

View File

@@ -11,6 +11,9 @@ import {useEffect, useState} from "react";
import {useNoticesStore} from "@/store/noticesStore";
import {useWishlist} from "@/store/wishlistStore";
import {Pressable} from "react-native";
import {getUserById} from "@/api/client";
export default function NoticeDetails() {
const {id} = useLocalSearchParams();
@@ -19,6 +22,9 @@ export default function NoticeDetails() {
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const [notice, setNotice] = useState(null);
const [user, setUser] = useState(null);
const [isUserLoading, setIsUserLoading] = useState(true);
const {getNoticeById, getAllImagesByNoticeId} = useNoticesStore();
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
@@ -69,6 +75,25 @@ export default function NoticeDetails() {
}
}, [notice]);
useEffect(() => {
const fetchUser = async () => {
if (notice && notice.clientId) {
setIsUserLoading(true);
try {
const userData = await getUserById(notice.clientId);
setUser(userData);
} catch (err) {
console.error("Nie udało się pobrać danych użytkownika:", err);
} finally {
setIsUserLoading(false);
}
}
};
fetchUser();
}, [notice]);
if (isLoading) {
return <ActivityIndicator/>;
}
@@ -105,12 +130,17 @@ export default function NoticeDetails() {
<VStack className="p-2">
<Text className="text-sm font-normal mb-2 text-typography-700">
{notice.publishDate}
</Text>
<Text className="text-2xl text-gray-950 font-bold mb-2 text-center bg-gray-50 rounded-md p-2">
{notice.title}
</Text>
<Box className="flex-row items-center">
<Heading size="md" className="flex-1">
{notice.price}
<Box className="flex-row items-center bg-gray-50 rounded-md p-2">
<Heading size="md" className="flex-1 text-xl text-gray-950">
{notice.price}
</Heading>
<Pressable
onPress={() => {
if (isInWishlist) {
@@ -127,6 +157,47 @@ export default function NoticeDetails() {
/>
</Pressable>
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-sm text-typography-500">
Kategoria: <Text className="font-bold text-gray-950">{notice.category}</Text>
</Text>
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-2xl text-gray-950">
Opis ogloszenia
</Text>
<Text className="text-sm text-typography-700">
{notice.description}
</Text>
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-sm text-typography-500">
Uzytkownik:
</Text>
{isUserLoading ? (
<ActivityIndicator />
) : user ? (
<Box>
<Text className="text-xl font-bold text-gray-950">
{user.firstName} {user.lastName}
</Text>
<Text className="text-sm text-typography-700">
Email: {user.email}
</Text>
</Box>
) : (
<Text>Błąd podczas ładowania danych użytkownika</Text>
)}
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-sm text-typography-500">
{notice.clientId}
</Text>
</Box>
</VStack>
</Card>
);