fix: fix double request

This commit is contained in:
Денис Катаев 2023-12-17 20:48:57 +00:00 committed by Victor Ershov
parent df6a725d30
commit 19d5fa3430
2 changed files with 28 additions and 11 deletions

View File

@ -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<NodeJS.Timeout>();
// const timeoutRef = useRef<NodeJS.Timeout>();
// 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 && (
<Elements stripe={stripePromise} options={{ clientSecret }}>
<ApplePayButton activeSubPlan={activeSubPlan} />
<CheckoutForm>
<>
{activeSubPlan && (
<SubPlanInformation
subPlan={activeSubPlan}
subPlans={subPlans}
/>
)}
</>
{activeSubPlan && (
<SubPlanInformation subPlan={activeSubPlan} subPlans={subPlans} />
)}
</CheckoutForm>
</Elements>
)}

View File

@ -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 && <Loader />}
</MainButton>
)}
<ApplePayButton activeSubPlan={subPlan} />
{/* <ApplePayButton activeSubPlan={subPlan} /> */}
<p className={styles.description}>
{t("auweb.pay.information").replaceAll("%@", getPrice(subPlan))}
</p>