import Title from "@/components/Title"; import styles from "./styles.module.css"; import ConsultationTable from "../../components/ConsultationTable"; import PaymentAddress from "../../components/PaymentAddress"; import FooterButton from "../../components/FooterButton"; import { useNavigate } from "react-router-dom"; import routes from "@/routes"; import { useAuth } from "@/auth"; import { SinglePayment, useApi, useApiCall } from "@/api"; import { useSelector } from "react-redux"; import { selectors } from "@/store"; import { useCallback, useState } from "react"; import { ResponsePost, } from "@/api/resources/SinglePayment"; import { createSinglePayment } from "@/services/singlePayment"; import Modal from "@/components/Modal"; import PaymentForm from "@/components/pages/PaymentWithEmailPage/PaymentForm"; import { getPriceCentsToDollars } from "@/services/price"; import Loader, { LoaderColor } from "@/components/Loader"; function AddConsultationPage() { const navigate = useNavigate(); const { user: userFromStore } = useAuth(); const api = useApi(); const tokenFromStore = useSelector(selectors.selectToken); const [isLoading, setIsLoading] = useState(false); const [paymentIntent, setPaymentIntent] = useState< ResponsePost | null >(null); const [isError, setIsError] = useState(false); const returnUrl = `${window.location.protocol}//${ window.location.host }${routes.client.getInformationPartner()}`; const loadData = useCallback(async () => { return await api.getSinglePaymentProducts({ token: tokenFromStore }); }, [api, tokenFromStore]); const { data: products, isPending: isPendingProducts } = useApiCall(loadData); const currentProduct = products?.find( (product) => product.key === "main.unique.individual.consultation" ); const handleClick = async () => { if (!userFromStore || !currentProduct) return; setIsLoading(true); const { productId, key } = currentProduct; const paymentInfo = { productId, key, }; const paymentIntent = await createSinglePayment( userFromStore, paymentInfo, tokenFromStore, userFromStore.email, userFromStore.profile.full_name, userFromStore.profile.birthday, returnUrl, api ); setPaymentIntent(paymentIntent); setIsLoading(false); if ("payment" in paymentIntent) { if (paymentIntent.payment.status === "paid") return navigate(routes.client.getInformationPartner()); return setIsError(true); } }; const handleClickSkip = () => { navigate(routes.client.getInformationPartner()); }; return (
{!isLoading && paymentIntent && "paymentIntent" in paymentIntent && !!tokenFromStore.length && ( <> setPaymentIntent(null)} > {getPriceCentsToDollars(currentProduct?.amount || 0)}$ )} More for you Exclusive offer recommended for you to achieve your goals faster

*You will be charged for the add-on services or offers selected at the time of purchase.
This is a non-recuring payment.

{isError && (

Something went wrong. Please try again later.

)} {isPendingProducts || isLoading ? ( ) : ( "Get my consultation" )}
); } export default AddConsultationPage;