From 6dc257dfe07dbeb025c50b074d9aa65246ddff81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=9A=D0=B0=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Mon, 4 Dec 2023 19:23:35 +0000 Subject: [PATCH] Clone --- src/components/SubscriptionPage/index.tsx | 57 +++++++++++++++++++---- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/components/SubscriptionPage/index.tsx b/src/components/SubscriptionPage/index.tsx index c4ed06d..2389b90 100644 --- a/src/components/SubscriptionPage/index.tsx +++ b/src/components/SubscriptionPage/index.tsx @@ -8,10 +8,10 @@ import PaymentTable, { Currency, Locale } from "../PaymentTable"; import CallToAction from "../CallToAction"; import routes from "@/routes"; import styles from "./styles.module.css"; -import Header from "../Header"; -import SpecialWelcomeOffer from "../SpecialWelcomeOffer"; -import { useState } from "react"; -import { ITrial } from "@/api/resources/SubscriptionPlans"; +// import Header from "../Header"; +// import SpecialWelcomeOffer from "../SpecialWelcomeOffer"; +import { useEffect, useState } from "react"; +import { ISubscriptionPlan, ITrial } from "@/api/resources/SubscriptionPlans"; import { ApiError, extractErrorMessage, useApi } from "@/api"; import { useAuth } from "@/auth"; import { getClientLocale, getClientTimezone } from "@/locales"; @@ -36,7 +36,7 @@ function SubscriptionPage(): JSX.Element { const { t } = useTranslation(); const navigate = useNavigate(); const dispatch = useDispatch(); - const [isOpenModal, setIsOpenModal] = useState(false); + // const [isOpenModal, setIsOpenModal] = useState(false); const [email, setEmail] = useState(""); const [emailError, setEmailError] = useState( "Email is invalid" @@ -48,8 +48,24 @@ function SubscriptionPage(): JSX.Element { const [isLoading, setIsLoading] = useState(false); const [apiError, setApiError] = useState(null); const [error, setError] = useState(false); - const activeSubPlan = useSelector(selectors.selectActiveSubPlan); + const [subPlans, setSubPlans] = useState([]); const birthday = useSelector(selectors.selectBirthday); + + const queryParameters = new URLSearchParams(window.location.search); + const sub_plan = queryParameters.get("sub_plan") || ""; + + const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan); + let activeSubPlan; + + if (sub_plan) { + const targetSubPlan = subPlans.find((subPlan) => subPlan.id === sub_plan); + if (targetSubPlan) { + activeSubPlan = targetSubPlan; + } + } else { + activeSubPlan = activeSubPlanFromStore; + } + const paymentItems = [ { title: activeSubPlan?.name || "Per 7-Day Trial For", @@ -106,7 +122,7 @@ function SubscriptionPage(): JSX.Element { console.log("sdvdvsdv"); // navigate(routes.client.paymentMethod()) }; - const handleCross = () => setIsOpenModal(true); + // const handleCross = () => setIsOpenModal(true); const policyLink = ( {t("subscription_policy")} @@ -141,10 +157,33 @@ function SubscriptionPage(): JSX.Element { setName(name); }; + useEffect(() => { + (async () => { + const { sub_plans } = await api.getSubscriptionPlans({ locale }); + const plans = sub_plans + .filter( + (plan: ISubscriptionPlan) => plan.provider === "stripe" && plan.trial + ) + .sort((a, b) => { + if (!a.trial || !b.trial) { + return 0; + } + if (a.trial.price_cents < b.trial.price_cents) { + return -1; + } + if (a.trial.price_cents > b.trial.price_cents) { + return 1; + } + return 0; + }); + setSubPlans(plans); + })(); + }, [api]); + return ( <> - -
+ {/* */} + {/*
*/} {/* */}