From 24731122faba6d25d26079129cbbec6c23c025af Mon Sep 17 00:00:00 2001 From: Daniil Chemerkin Date: Mon, 28 Jul 2025 22:30:37 +0000 Subject: [PATCH] AW-483-484-485-fix-bugs --- src/api/resources/Session.ts | 3 ++- src/components/App/index.tsx | 7 ++++++- src/components/Payment/nmi/PaymentPage/index.tsx | 9 +++++++-- src/env.d.ts | 1 + src/hooks/session/useSession.ts | 15 ++++++++++----- src/init.tsx | 10 ++++++++++ src/store/utm.ts | 3 +-- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/api/resources/Session.ts b/src/api/resources/Session.ts index 6b28607..9626a83 100644 --- a/src/api/resources/Session.ts +++ b/src/api/resources/Session.ts @@ -13,7 +13,8 @@ export interface PayloadCreate { source: string, // Type: string sign: boolean, // Type: boolean signDate: string | undefined, // Type: string, ISO Date - utm: IUTM // Type: { [key: string]: string } - Optional + utm: IUTM, // Type: { [key: string]: string } - Optional + domain: string // Type: string } export interface PayloadUpdate { diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index f1707f5..75858fc 100755 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -225,7 +225,12 @@ function App(): JSX.Element { if (isPageAvailable) { const utm = parseQueryParams(); - dispatch(actions.utm.update(utm)); + console.log('App component - parsed UTM on page:', location.pathname, utm); + // Only update UTM if there are new parameters and they're not empty + if (Object.keys(utm).length > 0) { + console.log('App component - dispatching UTM update:', utm); + dispatch(actions.utm.update(utm)); + } } }, [dispatch, location.pathname]); diff --git a/src/components/Payment/nmi/PaymentPage/index.tsx b/src/components/Payment/nmi/PaymentPage/index.tsx index 981f231..79d68f0 100644 --- a/src/components/Payment/nmi/PaymentPage/index.tsx +++ b/src/components/Payment/nmi/PaymentPage/index.tsx @@ -20,6 +20,8 @@ import { EUnleashFlags, useUnleash } from "@/hooks/ab/unleash/useUnleash"; import { IFunnelPaymentVariant } from "@/api/resources/Session"; import { useFunnel } from "@/hooks/funnel/useFunnel"; +const environments = import.meta.env; + interface IPaymentPageProps { isSinglePayment?: boolean; className?: string; @@ -50,7 +52,7 @@ function PaymentPage({ funnel, paymentPlacement, onError, - onSuccess, + // onSuccess, onBack, onPopState, }: IPaymentPageProps) { @@ -114,7 +116,10 @@ function PaymentPage({ currency, value: ((activeProduct?.trialPrice || 100) / 100).toFixed(2), }); - onSuccess?.(); + // onSuccess?.(); + + const redirectUrl = `${environments.AURA_NEW_SITE_URL}/auth/callback?jwtToken=${token}&nextUrl=/ap`; + return window.location.replace(redirectUrl); } function onModalClosed(): void { diff --git a/src/env.d.ts b/src/env.d.ts index 75c8816..cc3b3b9 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -12,4 +12,5 @@ interface ImportMetaEnv { AURA_GA_MEASUREMENT_ID: string, AURA_UNLEASH_URL: string, AURA_UNLEASH_CLIENT_KEY: string, + AURA_NEW_SITE_URL: string, } \ No newline at end of file diff --git a/src/hooks/session/useSession.ts b/src/hooks/session/useSession.ts index 68c67b8..ee2fb33 100644 --- a/src/hooks/session/useSession.ts +++ b/src/hooks/session/useSession.ts @@ -27,17 +27,21 @@ export const useSession = () => { sessionId: session[source], status: "old" } - }; + } try { - const sessionFromServer = await api.createSession({ + const sessionParams = { feature, locale: language, timezone, source, sign: checked, signDate: dateOfCheck.length ? dateOfCheck : undefined, - utm - }); + utm, + domain: window.location.hostname + }; + console.log('Creating session with parameters:', sessionParams); + const sessionFromServer = await api.createSession(sessionParams); + console.log('Session creation response:', sessionFromServer); if (sessionFromServer?.sessionId?.length && sessionFromServer?.status === "success") { dispatch(actions.session.update({ session: sessionFromServer.sessionId, @@ -46,13 +50,14 @@ export const useSession = () => { localStorage.setItem(`${source}_sessionId`, sessionFromServer.sessionId); return sessionFromServer } + console.error('Session creation failed - invalid response:', sessionFromServer); setIsError(true); return { status: "error", sessionId: "" } } catch (error) { - console.log(error) + console.error('Session creation failed with error:', error); setIsError(true); return { status: "error", diff --git a/src/init.tsx b/src/init.tsx index 695ddbe..0a970b5 100755 --- a/src/init.tsx +++ b/src/init.tsx @@ -24,12 +24,22 @@ import HeadData from "./utils/Helmet"; import Clarity from '@microsoft/clarity'; import { InitializationProvider } from "./initialization"; import { getSourceByPathname } from "./utils/source.utils"; +import { parseQueryParams } from "./services/url"; +import { actions } from "./store"; pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.js`; const environments = import.meta.env; const init = async () => { + // Parse UTM parameters from URL at initialization + const utm = parseQueryParams(); + console.log('UTM parameters parsed at init:', utm); + if (Object.keys(utm).length > 0) { + console.log('Dispatching UTM update:', utm); + store.dispatch(actions.utm.update(utm)); + } + await setLanguage(); const api = createApi(); diff --git a/src/store/utm.ts b/src/store/utm.ts index 1805a68..2d399ab 100644 --- a/src/store/utm.ts +++ b/src/store/utm.ts @@ -12,8 +12,7 @@ const utmSlice = createSlice({ initialState, reducers: { update(state, action: PayloadAction) { - state = action.payload - return state + return { ...state, ...action.payload } }, }, extraReducers: (builder) => builder.addCase('reset', () => initialState)