V1
This commit is contained in:
13
ArtisanConnect/api/client.jsx
Normal file
13
ArtisanConnect/api/client.jsx
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,9 @@ import {useEffect, useState} from "react";
|
|||||||
import {useNoticesStore} from "@/store/noticesStore";
|
import {useNoticesStore} from "@/store/noticesStore";
|
||||||
import {useWishlist} from "@/store/wishlistStore";
|
import {useWishlist} from "@/store/wishlistStore";
|
||||||
import {Pressable} from "react-native";
|
import {Pressable} from "react-native";
|
||||||
|
import {getUserById} from "@/api/client";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function NoticeDetails() {
|
export default function NoticeDetails() {
|
||||||
const {id} = useLocalSearchParams();
|
const {id} = useLocalSearchParams();
|
||||||
@@ -19,6 +22,9 @@ export default function NoticeDetails() {
|
|||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [notice, setNotice] = useState(null);
|
const [notice, setNotice] = useState(null);
|
||||||
|
const [user, setUser] = useState(null);
|
||||||
|
const [isUserLoading, setIsUserLoading] = useState(true);
|
||||||
|
|
||||||
|
|
||||||
const {getNoticeById, getAllImagesByNoticeId} = useNoticesStore();
|
const {getNoticeById, getAllImagesByNoticeId} = useNoticesStore();
|
||||||
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
||||||
@@ -69,6 +75,25 @@ export default function NoticeDetails() {
|
|||||||
}
|
}
|
||||||
}, [notice]);
|
}, [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) {
|
if (isLoading) {
|
||||||
return <ActivityIndicator/>;
|
return <ActivityIndicator/>;
|
||||||
}
|
}
|
||||||
@@ -105,12 +130,17 @@ export default function NoticeDetails() {
|
|||||||
|
|
||||||
<VStack className="p-2">
|
<VStack className="p-2">
|
||||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
<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}
|
{notice.title}
|
||||||
</Text>
|
</Text>
|
||||||
<Box className="flex-row items-center">
|
|
||||||
<Heading size="md" className="flex-1">
|
<Box className="flex-row items-center bg-gray-50 rounded-md p-2">
|
||||||
{notice.price}zł
|
<Heading size="md" className="flex-1 text-xl text-gray-950">
|
||||||
|
{notice.price} zł
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (isInWishlist) {
|
if (isInWishlist) {
|
||||||
@@ -127,6 +157,47 @@ export default function NoticeDetails() {
|
|||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</Box>
|
</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>
|
</VStack>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user