From 1ecd01b51882a2a8549045c4fbdea8b901f2abaa Mon Sep 17 00:00:00 2001 From: gofnnp Date: Wed, 10 Apr 2024 00:32:29 +0400 Subject: [PATCH] add jwtToken to epe short path --- src/components/App/index.tsx | 36 +++++++++++++++---- .../pages/PaymentWithEmailPage/index.tsx | 6 ++-- src/data/products.ts | 1 + src/hooks/payment/useSinglePayment.ts | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index 8c1d9db..1ab60e3 100755 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -1,4 +1,11 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { + useCallback, + useEffect, + useLayoutEffect, + useMemo, + useRef, + useState, +} from "react"; import { Routes, Route, @@ -127,7 +134,7 @@ function App(): JSX.Element { const navigate = useNavigate(); const api = useApi(); const dispatch = useDispatch(); - const { token, user, signUp } = useAuth(); + const { token, user, signUp, logout } = useAuth(); const [searchParams] = useSearchParams(); const jwtToken = searchParams.get("token"); @@ -164,16 +171,17 @@ function App(): JSX.Element { const { data } = useApiCall(assetsData); // jwt auth - useEffect(() => { + useLayoutEffect(() => { (async () => { if (!jwtToken) return; + logout(); const auth = await api.auth({ jwt: jwtToken }); const { auth: { token, user }, } = auth; signUp(token, user); })(); - }, [api, jwtToken, signUp]); + }, [api, jwtToken, logout, signUp]); useEffect(() => { (async () => { @@ -256,8 +264,22 @@ function App(): JSX.Element { }> } /> {/* Email - Pay - Email */} - } /> - } /> + + } + > + } /> + } + /> + {/* } @@ -288,7 +310,7 @@ function App(): JSX.Element { element={ } > diff --git a/src/components/pages/PaymentWithEmailPage/index.tsx b/src/components/pages/PaymentWithEmailPage/index.tsx index d72afa8..07ffe72 100644 --- a/src/components/pages/PaymentWithEmailPage/index.tsx +++ b/src/components/pages/PaymentWithEmailPage/index.tsx @@ -147,7 +147,6 @@ function PaymentWithEmailPage() { if (!tokenFromStore.length || !userFromStore) { return; } - await createSinglePayment({ user: userFromStore, token: tokenFromStore, @@ -187,9 +186,8 @@ function PaymentWithEmailPage() { /> )} - {(!tokenFromStore || - !paymentIntent || - (productId !== "chat.aura" && !name.length)) && + {(!tokenFromStore || !paymentIntent) && + // || (productId !== "chat.aura" && !name.length) !isLoadingSinglePayment && !isLoadingAuth && ( <> diff --git a/src/data/products.ts b/src/data/products.ts index 7399ea0..c7c8fd2 100644 --- a/src/data/products.ts +++ b/src/data/products.ts @@ -8,6 +8,7 @@ export const productUrls: IProductUrls = { "chat.aura": routes.client.advisorChatPrivate( "asst_WWkAlT4Ovs6gKRy6VEn9LqNS" ), + "moons.pdf.aura": routes.client.epeSuccessPayment(), }; interface IPaymentResultPathsOfProducts { diff --git a/src/hooks/payment/useSinglePayment.ts b/src/hooks/payment/useSinglePayment.ts index 8b82e48..bf73e88 100644 --- a/src/hooks/payment/useSinglePayment.ts +++ b/src/hooks/payment/useSinglePayment.ts @@ -101,7 +101,7 @@ export const useSinglePayment = () => { targetProductKey, token ); - if (isPurchased && productUrls[targetProductKey].length) { + if (isPurchased && productUrls[targetProductKey]?.length) { return navigate(productUrls[targetProductKey]); } const paymentIntent = await api.createSinglePayment({