From 71d1be6416de0d6e096825bbfeb768c87c04689e 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 21:08:23 +0000 Subject: [PATCH] Clone --- src/components/SubscriptionPage/index.tsx | 45 ++++++++++++----------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/components/SubscriptionPage/index.tsx b/src/components/SubscriptionPage/index.tsx index eb2495c..a4725d2 100644 --- a/src/components/SubscriptionPage/index.tsx +++ b/src/components/SubscriptionPage/index.tsx @@ -49,30 +49,28 @@ function SubscriptionPage(): JSX.Element { const [apiError, setApiError] = useState(null); const [error, setError] = useState(false); const [subPlans, setSubPlans] = useState([]); + const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan); + const [activeSubPlan, setActiveSubPlan] = useState( + activeSubPlanFromStore + ); + const { subPlan } = useParams(); const birthday = useSelector(selectors.selectBirthday); - // const queryParameters = new URLSearchParams(window.location.search); - // const sub_plan = queryParameters.get("sub_plan") || ""; - const { subPlan } = useParams(); - - const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan); - let activeSubPlan; - - if (subPlan) { - const targetSubPlan = subPlans.find( - (sub_plan) => - String( - sub_plan.trial?.price_cents - ? Math.floor(sub_plan.trial?.price_cents / 100) - : sub_plan.id.replace(".", "") - ) === subPlan - ); - if (targetSubPlan) { - activeSubPlan = targetSubPlan; + useEffect(() => { + if (subPlan) { + const targetSubPlan = subPlans.find( + (sub_plan) => + String( + sub_plan.trial?.price_cents + ? Math.floor(sub_plan.trial?.price_cents / 100) + : sub_plan.id.replace(".", "") + ) === subPlan + ); + if (targetSubPlan) { + setActiveSubPlan(targetSubPlan); + } } - } else { - activeSubPlan = activeSubPlanFromStore; - } + }, [subPlan, subPlans]); const paymentItems = [ { @@ -103,6 +101,11 @@ function SubscriptionPage(): JSX.Element { dispatch(actions.user.update(updatedUser.user)); } dispatch(actions.status.update("registred")); + dispatch( + actions.payment.update({ + activeSubPlan, + }) + ); setIsLoading(false); setIsAuth(true); setTimeout(() => {