fix: fix double request
This commit is contained in:
parent
df6a725d30
commit
19d5fa3430
@ -14,6 +14,7 @@ import SubPlanInformation from "../SubPlanInformation";
|
|||||||
import Title from "../Title";
|
import Title from "../Title";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
||||||
|
import ApplePayButton from "./ApplePayButton";
|
||||||
|
|
||||||
export function StripePage(): JSX.Element {
|
export function StripePage(): JSX.Element {
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
@ -31,7 +32,7 @@ export function StripePage(): JSX.Element {
|
|||||||
if (!activeSubPlan) {
|
if (!activeSubPlan) {
|
||||||
navigate(routes.client.priceList());
|
navigate(routes.client.priceList());
|
||||||
}
|
}
|
||||||
const timeoutRef = useRef<NodeJS.Timeout>();
|
// const timeoutRef = useRef<NodeJS.Timeout>();
|
||||||
|
|
||||||
// const appleReceipt = async () => {
|
// const appleReceipt = async () => {
|
||||||
// const { subscription_receipt } = await api.createSubscriptionReceipt({
|
// const { subscription_receipt } = await api.createSubscriptionReceipt({
|
||||||
@ -58,6 +59,26 @@ export function StripePage(): JSX.Element {
|
|||||||
})();
|
})();
|
||||||
}, [activeSubPlan, api, locale, navigate]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
timeoutRef.current = setTimeout(async () => {
|
timeoutRef.current = setTimeout(async () => {
|
||||||
const { subscription_receipt } = await api.createSubscriptionReceipt({
|
const { subscription_receipt } = await api.createSubscriptionReceipt({
|
||||||
@ -95,15 +116,11 @@ export function StripePage(): JSX.Element {
|
|||||||
)}
|
)}
|
||||||
{stripePromise && clientSecret && (
|
{stripePromise && clientSecret && (
|
||||||
<Elements stripe={stripePromise} options={{ clientSecret }}>
|
<Elements stripe={stripePromise} options={{ clientSecret }}>
|
||||||
|
<ApplePayButton activeSubPlan={activeSubPlan} />
|
||||||
<CheckoutForm>
|
<CheckoutForm>
|
||||||
<>
|
{activeSubPlan && (
|
||||||
{activeSubPlan && (
|
<SubPlanInformation subPlan={activeSubPlan} subPlans={subPlans} />
|
||||||
<SubPlanInformation
|
)}
|
||||||
subPlan={activeSubPlan}
|
|
||||||
subPlans={subPlans}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
</CheckoutForm>
|
</CheckoutForm>
|
||||||
</Elements>
|
</Elements>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import styles from "./styles.module.css";
|
import styles from "./styles.module.css";
|
||||||
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
||||||
import TotalToday from "./TotalToday";
|
import TotalToday from "./TotalToday";
|
||||||
import ApplePayButton from "../StripePage/ApplePayButton";
|
// import ApplePayButton from "../StripePage/ApplePayButton";
|
||||||
import MainButton from "../MainButton";
|
import MainButton from "../MainButton";
|
||||||
import { useApi } from "@/api";
|
import { useApi } from "@/api";
|
||||||
import { useAuth } from "@/auth";
|
import { useAuth } from "@/auth";
|
||||||
@ -87,7 +87,7 @@ function SubPlanInformation({
|
|||||||
{isLoading && <Loader />}
|
{isLoading && <Loader />}
|
||||||
</MainButton>
|
</MainButton>
|
||||||
)}
|
)}
|
||||||
<ApplePayButton activeSubPlan={subPlan} />
|
{/* <ApplePayButton activeSubPlan={subPlan} /> */}
|
||||||
<p className={styles.description}>
|
<p className={styles.description}>
|
||||||
{t("auweb.pay.information").replaceAll("%@", getPrice(subPlan))}
|
{t("auweb.pay.information").replaceAll("%@", getPrice(subPlan))}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user