From 19d5fa3430c8bf98d18d5338763549df1ba56f58 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: Sun, 17 Dec 2023 20:48:57 +0000 Subject: [PATCH] fix: fix double request --- src/components/StripePage/index.tsx | 35 +++++++++++++++------ src/components/SubPlanInformation/index.tsx | 4 +-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/components/StripePage/index.tsx b/src/components/StripePage/index.tsx index c427081..73fc431 100644 --- a/src/components/StripePage/index.tsx +++ b/src/components/StripePage/index.tsx @@ -14,6 +14,7 @@ import SubPlanInformation from "../SubPlanInformation"; import Title from "../Title"; import { useTranslation } from "react-i18next"; import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans"; +import ApplePayButton from "./ApplePayButton"; export function StripePage(): JSX.Element { const { i18n } = useTranslation(); @@ -31,7 +32,7 @@ export function StripePage(): JSX.Element { if (!activeSubPlan) { navigate(routes.client.priceList()); } - const timeoutRef = useRef(); + // const timeoutRef = useRef(); // const appleReceipt = async () => { // const { subscription_receipt } = await api.createSubscriptionReceipt({ @@ -58,6 +59,26 @@ export function StripePage(): JSX.Element { })(); }, [activeSubPlan, api, locale, navigate]); + // useEffect(() => { + // timeoutRef.current = setTimeout(async () => { + // const { subscription_receipt } = await api.createSubscriptionReceipt({ + // token, + // way: "stripe", + // subscription_receipt: { + // sub_plan_id: activeSubPlan?.id || "stripe.7", + // }, + // }); + // const { client_secret } = subscription_receipt.data; + // setClientSecret(client_secret); + // setIsLoading(false); + // }, 4000); + // return () => { + // if (timeoutRef.current) { + // clearTimeout(timeoutRef.current); + // } + // }; + // }, [api, token]); + useEffect(() => { timeoutRef.current = setTimeout(async () => { const { subscription_receipt } = await api.createSubscriptionReceipt({ @@ -95,15 +116,11 @@ export function StripePage(): JSX.Element { )} {stripePromise && clientSecret && ( + - <> - {activeSubPlan && ( - - )} - + {activeSubPlan && ( + + )} )} diff --git a/src/components/SubPlanInformation/index.tsx b/src/components/SubPlanInformation/index.tsx index 15509f2..05e83b2 100644 --- a/src/components/SubPlanInformation/index.tsx +++ b/src/components/SubPlanInformation/index.tsx @@ -2,7 +2,7 @@ import { useTranslation } from "react-i18next"; import styles from "./styles.module.css"; import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans"; import TotalToday from "./TotalToday"; -import ApplePayButton from "../StripePage/ApplePayButton"; +// import ApplePayButton from "../StripePage/ApplePayButton"; import MainButton from "../MainButton"; import { useApi } from "@/api"; import { useAuth } from "@/auth"; @@ -87,7 +87,7 @@ function SubPlanInformation({ {isLoading && } )} - + {/* */}

{t("auweb.pay.information").replaceAll("%@", getPrice(subPlan))}