some fixes
This commit is contained in:
@@ -3,11 +3,12 @@ import { Ionicons } from "@expo/vector-icons";
|
||||
import { useAuthStore } from "@/store/authStore";
|
||||
|
||||
export default function TabLayout() {
|
||||
const token = useAuthStore((state) => state.token);
|
||||
const { token } = useAuthStore.getState();
|
||||
|
||||
if (!token) {
|
||||
return <Redirect href="/login" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
screenOptions={{
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Text } from "@/components/ui/text";
|
||||
import { VStack } from "@/components/ui/vstack";
|
||||
import { ActivityIndicator, FlatList } from "react-native";
|
||||
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 { Ionicons } from "@expo/vector-icons";
|
||||
import { useToast, Toast, ToastTitle } from "@/components/ui/toast";
|
||||
@@ -22,27 +22,34 @@ export default function UserNotices() {
|
||||
const appState = useRef(AppState.currentState);
|
||||
const [toastId, setToastId] = useState(0);
|
||||
const { user_id } = useAuthStore.getState();
|
||||
const currentUserId= user_id;
|
||||
const currentUserId = user_id;
|
||||
const [orderId, setOrderId] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isRedirecting) return;
|
||||
const subscription = AppState.addEventListener("change", (state) => {
|
||||
if (state === "active") {
|
||||
setIsRedirecting(false);
|
||||
const paymentStatus = "CORRECT";
|
||||
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.");
|
||||
}
|
||||
(async () => {
|
||||
const lastOrder = await getOrder(orderId);
|
||||
const lastPayments = lastOrder.payments;
|
||||
const paymentStatus =
|
||||
lastPayments.length > 0
|
||||
? lastPayments[lastPayments.length - 1].status
|
||||
: null;
|
||||
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;
|
||||
});
|
||||
return () => subscription.remove();
|
||||
}, [isRedirecting, toast]);
|
||||
}, [isRedirecting, toast, orderId]);
|
||||
|
||||
useEffect(() => {
|
||||
const loadNotices = async () => {
|
||||
@@ -81,23 +88,23 @@ export default function UserNotices() {
|
||||
try {
|
||||
const result = await createOrder(noticeId, type);
|
||||
if (result) {
|
||||
setOrderId(result);
|
||||
try {
|
||||
const paymentResult = await createPayment(); //trzeba dodać orderId
|
||||
const paymentResult = await createPayment(result);
|
||||
if (paymentResult) {
|
||||
setIsRedirecting(true);
|
||||
await Linking.openURL(paymentResult);
|
||||
setWaitingForPayment(true);
|
||||
} else {
|
||||
console.log(`Nie udało się aktywować ogłoszenia ${noticeId}.`);
|
||||
console.log(`Nie udało się aktywować ogłoszenia 4 ${noticeId}.`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Błąd podczas aktywacji ogłoszenia:", err);
|
||||
// console.log("Błąd podczas aktywacji ogłoszenia 3:", err);
|
||||
}
|
||||
} else {
|
||||
console.log(`Nie udało się aktywować ogłoszenia ${noticeId}.`);
|
||||
// console.log(`Nie udało się aktywować ogłoszenia 2 ${noticeId}.`);
|
||||
}
|
||||
} 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) {
|
||||
return (
|
||||
<Box className="items-center justify-center flex-1">
|
||||
<ActivityIndicator size="large" color="#787878"/>
|
||||
</Box>
|
||||
<Box className="items-center justify-center flex-1">
|
||||
<ActivityIndicator size="large" color="#787878" />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -141,38 +148,42 @@ export default function UserNotices() {
|
||||
<NoticeCard notice={item} />
|
||||
<Box className="flex-row justify-between mt-2">
|
||||
<Button
|
||||
className="ml-2"
|
||||
onPress={() => handleDeleteNotice(item.noticeId)}
|
||||
size="md"
|
||||
variant="outline"
|
||||
action="primary"
|
||||
className="ml-2"
|
||||
onPress={() => handleDeleteNotice(item.noticeId)}
|
||||
size="md"
|
||||
variant="outline"
|
||||
action="primary"
|
||||
>
|
||||
<ButtonText>Usuń</ButtonText>
|
||||
<Ionicons name="trash-outline" size={14} />
|
||||
</Button>
|
||||
|
||||
{item.status === "ACTIVE" ? (
|
||||
<Button
|
||||
className="mr-2"
|
||||
size="md"
|
||||
variant="solid"
|
||||
action="primary"
|
||||
onPress={() => handleOrder(item.noticeId, "BOOST")}
|
||||
>
|
||||
<ButtonText>Podbij</ButtonText>
|
||||
<Ionicons name="arrow-up" size={14} color="#fff" />
|
||||
</Button>
|
||||
<Button
|
||||
className="mr-2"
|
||||
size="md"
|
||||
variant="solid"
|
||||
action="primary"
|
||||
onPress={() => handleOrder(item.noticeId, "BOOST")}
|
||||
>
|
||||
<ButtonText>Podbij</ButtonText>
|
||||
<Ionicons name="arrow-up" size={14} color="#fff" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
className="mr-2"
|
||||
size="md"
|
||||
variant="solid"
|
||||
action="primary"
|
||||
onPress={() => handleOrder(item.noticeId, "ACTIVATE")}
|
||||
>
|
||||
<ButtonText>Aktywuj</ButtonText>
|
||||
<Ionicons name="arrow-redo-outline" size={14} color="#fff" />
|
||||
</Button>
|
||||
<Button
|
||||
className="mr-2"
|
||||
size="md"
|
||||
variant="solid"
|
||||
action="primary"
|
||||
onPress={() => handleOrder(item.noticeId, "ACTIVATION")}
|
||||
>
|
||||
<ButtonText>Aktywuj</ButtonText>
|
||||
<Ionicons
|
||||
name="arrow-redo-outline"
|
||||
size={14}
|
||||
color="#fff"
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@@ -32,11 +32,8 @@ export default function Home() {
|
||||
}, [token, fetchNotices]);
|
||||
|
||||
const notices = useNoticesStore((state) => state.notices);
|
||||
// console.log("Notices:", notices);
|
||||
// console.log("Notices length:", notices.length);
|
||||
|
||||
const activeNotices = notices.filter((notice) => notice.status === "ACTIVE");
|
||||
// console.log("Activer Notices:", activeNotices.length);
|
||||
const latestNotices = [...activeNotices]
|
||||
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate))
|
||||
.slice(0, 6);
|
||||
|
||||
Reference in New Issue
Block a user