Added content to account.jsx and userNotices.jsx

This commit is contained in:
2025-06-03 00:19:12 +02:00
parent 1c57984a36
commit 8722488a45
2 changed files with 144 additions and 7 deletions

View File

@@ -1,4 +1,70 @@
import { Text } from "@/components/ui/text";
export default function User() {
return <Text>Użytkownik</Text>;
}
import { Link } from "expo-router";
import {Button} from "react-native";
import {Box} from "@/components/ui/box";
import {Text} from "@/components/ui/text";
import {VStack} from "@/components/ui/vstack";
import {Image} from "@/components/ui/image";
import {ActivityIndicator, } from "react-native";
import {useEffect, useState} from "react";
import {getUserById} from "@/api/client";
export default function Account() {
const [user, setUser] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const currentUserId = 1; // Tymczasowo, do czasu zaimplementowania logowania bo nie moge pobrac usera
useEffect(() => {
const fetchUser = async () => {
setIsLoading(true);
try {
const userData = await getUserById(currentUserId);
setUser(userData);
} catch (err) {
console.error("Błąd podczas pobierania danych użytkownika:", err);
} finally {
setIsLoading(false);
}
};
fetchUser();
}, []);
if (isLoading) {
return <ActivityIndicator />;
}
if (!user) {
return <Text>Nie udało się pobrać danych użytkownika.</Text>;
}
return (
<VStack className="p-4">
<Box className="flex-row items-center mb-4">
<Image
source={{ uri: user.profileImage || "https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain" }}
className="h-16 w-16 text-center rounded-full mr-4"
alt="Zdjęcie profilowe"
/>
<Text className="text-xl font-bold">
{user.firstName} {user.lastName}
</Text>
</Box>
<Button className="mb-4"
title="Edytuj dane użytkownika"
onPress={() => {
// TODO: Implementacja edycji danych użytkownika
console.log("Edytuj dane użytkownika");
}}
>
</Button>
<Box className="mt-4">
<Link href="/dashboard/userNotices">
<Text className="text-lg text-primary-500">Moje ogłoszenia</Text>
</Link>
<Link href="/dashboard/userPaymentHistory">
<Text className="text-lg text-primary-500 mt-2">Moje płatności</Text>
</Link>
</Box>
</VStack>
);
}

View File

@@ -1,4 +1,75 @@
import { Text } from "@/components/ui/text";
import { useNoticesStore } from "@/store/noticesStore";
import { NoticeCard } from "@/components/NoticeCard";
import {Button} from "react-native";
import {Box} from "@/components/ui/box";
import {Text} from "@/components/ui/text";
import {VStack} from "@/components/ui/vstack";
import {ActivityIndicator, FlatList } from "react-native";
import {useEffect, useState} from "react";
export default function UserNotices() {
return <Text>Użytkownik</Text>;
}
const { notices, fetchNotices } = useNoticesStore();
const [isLoading, setIsLoading] = useState(true);
const currentUserId = 1; // Tymczasowo, do czasu zaimplementowania logowania bo nie moge pobrac usera
useEffect(() => {
const loadNotices = async () => {
setIsLoading(true);
try {
await fetchNotices();
} catch (err) {
console.error("Błąd podczas pobierania ogłoszeń:", err);
} finally {
setIsLoading(false);
}
};
loadNotices();
}, []);
const userNotices = notices.filter(notice => notice.clientId === currentUserId);
if (isLoading) {
return <ActivityIndicator />;
}
return (
<VStack className="p-4">
<Text className="text-2xl font-bold mb-4">Moje ogłoszenia</Text>
{userNotices.length > 0 ? (
<FlatList
data={userNotices}
numColumns={2}
columnWrapperStyle={{ marginBottom: 10, justifyContent: "space-between" }}
renderItem={({ item }) => (
<Box className="flex-1">
<NoticeCard notice={item} />
<Box className="flex-row justify-between mt-2">
<Button
title="Promuj"
onPress={() => {
// TODO: Implementacja promocji ogłoszenia
console.log(`Promuj ogłoszenie ${item.noticeId}`);
}}
className="bg-primary-500 py-2 px-4 rounded-md"
>
</Button>
<Button
title="Podbij"
onPress={() => {
// TODO: Implementacja podbicia ogłoszenia
console.log(`Podbij ogłoszenie ${item.noticeId}`);
}}
className="bg-primary-500 py-2 px-4 rounded-md"
>
</Button>
</Box>
</Box>
)}
keyExtractor={(item) => item.noticeId.toString()}
/>
) : (
<Text>Nie masz żadnych ogłoszeń.</Text>
)}
</VStack>
);
}