From 4667e066e01dc883e9a12427b7d53408ce80a474 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: Tue, 9 Apr 2024 19:19:05 +0000 Subject: [PATCH] Preview/advisor short path --- src/components/App/index.tsx | 79 +++++++++++++------ src/components/pages/AdvisorChat/index.tsx | 14 ++-- .../pages/PaymentWithEmailPage/index.tsx | 7 +- src/hooks/payment/useSinglePayment.ts | 22 ++++-- 4 files changed, 82 insertions(+), 40 deletions(-) diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index 4cfb767..8c1d9db 100755 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -285,30 +285,39 @@ function App(): JSX.Element { } > } - /> - } - /> - } - /> - } - /> - } - /> - } - /> + element={ + + } + > + } + /> + } + /> + } + /> + } + /> + + } + /> + } + /> ; + } + if (!user && pageType === EIsAuthPageType.private) { + return ; + } + return ; +} + interface ICheckPurchasedSingleProductOutletProps { productKey: string; isProductPage: boolean; diff --git a/src/components/pages/AdvisorChat/index.tsx b/src/components/pages/AdvisorChat/index.tsx index 083a220..b0af0be 100644 --- a/src/components/pages/AdvisorChat/index.tsx +++ b/src/components/pages/AdvisorChat/index.tsx @@ -14,6 +14,7 @@ import Message from "./components/Message"; import LoaderDots from "./components/LoaderDots"; import useDetectScroll from "@smakss/react-scroll-direction"; import { getZodiacSignByDate } from "@/services/zodiac-sign"; +import { useAuth } from "@/auth"; function AdvisorChatPage() { const isPrivateChat = window.location.href.includes("/advisor-chat-private/"); @@ -29,6 +30,7 @@ function AdvisorChatPage() { const { gender, birthtime, birthPlace } = useSelector( selectors.selectQuestionnaire ); + const { user } = useAuth(); const [assistant, setAssistant] = useState(); const [messageText, setMessageText] = useState(""); const [textareaRows, setTextareaRows] = useState(1); @@ -200,11 +202,13 @@ function AdvisorChatPage() { }; const getContentMessage = (messageText: string) => { - const content = `#USER INFO: zodiac sign - ${zodiacSign}; gender - ${gender}; birthdate - ${birthdate}; name - ${ - username || "unknown" - }; birthtime - ${birthtime || "unknown"}; birthPlace - ${ - birthPlace || "unknown" - }# ${messageText}`; + const sign = zodiacSign || user?.profile?.sign || "unknown"; + const _gender = gender || user?.profile?.gender || "unknown"; + const _birthDate = birthdate || user?.profile?.birthday || "unknown"; + const _birthtime = birthtime || "unknown"; + const _birthPlace = birthPlace || user?.profile?.birthplace || "unknown"; + const name = username || user?.profile?.full_name || "unknown"; + const content = `#USER INFO: zodiac sign - ${sign}; gender - ${_gender}; birthdate - ${_birthDate}; name - ${name}; birthtime - ${_birthtime}; birthPlace - ${_birthPlace}# ${messageText}`; return content; }; diff --git a/src/components/pages/PaymentWithEmailPage/index.tsx b/src/components/pages/PaymentWithEmailPage/index.tsx index 83e5cd5..d72afa8 100644 --- a/src/components/pages/PaymentWithEmailPage/index.tsx +++ b/src/components/pages/PaymentWithEmailPage/index.tsx @@ -21,8 +21,8 @@ import { useSinglePayment } from "@/hooks/payment/useSinglePayment"; function PaymentWithEmailPage() { const { productId } = useParams(); const { t, i18n } = useTranslation(); - const tokenFromStore = useSelector(selectors.selectToken); - const { signUp, user: userFromStore } = useAuth(); + // const tokenFromStore = useSelector(selectors.selectToken); + const { signUp, user: userFromStore, token: tokenFromStore } = useAuth(); const api = useApi(); const timezone = getClientTimezone(); const dispatch = useDispatch(); @@ -164,8 +164,7 @@ function PaymentWithEmailPage() { useEffect(() => { handleAuthUser(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [handleAuthUser]); return (
diff --git a/src/hooks/payment/useSinglePayment.ts b/src/hooks/payment/useSinglePayment.ts index cb6d133..8b82e48 100644 --- a/src/hooks/payment/useSinglePayment.ts +++ b/src/hooks/payment/useSinglePayment.ts @@ -69,18 +69,16 @@ export const useSinglePayment = () => { token, }); - if ( - "active" in purchased && - purchased.active && - productUrls[productKey].length - ) { - return navigate(productUrls[productKey]); + if ("active" in purchased && purchased.active) { + return true; } + return false; } catch (error) { + return false; console.error(error); } }, - [api, navigate] + [api] ); const createSinglePayment = useCallback( @@ -98,7 +96,14 @@ export const useSinglePayment = () => { return; } setProduct(product); - await checkProductPurchased(user?.email || "", targetProductKey, token); + const isPurchased = await checkProductPurchased( + user?.email || "", + targetProductKey, + token + ); + if (isPurchased && productUrls[targetProductKey].length) { + return navigate(productUrls[targetProductKey]); + } const paymentIntent = await api.createSinglePayment({ token, data: { @@ -140,6 +145,7 @@ export const useSinglePayment = () => { gender, getCurrentProduct, handlerPaymentIntentResult, + navigate, ] );