diff --git a/src/config/func.ts b/src/config/func.ts index fcaa848..baa7630 100644 --- a/src/config/func.ts +++ b/src/config/func.ts @@ -58,3 +58,8 @@ export const removeToken = () => { export const removeRefreshToken = () => { Cookie.remove(import.meta.env.VITE_REFRESH_TOKEN_NAME, { domain, path: "/" }); }; + +export const getRedirectUrl = () => { + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get("redirect"); +}; diff --git a/src/pages/ads/types/AdsTypes.ts b/src/pages/ads/types/AdsTypes.ts index e1a719d..f54cd87 100644 --- a/src/pages/ads/types/AdsTypes.ts +++ b/src/pages/ads/types/AdsTypes.ts @@ -5,6 +5,8 @@ export enum AdsDisplayLocation { OTHER_SERVICES_TOP = "OTHER_SERVICES_TOP", OTHER_SERVICES_LEFT = "OTHER_SERVICES_LEFT", SERVICE = "SERVICE", + BLOG_PAGE_TOP_RIGHT = "BLOG_PAGE_TOP_RIGHT", + BLOG_PAGE_BOTTOM_RIGHT = "BLOG_PAGE_BOTTOM_RIGHT", } export type AdsItemType = { diff --git a/src/pages/auth/components/LoginStep2.tsx b/src/pages/auth/components/LoginStep2.tsx index e09d99e..ad10fe1 100644 --- a/src/pages/auth/components/LoginStep2.tsx +++ b/src/pages/auth/components/LoginStep2.tsx @@ -14,7 +14,7 @@ import { ErrorType } from '../../../helpers/types' import { toast } from 'react-toastify' import { setRefreshToken } from '../../../config/func' import { setToken } from '../../../config/func' - +import { getRedirectUrl } from '../../../config/func' const LoginStep2: FC = () => { const { t } = useTranslation('global') @@ -41,6 +41,12 @@ const LoginStep2: FC = () => { onSuccess(data) { setToken(data?.data?.accessToken?.token) setRefreshToken(data?.data?.refreshToken?.token) + // Check if there's a redirect parameter in the URL + const redirectUrl = getRedirectUrl(); + if (redirectUrl) { + window.location.href = redirectUrl; + return; // Prevent the default navigation + } window.location.href = Pages.dashboard }, onError(error: ErrorType) { @@ -63,7 +69,6 @@ const LoginStep2: FC = () => { } as CredentialRequestOptions) // اطمینان از تطابق تایپ‌ها .then((otpCredential) => { if (otpCredential && "code" in otpCredential) { - alert("OTP Received: " + otpCredential.code); formik.setFieldValue("code", (otpCredential).code); } }) diff --git a/src/pages/auth/components/LoginStep3.tsx b/src/pages/auth/components/LoginStep3.tsx index c6f9dfb..21fbe99 100644 --- a/src/pages/auth/components/LoginStep3.tsx +++ b/src/pages/auth/components/LoginStep3.tsx @@ -15,6 +15,7 @@ import { toast } from 'react-toastify' import { ErrorType } from '../../../helpers/types' import { setRefreshToken } from '../../../config/func' import { setToken } from '../../../config/func' +import { getRedirectUrl } from '../../../config/func' const LoginStep3: FC = () => { @@ -37,6 +38,11 @@ const LoginStep3: FC = () => { onSuccess(data) { setToken(data?.data?.accessToken?.token) setRefreshToken(data?.data?.refreshToken?.token) + const redirectUrl = getRedirectUrl(); + if (redirectUrl) { + window.location.href = redirectUrl; + return; // Prevent the default navigation + } window.location.href = Pages.dashboard }, onError(error: ErrorType) { diff --git a/src/pages/auth/components/RegisterStep2.tsx b/src/pages/auth/components/RegisterStep2.tsx index b85d319..b41ed94 100644 --- a/src/pages/auth/components/RegisterStep2.tsx +++ b/src/pages/auth/components/RegisterStep2.tsx @@ -13,7 +13,7 @@ import { toast } from 'react-toastify' import { Pages } from '../../../config/Pages' import { setToken } from '../../../config/func' import { setRefreshToken } from '../../../config/func' - +import { getRedirectUrl } from '../../../config/func' const RegisterStep2: FC = () => { const { t } = useTranslation('global') @@ -51,6 +51,11 @@ const RegisterStep2: FC = () => { onSuccess(data) { setToken(data?.data?.accessToken?.token) setRefreshToken(data?.data?.refreshToken?.token) + const redirectUrl = getRedirectUrl(); + if (redirectUrl) { + window.location.href = redirectUrl; + return; // Prevent the default navigation + } window.location.href = Pages.dashboard }, onError(error: ErrorType) { diff --git a/src/pages/service/components/ServiceHeader.tsx b/src/pages/service/components/ServiceHeader.tsx index 70b4e3d..75afab3 100644 --- a/src/pages/service/components/ServiceHeader.tsx +++ b/src/pages/service/components/ServiceHeader.tsx @@ -19,15 +19,13 @@ const ServiceHeader: FC = (props: Props) => { const { t } = useTranslation('global') const [planSelected, setPlanSelected] = useState(data?.subscriptionPlans[0]?.id) const [price, setPrice] = useState(data?.subscriptionPlans[0]?.price) - // const [finalPrice, setFinalPrice] = useState(0) + const [finalPrice, setFinalPrice] = useState(0) const buyService = useBuyService() useEffect(() => { const plan: PlanItemType = data?.subscriptionPlans.find((item) => item.id === planSelected) - console.log(plan); - - // setFinalPrice(plan.finalPrice) + setFinalPrice(plan.originalPrice) setPrice(plan?.price) }, [planSelected]) @@ -78,30 +76,34 @@ const ServiceHeader: FC = (props: Props) => {
- {/* { + { finalPrice !== price &&
{NumberFormat(Number(price))}
- } */} + }
{NumberFormat(Number(price))}
{t('toman')}
- -
- - + + + } + diff --git a/src/pages/service/types/ServiecTypes.ts b/src/pages/service/types/ServiecTypes.ts index f0d08ce..8b7d9ea 100644 --- a/src/pages/service/types/ServiecTypes.ts +++ b/src/pages/service/types/ServiecTypes.ts @@ -63,12 +63,12 @@ export type PlanItemType = { type: string; }[]; duration: number; - finalPrice: number; id: string; isActive: boolean; name: string; price: number; updatedAt: string; + originalPrice: number; }; // export type BuyServiceType = {