Compare commits
11 Commits
b34ce7fd20
...
ScreenRota
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a04ef906cd | ||
|
|
a51345fd93 | ||
|
|
c2d4f5fb79 | ||
| 7ec883100f | |||
|
|
207f8f7161 | ||
|
|
27175ffa91 | ||
| c25495ba3f | |||
| be51f1e9cc | |||
| 14bd178f84 | |||
| 7fc1312ddc | |||
| 1d3cbeef3a |
@@ -8,9 +8,11 @@ export async function listCategories() {
|
|||||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_URL}/vars/categories`, { headers: headers });
|
const response = await axios.get(`${API_URL}/vars/categories`, {
|
||||||
|
headers: headers,
|
||||||
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Nie udało się pobrać listy kategorii.", err.response.status);
|
// console.error("Nie udało się pobrać listy kategorii.", err.response.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ export async function getUserById(userId) {
|
|||||||
const { token } = useAuthStore.getState();
|
const { token } = useAuthStore.getState();
|
||||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(
|
const response = await axios.get(`${API_URL}/clients/get/${userId}`, {
|
||||||
`${API_URL}/clients/get/${userId}`,
|
headers: headers,
|
||||||
headers
|
});
|
||||||
);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|||||||
30
ArtisanConnect/api/email.jsx
Normal file
30
ArtisanConnect/api/email.jsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { useAuthStore } from "@/store/authStore";
|
||||||
|
|
||||||
|
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||||
|
|
||||||
|
export const sendEmail = async (emailData) => {
|
||||||
|
const token = useAuthStore.getState().token;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_URL}/email/send`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(token && { Authorization: `Bearer ${token}` }),
|
||||||
|
},
|
||||||
|
body: JSON.stringify(emailData),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorMessage = `HTTP error! Status: ${response.status}`;
|
||||||
|
console.error("Error przy wysyłaniu maila", errorMessage);
|
||||||
|
return { success: false, error: errorMessage };
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.text();
|
||||||
|
return { success: true, result };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error przy wysyłaniu maila:", error.message);
|
||||||
|
return { success: false, error: error.message };
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -2,7 +2,7 @@ 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://testowe.zikor.pl/api/v1";
|
// 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";
|
||||||
|
|
||||||
@@ -36,7 +36,9 @@ export async function createNotice(notice) {
|
|||||||
const { token } = useAuthStore.getState();
|
const { token } = useAuthStore.getState();
|
||||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`${API_URL}/notices/add`, notice, {headers: headers});
|
const response = await axios.post(`${API_URL}/notices/add`, notice, {
|
||||||
|
headers: headers,
|
||||||
|
});
|
||||||
|
|
||||||
if (response.data.noticeId !== null) {
|
if (response.data.noticeId !== null) {
|
||||||
for (const imageUri of notice.image) {
|
for (const imageUri of notice.image) {
|
||||||
@@ -71,7 +73,9 @@ export async function getAllImagesByNoticeId(noticeId) {
|
|||||||
const { token } = useAuthStore.getState();
|
const { token } = useAuthStore.getState();
|
||||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
try {
|
try {
|
||||||
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`, {headers: headers});
|
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`, {
|
||||||
|
headers: headers,
|
||||||
|
});
|
||||||
|
|
||||||
if (listResponse.data && listResponse.data.length > 0) {
|
if (listResponse.data && listResponse.data.length > 0) {
|
||||||
return listResponse.data.map((imageName) => ({
|
return listResponse.data.map((imageName) => ({
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import FormData from "form-data";
|
|
||||||
|
|
||||||
import { useAuthStore } from "@/store/authStore";
|
import { useAuthStore } from "@/store/authStore";
|
||||||
|
|
||||||
const API_URL = "https://hopp.zikor.pl/api/v1/orders";
|
const API_URL = "https://hopp.zikor.pl/api/v1/orders";
|
||||||
@@ -9,17 +7,16 @@ export async function createOrder(noticeId, orderType) {
|
|||||||
const { token } = useAuthStore.getState();
|
const { token } = useAuthStore.getState();
|
||||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
const clientId = 1;
|
const clientId = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${API_URL}/add`,
|
`${API_URL}/add`,
|
||||||
{ clientId, noticeId, orderType },
|
{ clientId: clientId, noticeId: noticeId, orderType: orderType },
|
||||||
{
|
{
|
||||||
headers: {
|
headers: headers,
|
||||||
"Content-Type": "application/json",
|
|
||||||
...headers,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error", error.response?.data, error.response?.status);
|
console.log("Error", error.response?.data, error.response?.status);
|
||||||
@@ -33,13 +30,10 @@ export async function createPayment(orderId) {
|
|||||||
const clientId = 1;
|
const clientId = 1;
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${API_URL}/token`,
|
`${API_URL}/token?orderId=${orderId}`,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: headers,
|
||||||
"Content-Type": "application/json",
|
|
||||||
...headers,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
@@ -49,13 +43,30 @@ export async function createPayment(orderId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getOrder(orderId) {
|
||||||
|
const { token } = useAuthStore.getState();
|
||||||
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${API_URL}/get/${orderId}`, { headers });
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"Error fetching order:",
|
||||||
|
error.response?.data,
|
||||||
|
error.response?.status
|
||||||
|
);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function listOrders() {
|
export async function listOrders() {
|
||||||
const { token } = useAuthStore.getState();
|
const { token } = useAuthStore.getState();
|
||||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_URL}/get/all`, { headers });
|
const response = await axios.get(`${API_URL}/get/all`, { headers });
|
||||||
return response.data; // to będzie tablica OrderWithPaymentsDTO
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
"Error fetching orders:",
|
"Error fetching orders:",
|
||||||
|
|||||||
@@ -28,11 +28,10 @@ export async function getWishlist() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_URL}/`, { headers });
|
const response = await axios.get(`${API_URL}/`, { headers });
|
||||||
console.log("Wishlist response:", response.data);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching wishlist:", error);
|
console.error("Error fetching wishlist:", error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
``
|
``;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"scheme": "com.hamx.artisanconnect",
|
"scheme": "com.hamx.artisanconnect",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"orientation": "portrait",
|
"orientation": "portrait",
|
||||||
"icon": "./assets/icon.png",
|
"icon": "./assets/AppIco.png",
|
||||||
"userInterfaceStyle": "light",
|
"userInterfaceStyle": "light",
|
||||||
"newArchEnabled": true,
|
"newArchEnabled": true,
|
||||||
"splash": {
|
"splash": {
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import { Ionicons } from "@expo/vector-icons";
|
|||||||
import { useAuthStore } from "@/store/authStore";
|
import { useAuthStore } from "@/store/authStore";
|
||||||
|
|
||||||
export default function TabLayout() {
|
export default function TabLayout() {
|
||||||
const token = useAuthStore((state) => state.token);
|
const { token } = useAuthStore.getState();
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return <Redirect href="/login" />;
|
return <Redirect href="/login" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { Text } from "@/components/ui/text";
|
|||||||
import { VStack } from "@/components/ui/vstack";
|
import { VStack } from "@/components/ui/vstack";
|
||||||
import { ActivityIndicator, FlatList } from "react-native";
|
import { ActivityIndicator, FlatList } from "react-native";
|
||||||
import { useEffect, useState, useRef } from "react";
|
import { useEffect, useState, useRef } from "react";
|
||||||
import { createOrder, createPayment } from "@/api/order";
|
import { createOrder, createPayment, getOrder } from "@/api/order";
|
||||||
import { Linking } from "react-native";
|
import { Linking } from "react-native";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { useToast, Toast, ToastTitle } from "@/components/ui/toast";
|
import { useToast, Toast, ToastTitle } from "@/components/ui/toast";
|
||||||
@@ -22,27 +22,34 @@ export default function UserNotices() {
|
|||||||
const appState = useRef(AppState.currentState);
|
const appState = useRef(AppState.currentState);
|
||||||
const [toastId, setToastId] = useState(0);
|
const [toastId, setToastId] = useState(0);
|
||||||
const { user_id } = useAuthStore.getState();
|
const { user_id } = useAuthStore.getState();
|
||||||
const currentUserId= user_id;
|
const currentUserId = user_id;
|
||||||
|
const [orderId, setOrderId] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isRedirecting) return;
|
if (!isRedirecting) return;
|
||||||
const subscription = AppState.addEventListener("change", (state) => {
|
const subscription = AppState.addEventListener("change", (state) => {
|
||||||
if (state === "active") {
|
if (state === "active") {
|
||||||
setIsRedirecting(false);
|
(async () => {
|
||||||
const paymentStatus = "CORRECT";
|
const lastOrder = await getOrder(orderId);
|
||||||
if (paymentStatus === "INCORRECT") {
|
const lastPayments = lastOrder.payments;
|
||||||
showNewToast("Płatność została anulowana.");
|
const paymentStatus =
|
||||||
} else if (paymentStatus === "CORRECT") {
|
lastPayments.length > 0
|
||||||
showNewToast("Płatność została zrealizowana.");
|
? lastPayments[lastPayments.length - 1].status
|
||||||
} else {
|
: null;
|
||||||
showNewToast("Płatność jeszcze nie wpłynęła.");
|
setIsRedirecting(false);
|
||||||
}
|
if (paymentStatus === "INCORRECT") {
|
||||||
|
showNewToast("Płatność została anulowana.");
|
||||||
|
} else if (paymentStatus === "CORRECT") {
|
||||||
|
showNewToast("Płatność została zrealizowana.");
|
||||||
|
} else {
|
||||||
|
showNewToast("Płatność jeszcze nie wpłynęła.");
|
||||||
|
}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
appState.current = state;
|
appState.current = state;
|
||||||
});
|
});
|
||||||
return () => subscription.remove();
|
return () => subscription.remove();
|
||||||
}, [isRedirecting, toast]);
|
}, [isRedirecting, toast, orderId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadNotices = async () => {
|
const loadNotices = async () => {
|
||||||
@@ -56,7 +63,7 @@ export default function UserNotices() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadNotices();
|
loadNotices();
|
||||||
}, []);
|
}, [fetchNotices]);
|
||||||
|
|
||||||
const showNewToast = (title) => {
|
const showNewToast = (title) => {
|
||||||
const newId = Math.random();
|
const newId = Math.random();
|
||||||
@@ -81,23 +88,23 @@ export default function UserNotices() {
|
|||||||
try {
|
try {
|
||||||
const result = await createOrder(noticeId, type);
|
const result = await createOrder(noticeId, type);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
setOrderId(result);
|
||||||
try {
|
try {
|
||||||
const paymentResult = await createPayment(); //trzeba dodać orderId
|
const paymentResult = await createPayment(result);
|
||||||
if (paymentResult) {
|
if (paymentResult) {
|
||||||
setIsRedirecting(true);
|
setIsRedirecting(true);
|
||||||
await Linking.openURL(paymentResult);
|
await Linking.openURL(paymentResult);
|
||||||
setWaitingForPayment(true);
|
|
||||||
} else {
|
} else {
|
||||||
console.log(`Nie udało się aktywować ogłoszenia ${noticeId}.`);
|
console.log(`Nie udało się aktywować ogłoszenia 4 ${noticeId}.`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Błąd podczas aktywacji ogłoszenia:", err);
|
// console.log("Błąd podczas aktywacji ogłoszenia 3:", err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(`Nie udało się aktywować ogłoszenia ${noticeId}.`);
|
// console.log(`Nie udało się aktywować ogłoszenia 2 ${noticeId}.`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Błąd podczas aktywacji ogłoszenia:", err);
|
console.log("Błąd podczas aktywacji ogłoszenia 1:", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -116,9 +123,9 @@ export default function UserNotices() {
|
|||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<Box className="items-center justify-center flex-1">
|
<Box className="items-center justify-center flex-1">
|
||||||
<ActivityIndicator size="large" color="#787878"/>
|
<ActivityIndicator size="large" color="#787878" />
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,38 +148,42 @@ export default function UserNotices() {
|
|||||||
<NoticeCard notice={item} />
|
<NoticeCard notice={item} />
|
||||||
<Box className="flex-row justify-between mt-2">
|
<Box className="flex-row justify-between mt-2">
|
||||||
<Button
|
<Button
|
||||||
className="ml-2"
|
className="ml-2"
|
||||||
onPress={() => handleDeleteNotice(item.noticeId)}
|
onPress={() => handleDeleteNotice(item.noticeId)}
|
||||||
size="md"
|
size="md"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
action="primary"
|
action="primary"
|
||||||
>
|
>
|
||||||
<ButtonText>Usuń</ButtonText>
|
<ButtonText>Usuń</ButtonText>
|
||||||
<Ionicons name="trash-outline" size={14} />
|
<Ionicons name="trash-outline" size={14} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{item.status === "ACTIVE" ? (
|
{item.status === "ACTIVE" ? (
|
||||||
<Button
|
<Button
|
||||||
className="mr-2"
|
className="mr-2"
|
||||||
size="md"
|
size="md"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
action="primary"
|
action="primary"
|
||||||
onPress={() => handleOrder(item.noticeId, "BOOST")}
|
onPress={() => handleOrder(item.noticeId, "BOOST")}
|
||||||
>
|
>
|
||||||
<ButtonText>Podbij</ButtonText>
|
<ButtonText>Podbij</ButtonText>
|
||||||
<Ionicons name="arrow-up" size={14} color="#fff" />
|
<Ionicons name="arrow-up" size={14} color="#fff" />
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
className="mr-2"
|
className="mr-2"
|
||||||
size="md"
|
size="md"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
action="primary"
|
action="primary"
|
||||||
onPress={() => handleOrder(item.noticeId, "ACTIVATE")}
|
onPress={() => handleOrder(item.noticeId, "ACTIVATION")}
|
||||||
>
|
>
|
||||||
<ButtonText>Aktywuj</ButtonText>
|
<ButtonText>Aktywuj</ButtonText>
|
||||||
<Ionicons name="arrow-redo-outline" size={14} color="#fff" />
|
<Ionicons
|
||||||
</Button>
|
name="arrow-redo-outline"
|
||||||
|
size={14}
|
||||||
|
color="#fff"
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ export default function Home() {
|
|||||||
const [isReady, setIsReady] = useState(false);
|
const [isReady, setIsReady] = useState(false);
|
||||||
const fetchNotices = useNoticesStore((state) => state.fetchNotices);
|
const fetchNotices = useNoticesStore((state) => state.fetchNotices);
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
setIsReady(true);
|
// setIsReady(true);
|
||||||
}, []);
|
// }, []);
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (isReady && !token) {
|
// if (isReady && !token) {
|
||||||
router.replace("/login");
|
// router.replace("/login");
|
||||||
}
|
// }
|
||||||
}, [isReady, token, router]);
|
// }, [isReady, token, router]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (token) {
|
if (token) {
|
||||||
@@ -32,11 +32,8 @@ export default function Home() {
|
|||||||
}, [token, fetchNotices]);
|
}, [token, fetchNotices]);
|
||||||
|
|
||||||
const notices = useNoticesStore((state) => state.notices);
|
const notices = useNoticesStore((state) => state.notices);
|
||||||
// console.log("Notices:", notices);
|
|
||||||
// console.log("Notices length:", notices.length);
|
|
||||||
|
|
||||||
const activeNotices = notices.filter((notice) => notice.status === "ACTIVE");
|
const activeNotices = notices.filter((notice) => notice.status === "ACTIVE");
|
||||||
// console.log("Activer Notices:", activeNotices.length);
|
|
||||||
const latestNotices = [...activeNotices]
|
const latestNotices = [...activeNotices]
|
||||||
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate))
|
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate))
|
||||||
.slice(0, 6);
|
.slice(0, 6);
|
||||||
|
|||||||
@@ -4,27 +4,25 @@ import { NoticeCard } from "@/components/NoticeCard";
|
|||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { Box } from "@/components/ui/box";
|
import { Box } from "@/components/ui/box";
|
||||||
import { Text } from "@/components/ui/text";
|
import { Text } from "@/components/ui/text";
|
||||||
import {useCallback} from "react";
|
import { useCallback } from "react";
|
||||||
import { useFocusEffect } from "@react-navigation/native";
|
import { useFocusEffect } from "@react-navigation/native";
|
||||||
|
|
||||||
|
|
||||||
export default function Wishlist() {
|
export default function Wishlist() {
|
||||||
const wishlistNotices = useWishlist((state) => state.wishlistNotices);
|
const wishlistNotices = useWishlist((state) => state.wishlistNotices);
|
||||||
const fetchWishlist = useWishlist((state) => state.fetchWishlist);
|
const fetchWishlist = useWishlist((state) => state.fetchWishlist);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
fetchWishlist();
|
fetchWishlist();
|
||||||
}, [fetchWishlist])
|
}, [fetchWishlist])
|
||||||
);
|
);
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
container: {
|
container: {
|
||||||
margin: 10,
|
margin: 10,
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
// console.log("Wishlist notices:", wishlistNotices);
|
|
||||||
if (wishlistNotices.length === 0) {
|
if (wishlistNotices.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Box style={styles.container} className="flex-row flex-1 justify-center">
|
<Box style={styles.container} className="flex-row flex-1 justify-center">
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ return (
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||||
|
<Stack.Screen name="user" options={{ headerShown: false }} />
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
name="(auth)/login"
|
name="(auth)/login"
|
||||||
options={{ headerShown: false }}/>
|
options={{ headerShown: false }}/>
|
||||||
|
|||||||
@@ -1,338 +1,338 @@
|
|||||||
import {Link, Stack, useLocalSearchParams} from "expo-router";
|
import { Link, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import {Box} from "@/components/ui/box";
|
import { Box } from "@/components/ui/box";
|
||||||
import {Card} from "@/components/ui/card";
|
import { Card } from "@/components/ui/card";
|
||||||
import {Heading} from "@/components/ui/heading";
|
import { Heading } from "@/components/ui/heading";
|
||||||
import {Image} from "@/components/ui/image";
|
import { Image } from "@/components/ui/image";
|
||||||
import {Text} from "@/components/ui/text";
|
import { Text } from "@/components/ui/text";
|
||||||
import {VStack} from "@/components/ui/vstack";
|
import { VStack } from "@/components/ui/vstack";
|
||||||
import {Ionicons} from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import {
|
import {
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
FlatList,
|
FlatList,
|
||||||
View,
|
View,
|
||||||
TextInput,
|
TextInput,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import {useEffect, useState, useRef} from "react";
|
import { useEffect, useState, useRef } from "react";
|
||||||
import {useNoticesStore} from "@/store/noticesStore";
|
import { useNoticesStore } from "@/store/noticesStore";
|
||||||
import {useWishlist} from "@/store/wishlistStore";
|
import { useWishlist } from "@/store/wishlistStore";
|
||||||
import {Pressable, ScrollView} from "react-native";
|
import { Pressable, ScrollView } from "react-native";
|
||||||
import {getUserById} from "@/api/client";
|
import { getUserById } from "@/api/client";
|
||||||
|
|
||||||
const {width} = Dimensions.get("window");
|
const { width } = Dimensions.get("window");
|
||||||
|
|
||||||
export default function NoticeDetails() {
|
export default function NoticeDetails() {
|
||||||
const {id} = useLocalSearchParams();
|
const { id } = useLocalSearchParams();
|
||||||
const [images, setImages] = useState([]);
|
const [images, setImages] = useState([]);
|
||||||
const [isImageLoading, setIsImageLoading] = useState(true);
|
const [isImageLoading, setIsImageLoading] = useState(true);
|
||||||
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 [user, setUser] = useState(null);
|
||||||
const [isUserLoading, setIsUserLoading] = useState(true);
|
const [isUserLoading, setIsUserLoading] = useState(true);
|
||||||
const flatListRef = useRef(null);
|
const flatListRef = useRef(null);
|
||||||
const [currentIndex, setCurrentIndex] = useState(0);
|
const [currentIndex, setCurrentIndex] = useState(0);
|
||||||
|
|
||||||
const [isMessageFormVisible, setIsMessageFormVisible] = useState(false);
|
const [isMessageFormVisible, setIsMessageFormVisible] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
const [Email, setEmail] = useState("");
|
const [Email, setEmail] = useState("");
|
||||||
const handleSendMessage = () => {
|
const handleSendMessage = () => {
|
||||||
console.log("Wiadomość do:", user?.email);
|
console.log("Wiadomość do:", user?.email);
|
||||||
console.log("Email nadawcy:", Email);
|
console.log("Email nadawcy:", Email);
|
||||||
console.log("Treść:", message);
|
console.log("Treść:", message);
|
||||||
|
|
||||||
setIsMessageFormVisible(false);
|
setIsMessageFormVisible(false);
|
||||||
setMessage("");
|
setMessage("");
|
||||||
setEmail("");
|
setEmail("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDate = (dateString) => {
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.toLocaleDateString("pl-PL", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "2-digit",
|
||||||
|
day: "2-digit",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const { getNoticeById, getAllImagesByNoticeId } = useNoticesStore();
|
||||||
|
const toggleNoticeInWishlist = useWishlist(
|
||||||
|
(state) => state.toggleNoticeInWishlist
|
||||||
|
);
|
||||||
|
|
||||||
|
const isInWishlist = useWishlist((state) =>
|
||||||
|
id ? state.wishlistNotices.some((item) => item.noticeId === id) : false
|
||||||
|
);
|
||||||
|
const onViewableItemsChanged = useRef(({ viewableItems }) => {
|
||||||
|
if (viewableItems.length > 0) {
|
||||||
|
setCurrentIndex(viewableItems[0].index);
|
||||||
|
}
|
||||||
|
}).current;
|
||||||
|
|
||||||
|
const viewabilityConfig = useRef({
|
||||||
|
itemVisiblePercentThreshold: 70,
|
||||||
|
}).current;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchNotice = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const noticeData = getNoticeById(Number(id));
|
||||||
|
if (noticeData) {
|
||||||
|
setNotice(noticeData);
|
||||||
|
setError(null);
|
||||||
|
} else {
|
||||||
|
setError(new Error(`Notice with ID ${id} not found.`));
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError(err);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatDate = (dateString) => {
|
fetchNotice();
|
||||||
const date = new Date(dateString);
|
}, [id]);
|
||||||
return date.toLocaleDateString("pl-PL", {
|
|
||||||
year: "numeric",
|
useEffect(() => {
|
||||||
month: "2-digit",
|
const fetchImage = async () => {
|
||||||
day: "2-digit",
|
setIsImageLoading(true);
|
||||||
});
|
if (notice) {
|
||||||
|
try {
|
||||||
|
const fetchedImages = await getAllImagesByNoticeId(notice.noticeId);
|
||||||
|
setImages(
|
||||||
|
fetchedImages && fetchedImages.length > 0
|
||||||
|
? fetchedImages
|
||||||
|
: { uri: "https://http.cat/404.jpg" }
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error while loading images:", err);
|
||||||
|
setImage({ uri: "https://http.cat/404.jpg" });
|
||||||
|
} finally {
|
||||||
|
setIsImageLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const {getNoticeById, getAllImagesByNoticeId} = useNoticesStore();
|
if (notice) {
|
||||||
const toggleNoticeInWishlist = useWishlist(
|
fetchImage();
|
||||||
(state) => state.toggleNoticeInWishlist
|
}
|
||||||
);
|
}, [notice]);
|
||||||
|
|
||||||
const isInWishlist = useWishlist((state) =>
|
useEffect(() => {
|
||||||
id ? state.wishlistNotices.some((item) => item.noticeId === id) : false
|
const fetchUser = async () => {
|
||||||
);
|
if (notice && notice.clientId) {
|
||||||
const onViewableItemsChanged = useRef(({viewableItems}) => {
|
setIsUserLoading(true);
|
||||||
if (viewableItems.length > 0) {
|
try {
|
||||||
setCurrentIndex(viewableItems[0].index);
|
const userData = await getUserById(notice.clientId);
|
||||||
|
setUser(userData);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Nie udało się pobrać danych użytkownika:", err);
|
||||||
|
} finally {
|
||||||
|
setIsUserLoading(false);
|
||||||
}
|
}
|
||||||
}).current;
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const viewabilityConfig = useRef({
|
fetchUser();
|
||||||
itemVisiblePercentThreshold: 70,
|
}, [notice]);
|
||||||
}).current;
|
|
||||||
|
|
||||||
useEffect(() => {
|
if (isLoading) {
|
||||||
const fetchNotice = async () => {
|
return <ActivityIndicator />;
|
||||||
setIsLoading(true);
|
}
|
||||||
try {
|
|
||||||
const noticeData = getNoticeById(Number(id));
|
|
||||||
if (noticeData) {
|
|
||||||
setNotice(noticeData);
|
|
||||||
setError(null);
|
|
||||||
} else {
|
|
||||||
setError(new Error(`Notice with ID ${id} not found.`));
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setError(err);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchNotice();
|
if (error) {
|
||||||
}, [id]);
|
return <Text>Błąd, spróbuj ponownie póżniej: {error.message}</Text>;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
if (!notice) {
|
||||||
const fetchImage = async () => {
|
return <Text>Nie znaleziono ogłoszenia</Text>;
|
||||||
setIsImageLoading(true);
|
}
|
||||||
if (notice) {
|
|
||||||
try {
|
|
||||||
const fetchedImages = await getAllImagesByNoticeId(notice.noticeId);
|
|
||||||
setImages(
|
|
||||||
fetchedImages && fetchedImages.length > 0
|
|
||||||
? fetchedImages
|
|
||||||
: {uri: "https://http.cat/404.jpg"}
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error while loading images:", err);
|
|
||||||
setImage({uri: "https://http.cat/404.jpg"});
|
|
||||||
} finally {
|
|
||||||
setIsImageLoading(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (notice) {
|
return (
|
||||||
fetchImage();
|
<Card className="p-0 rounded-lg m-3 flex-1">
|
||||||
}
|
<Stack.Screen
|
||||||
}, [notice]);
|
options={{
|
||||||
|
title: notice.title,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{isImageLoading ? (
|
||||||
|
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
|
||||||
|
<ActivityIndicator size="large" color="#3b82f6" />
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Box className="sticky top-0 z-10 bg-white">
|
||||||
|
<FlatList
|
||||||
|
ref={flatListRef}
|
||||||
|
data={images}
|
||||||
|
horizontal
|
||||||
|
snapToInterval={width}
|
||||||
|
snapToAlignment="start"
|
||||||
|
decelerationRate="fast"
|
||||||
|
showsHorizontalScrollIndicator={false}
|
||||||
|
pagingEnabled
|
||||||
|
onViewableItemsChanged={onViewableItemsChanged}
|
||||||
|
viewabilityConfig={viewabilityConfig}
|
||||||
|
renderItem={({ item, index }) => (
|
||||||
|
<View style={{ width: width }} className="p-1">
|
||||||
|
<Image
|
||||||
|
source={item}
|
||||||
|
className="h-auto w-auto rounded-md aspect-[1/1]"
|
||||||
|
alt={`Zdjęcie ${index + 1}`}
|
||||||
|
resizeMode="cover"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
keyExtractor={(item, index) => index.toString()}
|
||||||
|
/>
|
||||||
|
|
||||||
useEffect(() => {
|
{images.length > 1 && (
|
||||||
const fetchUser = async () => {
|
<Box className="flex-row justify-center mt-2">
|
||||||
if (notice && notice.clientId) {
|
{images.map((_, index) => (
|
||||||
setIsUserLoading(true);
|
<Box
|
||||||
try {
|
key={index}
|
||||||
const userData = await getUserById(notice.clientId);
|
className={`w-2 h-2 rounded-full mx-1 ${
|
||||||
setUser(userData);
|
index === currentIndex ? "bg-primary-500" : "bg-gray-300"
|
||||||
} catch (err) {
|
}`}
|
||||||
console.error("Nie udało się pobrać danych użytkownika:", err);
|
/>
|
||||||
} finally {
|
))}
|
||||||
setIsUserLoading(false);
|
</Box>
|
||||||
}
|
)}
|
||||||
}
|
</Box>
|
||||||
};
|
)}
|
||||||
|
|
||||||
fetchUser();
|
<ScrollView showsVerticalScrollIndicator={false}>
|
||||||
}, [notice]);
|
<VStack className="p-2">
|
||||||
|
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||||
|
{formatDate(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>
|
||||||
|
|
||||||
if (isLoading) {
|
<Box className="flex-row items-center bg-gray-50 rounded-md p-2">
|
||||||
return <ActivityIndicator/>;
|
<Heading size="md" className="flex-1 text-xl text-gray-950">
|
||||||
}
|
<Text className="text-sm text-typography-500">Cena: </Text>
|
||||||
|
{notice.price} zł
|
||||||
|
</Heading>
|
||||||
|
|
||||||
if (error) {
|
<Pressable
|
||||||
return <Text>Błąd, spróbuj ponownie póżniej: {error.message}</Text>;
|
onPress={() => {
|
||||||
}
|
toggleNoticeInWishlist(id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name={isInWishlist ? "heart" : "heart-outline"}
|
||||||
|
size={24}
|
||||||
|
color={"primary-heading-500"}
|
||||||
|
/>
|
||||||
|
</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>
|
||||||
|
|
||||||
if (!notice) {
|
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
|
||||||
return <Text>Nie znaleziono ogłoszenia</Text>;
|
<Text className="text-sm text-typography-500">Uzytkownik:</Text>
|
||||||
}
|
{isUserLoading ? (
|
||||||
|
<ActivityIndicator />
|
||||||
return (
|
) : user ? (
|
||||||
<Card className="p-0 rounded-lg m-3 flex-1">
|
<>
|
||||||
<Stack.Screen
|
<Box className="mr-4">
|
||||||
options={{
|
<Image
|
||||||
title: notice.title,
|
source={{
|
||||||
}}
|
uri:
|
||||||
/>
|
user.profileImage ||
|
||||||
{isImageLoading ? (
|
"https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain",
|
||||||
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
|
}} // Domyślny obraz, jeśli brak zdjęcia profilowego
|
||||||
<ActivityIndicator size="large" color="#3b82f6"/>
|
className="h-12 w-12 rounded-full"
|
||||||
|
alt="Zdjęcie profilowe"
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
<Box className="flex-1">
|
||||||
|
<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>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => setIsMessageFormVisible(true)}
|
||||||
|
className="mt-3 bg-primary-500 py-2 px-4 rounded-md"
|
||||||
|
>
|
||||||
|
<Text className="text-white text-center font-bold">
|
||||||
|
Wyślij wiadomość
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
<Link href={`/user/${notice.clientId}`}>
|
||||||
|
<Text className="text-xl p-3 font-bold text-center text-typography-700 mt-3">
|
||||||
|
Zobacz więcej ogłoszeń od {user.firstName}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Box className="sticky top-0 z-10 bg-white">
|
<Text>Błąd podczas ładowania danych użytkownika</Text>
|
||||||
<FlatList
|
|
||||||
ref={flatListRef}
|
|
||||||
data={images}
|
|
||||||
horizontal
|
|
||||||
snapToInterval={width}
|
|
||||||
snapToAlignment="start"
|
|
||||||
decelerationRate="fast"
|
|
||||||
showsHorizontalScrollIndicator={false}
|
|
||||||
pagingEnabled
|
|
||||||
onViewableItemsChanged={onViewableItemsChanged}
|
|
||||||
viewabilityConfig={viewabilityConfig}
|
|
||||||
renderItem={({item, index}) => (
|
|
||||||
<View style={{width: width}} className="p-1">
|
|
||||||
<Image
|
|
||||||
source={item}
|
|
||||||
className="h-auto w-auto rounded-md aspect-[1/1]"
|
|
||||||
alt={`Zdjęcie ${index + 1}`}
|
|
||||||
resizeMode="cover"
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
keyExtractor={(item, index) => index.toString()}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{images.length > 1 && (
|
|
||||||
<Box className="flex-row justify-center mt-2">
|
|
||||||
{images.map((_, index) => (
|
|
||||||
<Box
|
|
||||||
key={index}
|
|
||||||
className={`w-2 h-2 rounded-full mx-1 ${
|
|
||||||
index === currentIndex ? "bg-primary-500" : "bg-gray-300"
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
)}
|
)}
|
||||||
|
</Box>
|
||||||
|
</VStack>
|
||||||
|
</ScrollView>
|
||||||
|
{isMessageFormVisible && (
|
||||||
|
<View className="absolute inset-0 bg-black bg-opacity-50 justify-center items-center z-20">
|
||||||
|
<View className="bg-white p-4 rounded-lg w-4/5">
|
||||||
|
<Text className="text-lg font-bold mb-4">
|
||||||
|
Wyślij wiadomość do {user?.firstName}
|
||||||
|
</Text>
|
||||||
|
|
||||||
<ScrollView showsVerticalScrollIndicator={false}>
|
<Text className="text-sm font-medium mb-1">Do:</Text>
|
||||||
<VStack className="p-2">
|
<Text className="bg-gray-100 p-3 rounded text-gray-500">
|
||||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
{user?.email || "Brak adresu e-mail"}
|
||||||
{formatDate(notice.publishDate)}
|
</Text>
|
||||||
</Text>
|
<Text className="text-sm font-medium mb-1">Twój e-mail:</Text>
|
||||||
<Text className="text-2xl text-gray-950 font-bold mb-2 text-center bg-gray-50 rounded-md p-2">
|
<TextInput
|
||||||
{notice.title}
|
className="border border-gray-300 p-2 rounded"
|
||||||
</Text>
|
placeholder="Wpisz swój adres e-mail"
|
||||||
|
value={Email}
|
||||||
|
onChangeText={setEmail}
|
||||||
|
/>
|
||||||
|
|
||||||
<Box className="flex-row items-center bg-gray-50 rounded-md p-2">
|
<TextInput
|
||||||
<Heading size="md" className="flex-1 text-xl text-gray-950">
|
className="border border-gray-300 rounded-md p-2 mb-4 h-32 text-left"
|
||||||
<Text className="text-sm text-typography-500">Cena: </Text>
|
multiline
|
||||||
{notice.price} zł
|
numberOfLines={4}
|
||||||
</Heading>
|
placeholder="Napisz swoją wiadomość..."
|
||||||
|
value={message}
|
||||||
|
onChangeText={setMessage}
|
||||||
|
/>
|
||||||
|
|
||||||
<Pressable
|
<View className="flex-row justify-end space-x-2">
|
||||||
onPress={() => {
|
<Pressable
|
||||||
toggleNoticeInWishlist(id);
|
onPress={() => setIsMessageFormVisible(false)}
|
||||||
}}
|
className="bg-gray-300 py-2 px-4 rounded-md"
|
||||||
>
|
>
|
||||||
<Ionicons
|
<Text className="text-gray-800">Anuluj</Text>
|
||||||
name={isInWishlist ? "heart" : "heart-outline"}
|
</Pressable>
|
||||||
size={24}
|
|
||||||
color={"primary-heading-500"}
|
|
||||||
/>
|
|
||||||
</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">
|
<Pressable
|
||||||
<Text className="text-sm text-typography-500">Uzytkownik:</Text>
|
onPress={handleSendMessage}
|
||||||
{isUserLoading ? (
|
className="bg-primary-500 py-2 px-4 rounded-md"
|
||||||
<ActivityIndicator/>
|
>
|
||||||
) : user ? (
|
<Text className="text-white">Wyślij</Text>
|
||||||
<>
|
</Pressable>
|
||||||
<Box className="mr-4">
|
</View>
|
||||||
<Image
|
</View>
|
||||||
source={{
|
</View>
|
||||||
uri:
|
)}
|
||||||
user.profileImage ||
|
</Card>
|
||||||
"https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain",
|
);
|
||||||
}} // Domyślny obraz, jeśli brak zdjęcia profilowego
|
|
||||||
className="h-12 w-12 rounded-full"
|
|
||||||
alt="Zdjęcie profilowe"
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Box className="flex-1">
|
|
||||||
<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>
|
|
||||||
<Pressable
|
|
||||||
onPress={() => setIsMessageFormVisible(true)}
|
|
||||||
className="mt-3 bg-primary-500 py-2 px-4 rounded-md"
|
|
||||||
>
|
|
||||||
<Text className="text-white text-center font-bold">
|
|
||||||
Wyślij wiadomość
|
|
||||||
</Text>
|
|
||||||
</Pressable>
|
|
||||||
<Link href={`/user/${notice.clientId}`}>
|
|
||||||
<Text className="text-xl p-3 font-bold text-center text-typography-700 mt-3">
|
|
||||||
Zobacz więcej ogłoszeń od {user.firstName}
|
|
||||||
</Text>
|
|
||||||
</Link>
|
|
||||||
</Box>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<Text>Błąd podczas ładowania danych użytkownika</Text>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
</VStack>
|
|
||||||
</ScrollView>
|
|
||||||
{isMessageFormVisible && (
|
|
||||||
<View className="absolute inset-0 bg-black bg-opacity-50 justify-center items-center z-20">
|
|
||||||
<View className="bg-white p-4 rounded-lg w-4/5">
|
|
||||||
<Text className="text-lg font-bold mb-4">
|
|
||||||
Wyślij wiadomość do {user?.firstName}
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<Text className="text-sm font-medium mb-1">Do:</Text>
|
|
||||||
<Text className="bg-gray-100 p-3 rounded text-gray-500">
|
|
||||||
{user?.email || "Brak adresu e-mail"}
|
|
||||||
</Text>
|
|
||||||
<Text className="text-sm font-medium mb-1">Twój e-mail:</Text>
|
|
||||||
<TextInput
|
|
||||||
className="border border-gray-300 p-2 rounded"
|
|
||||||
placeholder="Wpisz swój adres e-mail"
|
|
||||||
value={Email}
|
|
||||||
onChangeText={setEmail}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextInput
|
|
||||||
className="border border-gray-300 rounded-md p-2 mb-4 h-32 text-left"
|
|
||||||
multiline
|
|
||||||
numberOfLines={4}
|
|
||||||
placeholder="Napisz swoją wiadomość..."
|
|
||||||
value={message}
|
|
||||||
onChangeText={setMessage}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<View className="flex-row justify-end space-x-2">
|
|
||||||
<Pressable
|
|
||||||
onPress={() => setIsMessageFormVisible(false)}
|
|
||||||
className="bg-gray-300 py-2 px-4 rounded-md"
|
|
||||||
>
|
|
||||||
<Text className="text-gray-800">Anuluj</Text>
|
|
||||||
</Pressable>
|
|
||||||
|
|
||||||
<Pressable
|
|
||||||
onPress={handleSendMessage}
|
|
||||||
className="bg-primary-500 py-2 px-4 rounded-md"
|
|
||||||
>
|
|
||||||
<Text className="text-white">Wyślij</Text>
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
11
ArtisanConnect/app/user/_layout.jsx
Normal file
11
ArtisanConnect/app/user/_layout.jsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Stack } from 'expo-router';
|
||||||
|
|
||||||
|
export default function UserLayout() {
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
screenOptions={{
|
||||||
|
headerTitle: 'Ogłoszenia użytkownika',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
BIN
ArtisanConnect/assets/AppIco.png
Normal file
BIN
ArtisanConnect/assets/AppIco.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 304 KiB |
@@ -1,6 +1,5 @@
|
|||||||
import { View, FlatList } from "react-native";
|
import { View, FlatList } from "react-native";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useAuthStore } from "@/store/authStore";
|
|
||||||
import { Heading } from "@/components/ui/heading";
|
import { Heading } from "@/components/ui/heading";
|
||||||
import { Text } from "@/components/ui/text";
|
import { Text } from "@/components/ui/text";
|
||||||
import { Link } from "expo-router";
|
import { Link } from "expo-router";
|
||||||
@@ -17,9 +16,8 @@ export function CategorySection({ notices, title }) {
|
|||||||
setCategoryMap(data);
|
setCategoryMap(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchCategories();
|
fetchCategories();
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
const categories = Array.from(
|
const categories = Array.from(
|
||||||
new Set(notices.map((notice) => notice.category))
|
new Set(notices.map((notice) => notice.category))
|
||||||
|
|||||||
11
ArtisanConnect/package-lock.json
generated
11
ArtisanConnect/package-lock.json
generated
@@ -43,6 +43,7 @@
|
|||||||
"expo-image-picker": "~16.1.4",
|
"expo-image-picker": "~16.1.4",
|
||||||
"expo-linking": "~7.1.4",
|
"expo-linking": "~7.1.4",
|
||||||
"expo-router": "~5.0.5",
|
"expo-router": "~5.0.5",
|
||||||
|
"expo-screen-orientation": "~8.1.7",
|
||||||
"expo-status-bar": "~2.2.3",
|
"expo-status-bar": "~2.2.3",
|
||||||
"expo-web-browser": "~14.1.6",
|
"expo-web-browser": "~14.1.6",
|
||||||
"form-data": "^4.0.2",
|
"form-data": "^4.0.2",
|
||||||
@@ -7012,6 +7013,16 @@
|
|||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/expo-screen-orientation": {
|
||||||
|
"version": "8.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/expo-screen-orientation/-/expo-screen-orientation-8.1.7.tgz",
|
||||||
|
"integrity": "sha512-nYwadYtdU6mMDk0MCHMPPPQtBoeFYJ2FspLRW+J35CMLqzE4nbpwGeiImfXzkvD94fpOCfI4KgLj5vGauC3pfA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"expo": "*",
|
||||||
|
"react-native": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/expo-status-bar": {
|
"node_modules/expo-status-bar": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -62,7 +62,8 @@
|
|||||||
"react-native-svg": "15.11.2",
|
"react-native-svg": "15.11.2",
|
||||||
"react-native-web": "~0.20.0",
|
"react-native-web": "~0.20.0",
|
||||||
"tailwindcss": "^3.4.17",
|
"tailwindcss": "^3.4.17",
|
||||||
"zustand": "^5.0.3"
|
"zustand": "^5.0.3",
|
||||||
|
"expo-screen-orientation": "~8.1.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.20.0",
|
"@babel/core": "^7.20.0",
|
||||||
|
|||||||
@@ -1,142 +1,134 @@
|
|||||||
import {create} from "zustand";
|
import { create } from "zustand";
|
||||||
import {createJSONStorage, persist} from "zustand/middleware";
|
import { createJSONStorage, persist } from "zustand/middleware";
|
||||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { router } from "expo-router";
|
||||||
|
|
||||||
const API_URL = "https://hopp.zikor.pl/api/v1";
|
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||||
|
|
||||||
let interceptorInitialized = false;
|
let interceptorInitialized = false;
|
||||||
|
|
||||||
export const useAuthStore = create(
|
export const useAuthStore = create(
|
||||||
persist(
|
persist(
|
||||||
(set, get) => {
|
(set, get) => {
|
||||||
if (!interceptorInitialized.current) {
|
if (!interceptorInitialized.current) {
|
||||||
axios.interceptors.response.use(
|
axios.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
if (
|
if (
|
||||||
(error.response && error.response.status === 401) ||
|
(error.response && error.response.status === 401) ||
|
||||||
error.response.status === 403
|
error.response.status === 403
|
||||||
) {
|
) {
|
||||||
set({user_id: null, token: null, isLoading: false});
|
set({ user_id: null, token: null, isLoading: false });
|
||||||
delete axios.defaults.headers.common["Authorization"];
|
delete axios.defaults.headers.common["Authorization"];
|
||||||
}
|
router.replace("/login");
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
interceptorInitialized = true;
|
|
||||||
}
|
}
|
||||||
return {
|
return Promise.reject(error);
|
||||||
user_id: null,
|
}
|
||||||
token: null,
|
);
|
||||||
isLoading: false,
|
interceptorInitialized = true;
|
||||||
error: null,
|
}
|
||||||
|
return {
|
||||||
|
user_id: null,
|
||||||
|
token: null,
|
||||||
|
isLoading: false,
|
||||||
|
error: null,
|
||||||
|
|
||||||
signIn: async (email, password) => {
|
signIn: async (email, password) => {
|
||||||
set({isLoading: true, error: null});
|
set({ isLoading: true, error: null });
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`${API_URL}/auth/login`, {
|
const response = await axios.post(`${API_URL}/auth/login`, {
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
|
|
||||||
const user_id = response.data.user_id;
|
const user_id = response.data.user_id;
|
||||||
const token = response.data.token;
|
const token = response.data.token;
|
||||||
set({user_id: user_id, token: token, isLoading: false});
|
set({ user_id: user_id, token: token, isLoading: false });
|
||||||
|
|
||||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
set({
|
set({
|
||||||
error: error.response?.data?.message || error.message,
|
error: error.response?.data?.message || error.message,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
signUp: async (userData) => {
|
|
||||||
set({isLoading: true, error: null});
|
|
||||||
try {
|
|
||||||
const response = await axios.post(
|
|
||||||
`${API_URL}/auth/register`,
|
|
||||||
userData,
|
|
||||||
{
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const user_id = response.data.user_id;
|
|
||||||
const token = response.data.token;
|
|
||||||
set({user_id: user_id, token: token, isLoading: false});
|
|
||||||
|
|
||||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
||||||
} catch (error) {
|
|
||||||
set({
|
|
||||||
error: error.response?.data?.message || error.message,
|
|
||||||
isLoading: false,
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
signInWithGoogle: async (googleToken) => {
|
|
||||||
set({isLoading: true, error: null});
|
|
||||||
try {
|
|
||||||
const response = await axios.post(
|
|
||||||
`${API_URL}/auth/google`,
|
|
||||||
{googleToken: googleToken},
|
|
||||||
{
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const user_id = response.data.user_id;
|
|
||||||
const token = response.data.token;
|
|
||||||
set({user_id: user_id, token: token, isLoading: false});
|
|
||||||
|
|
||||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
||||||
} catch (error) {
|
|
||||||
set({
|
|
||||||
error: error.response?.data?.message || error.message,
|
|
||||||
isLoading: false,
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
signOut: async () => {
|
|
||||||
try {
|
|
||||||
await axios.post(`${API_URL}/auth/logout`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Logout error:", error);
|
|
||||||
} finally {
|
|
||||||
delete axios.defaults.headers.common["Authorization"];
|
|
||||||
set({user_id: null, token: null});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// checkAuth: async () => {
|
|
||||||
// const { token } = useAuthStore.getState();
|
|
||||||
// if (!token) return null;
|
|
||||||
|
|
||||||
// set({ isLoading: true });
|
|
||||||
// try {
|
|
||||||
// axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
||||||
|
|
||||||
// const response = await axios.get(`${API_URL}/auth/me`);
|
|
||||||
|
|
||||||
// set({ user_id: response.data, isLoading: false });
|
|
||||||
// return response.data;
|
|
||||||
// } catch (error) {
|
|
||||||
// delete axios.defaults.headers.common["Authorization"];
|
|
||||||
// set({ user_id: null, token: null, isLoading: false });
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "auth-storage",
|
signUp: async (userData) => {
|
||||||
storage: createJSONStorage(() => AsyncStorage),
|
set({ isLoading: true, error: null });
|
||||||
}
|
try {
|
||||||
)
|
const response = await axios.post(
|
||||||
|
`${API_URL}/auth/register`,
|
||||||
|
userData,
|
||||||
|
{
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const user_id = response.data.user_id;
|
||||||
|
const token = response.data.token;
|
||||||
|
set({ user_id: user_id, token: token, isLoading: false });
|
||||||
|
|
||||||
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
|
} catch (error) {
|
||||||
|
set({
|
||||||
|
error: error.response?.data?.message || error.message,
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
signInWithGoogle: async (googleToken) => {
|
||||||
|
set({ isLoading: true, error: null });
|
||||||
|
try {
|
||||||
|
const response = await axios.post(
|
||||||
|
`${API_URL}/auth/google`,
|
||||||
|
{ googleToken: googleToken },
|
||||||
|
{
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const user_id = response.data.user_id;
|
||||||
|
const token = response.data.token;
|
||||||
|
set({ user_id: user_id, token: token, isLoading: false });
|
||||||
|
|
||||||
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
|
} catch (error) {
|
||||||
|
set({
|
||||||
|
error: error.response?.data?.message || error.message,
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
signOut: async () => {
|
||||||
|
const { token } = get();
|
||||||
|
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
try {
|
||||||
|
await axios.post(
|
||||||
|
`${API_URL}/auth/logout`,
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
headers: headers,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Logout error:", error);
|
||||||
|
} finally {
|
||||||
|
delete axios.defaults.headers.common["Authorization"];
|
||||||
|
set({ user_id: null, token: null });
|
||||||
|
router.replace("/login");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "auth-storage",
|
||||||
|
storage: createJSONStorage(() => AsyncStorage),
|
||||||
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user