import React, { useState } from "react"; import { useSelector } from "react-redux"; import "./payment-screen.css"; import useSteps, { Step } from "@/hooks/palmistry/use-steps"; import useTimer from "@/hooks/palmistry/use-timer"; import HeaderLogo from "@/components/palmistry/header-logo/header-logo"; import { selectors } from "@/store"; import { EPlacementKeys } from "@/api/resources/Paywall"; import { useNavigate, useSearchParams } from "react-router-dom"; import PaymentModalNew from "@/components/PaymentModalNew"; import { addCurrency, ELocalesPlacement } from "@/locales"; import { getPriceCentsToDollars } from "@/services/price"; import routes from "@/routes"; import { useTranslations } from "@/hooks/translations"; import metricService, { EGoals, EMetrics } from "@/services/metric/metricService"; export default function PaymentScreen() { const { translate } = useTranslations(ELocalesPlacement.PalmistryV0); const navigate = useNavigate(); const time = useTimer(); const activeProductFromStore = useSelector(selectors.selectActiveProduct); const [searchParams] = useSearchParams(); const subscriptionStatus = searchParams.get("redirect_status") === "succeeded" ? "subscribed" : "lead"; const [height, setHeight] = useState( subscriptionStatus === "subscribed" ? 246 : 146 ); const steps = useSteps(); React.useEffect(() => { if (subscriptionStatus === "subscribed") { metricService.reachGoal(EGoals.PAYMENT_SUCCESS, [EMetrics.YANDEX, EMetrics.KLAVIYO]); metricService.reachGoal(EGoals.PAYMENT_SUCCESS_PALMISTRY, [ EMetrics.YANDEX, ]); // if (activeProductFromStore) { // metricService.reachGoal(EGoals.PURCHASE, [EMetrics.FACEBOOK], { // currency: "USD", // value: ((activeProductFromStore.trialPrice || 100) / 100).toFixed(2), // }); // } setTimeout(() => { // steps.goNext(); navigate(routes.client.skipTrial()); }, 1500); } }, [activeProductFromStore, navigate, subscriptionStatus]); React.useEffect(() => { if (!activeProductFromStore) { steps.setFirstUnpassedStep(Step.SubscriptionPlan); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [activeProductFromStore]); const trialPrice = activeProductFromStore?.trialPrice || 0; const fullPrice = activeProductFromStore?.price || 0; const currency = useSelector(selectors.selectCurrency); const [minutes, seconds] = time.split(":"); const returnUrl = window.location.origin + "/palmistry/payment"; return (