import type { PaymentStackScreenComponentProps } from "@/navigations/Types";
import getPaymentTypes from "@/utils/requests/getPaymentTypes";
import BalanceContainer from "@components/BalanceContainer";
import BeasyLogoIcon from "@components/BeasyLogoIcon";
import NotificationIconButton from "@components/NotificationIconButton";
import PaymentOption from "@components/PaymentOption";
import BackgroundGreenWhiteContentArea from "@components/backgrounds/BackgroundGreenWhiteContentArea";
import Box from "@components/bases/Box";
import Text from "@components/bases/Text";
import { LOG } from "@logger";
import { useQuery } from "@tanstack/react-query";
import { useMemo } from "react";
import { Dimensions } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
const log = LOG.extend("HomePageWithPaymentOptions");
const HomePageWithPaymentOptions: PaymentStackScreenComponentProps<"homePageWithPaymentOptions"> =
({ navigation }) => {
log.debug("HomePageWithPaymentOptions");
const { data, isLoading, error } = useQuery({
queryKey: ["paymentTypes"],
queryFn: getPaymentTypes,
enabled: true,
});
// getting valid payments supported
const paymentTypesWithActiveStatus = useMemo(() => {
log.info("Filtering payment types");
const paymentTypes = data?.results || [];
return paymentTypes.filter((paymentType) => paymentType.etat === true);
}, [data]);
log.info(
"payment types to render",
paymentTypesWithActiveStatus.map((paymentType) => paymentType.code),
);
return (
Types de paiement
{/* */}
{isLoading && (
Chargement des méthodes de paiement...
)}
{!isLoading &&
!error &&
paymentTypesWithActiveStatus.map((paymentType) => (
navigation.navigate(
"paymentAmountInputScreen",
{
paymentType: paymentType.code,
},
)
}
paymentMethod={paymentType.code}
/>
))}
);
};
export default HomePageWithPaymentOptions;
const screenWidth = Dimensions.get("window").width;
const paymentOptionCardWidth = screenWidth / 2 - 30;
const paymentOptionCardHeight = paymentOptionCardWidth * 0.65;
const PaymentOptionContainer = ({ children }: { children: React.ReactNode }) => {
return (
{children}
);
};