redirect url

This commit is contained in:
hamid zarghami
2025-04-21 11:50:49 +03:30
parent 6badc5fb31
commit 1e134c1e19
7 changed files with 48 additions and 23 deletions
+5
View File
@@ -58,3 +58,8 @@ export const removeToken = () => {
export const removeRefreshToken = () => { export const removeRefreshToken = () => {
Cookie.remove(import.meta.env.VITE_REFRESH_TOKEN_NAME, { domain, path: "/" }); 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");
};
+2
View File
@@ -5,6 +5,8 @@ export enum AdsDisplayLocation {
OTHER_SERVICES_TOP = "OTHER_SERVICES_TOP", OTHER_SERVICES_TOP = "OTHER_SERVICES_TOP",
OTHER_SERVICES_LEFT = "OTHER_SERVICES_LEFT", OTHER_SERVICES_LEFT = "OTHER_SERVICES_LEFT",
SERVICE = "SERVICE", SERVICE = "SERVICE",
BLOG_PAGE_TOP_RIGHT = "BLOG_PAGE_TOP_RIGHT",
BLOG_PAGE_BOTTOM_RIGHT = "BLOG_PAGE_BOTTOM_RIGHT",
} }
export type AdsItemType = { export type AdsItemType = {
+7 -2
View File
@@ -14,7 +14,7 @@ import { ErrorType } from '../../../helpers/types'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { setRefreshToken } from '../../../config/func' import { setRefreshToken } from '../../../config/func'
import { setToken } from '../../../config/func' import { setToken } from '../../../config/func'
import { getRedirectUrl } from '../../../config/func'
const LoginStep2: FC = () => { const LoginStep2: FC = () => {
const { t } = useTranslation('global') const { t } = useTranslation('global')
@@ -41,6 +41,12 @@ const LoginStep2: FC = () => {
onSuccess(data) { onSuccess(data) {
setToken(data?.data?.accessToken?.token) setToken(data?.data?.accessToken?.token)
setRefreshToken(data?.data?.refreshToken?.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 window.location.href = Pages.dashboard
}, },
onError(error: ErrorType) { onError(error: ErrorType) {
@@ -63,7 +69,6 @@ const LoginStep2: FC = () => {
} as CredentialRequestOptions) // اطمینان از تطابق تایپ‌ها } as CredentialRequestOptions) // اطمینان از تطابق تایپ‌ها
.then((otpCredential) => { .then((otpCredential) => {
if (otpCredential && "code" in otpCredential) { if (otpCredential && "code" in otpCredential) {
alert("OTP Received: " + otpCredential.code);
formik.setFieldValue("code", (otpCredential).code); formik.setFieldValue("code", (otpCredential).code);
} }
}) })
+6
View File
@@ -15,6 +15,7 @@ import { toast } from 'react-toastify'
import { ErrorType } from '../../../helpers/types' import { ErrorType } from '../../../helpers/types'
import { setRefreshToken } from '../../../config/func' import { setRefreshToken } from '../../../config/func'
import { setToken } from '../../../config/func' import { setToken } from '../../../config/func'
import { getRedirectUrl } from '../../../config/func'
const LoginStep3: FC = () => { const LoginStep3: FC = () => {
@@ -37,6 +38,11 @@ const LoginStep3: FC = () => {
onSuccess(data) { onSuccess(data) {
setToken(data?.data?.accessToken?.token) setToken(data?.data?.accessToken?.token)
setRefreshToken(data?.data?.refreshToken?.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 window.location.href = Pages.dashboard
}, },
onError(error: ErrorType) { onError(error: ErrorType) {
+6 -1
View File
@@ -13,7 +13,7 @@ import { toast } from 'react-toastify'
import { Pages } from '../../../config/Pages' import { Pages } from '../../../config/Pages'
import { setToken } from '../../../config/func' import { setToken } from '../../../config/func'
import { setRefreshToken } from '../../../config/func' import { setRefreshToken } from '../../../config/func'
import { getRedirectUrl } from '../../../config/func'
const RegisterStep2: FC = () => { const RegisterStep2: FC = () => {
const { t } = useTranslation('global') const { t } = useTranslation('global')
@@ -51,6 +51,11 @@ const RegisterStep2: FC = () => {
onSuccess(data) { onSuccess(data) {
setToken(data?.data?.accessToken?.token) setToken(data?.data?.accessToken?.token)
setRefreshToken(data?.data?.refreshToken?.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 window.location.href = Pages.dashboard
}, },
onError(error: ErrorType) { onError(error: ErrorType) {
+21 -19
View File
@@ -19,15 +19,13 @@ const ServiceHeader: FC<Props> = (props: Props) => {
const { t } = useTranslation('global') const { t } = useTranslation('global')
const [planSelected, setPlanSelected] = useState<string>(data?.subscriptionPlans[0]?.id) const [planSelected, setPlanSelected] = useState<string>(data?.subscriptionPlans[0]?.id)
const [price, setPrice] = useState<number>(data?.subscriptionPlans[0]?.price) const [price, setPrice] = useState<number>(data?.subscriptionPlans[0]?.price)
// const [finalPrice, setFinalPrice] = useState<number>(0) const [finalPrice, setFinalPrice] = useState<number>(0)
const buyService = useBuyService() const buyService = useBuyService()
useEffect(() => { useEffect(() => {
const plan: PlanItemType = data?.subscriptionPlans.find((item) => item.id === planSelected) const plan: PlanItemType = data?.subscriptionPlans.find((item) => item.id === planSelected)
console.log(plan); setFinalPrice(plan.originalPrice)
// setFinalPrice(plan.finalPrice)
setPrice(plan?.price) setPrice(plan?.price)
}, [planSelected]) }, [planSelected])
@@ -78,30 +76,34 @@ const ServiceHeader: FC<Props> = (props: Props) => {
<div className='flex gap-4 mt-5 xl:mt-0 items-center justify-between xl:justify-normal'> <div className='flex gap-4 mt-5 xl:mt-0 items-center justify-between xl:justify-normal'>
<div className='text-xs whitespace-nowrap flex gap-1 items-center'> <div className='text-xs whitespace-nowrap flex gap-1 items-center'>
<div className='flex gap-2'> <div className='flex gap-2'>
{/* { {
finalPrice !== price && finalPrice !== price &&
<div className='line-through text-xs text-description'> <div className='line-through text-xs text-description'>
{NumberFormat(Number(price))} {NumberFormat(Number(price))}
</div> </div>
} */} }
<div>{NumberFormat(Number(price))}</div> <div>{NumberFormat(Number(price))}</div>
</div> </div>
<span>{t('toman')}</span> <span>{t('toman')}</span>
</div> </div>
<Link to={Pages.services.buy + `${data.id}/${planSelected}`}> {
<Button planSelected &&
// onClick={handleBuy} <Link to={Pages.services.buy + `${data.id}/${planSelected}`}>
isLoading={buyService.isPending} <Button
className='bg-description xl:max-w-full max-w-[100px] text-xs h-8 bg-opacity-20 text-black px-4' // onClick={handleBuy}
> isLoading={buyService.isPending}
<div className='flex gap-1 items-center'> className='bg-description xl:max-w-full max-w-[100px] text-xs h-8 bg-opacity-20 text-black px-4'
<div> >
{t('service.buy')} <div className='flex gap-1 items-center'>
<div>
{t('service.buy')}
</div>
<ArrowLeft className='size-4' color='black' />
</div> </div>
<ArrowLeft className='size-4' color='black' /> </Button>
</div> </Link>
</Button> }
</Link>
</div> </div>
</div> </div>
</div> </div>
+1 -1
View File
@@ -63,12 +63,12 @@ export type PlanItemType = {
type: string; type: string;
}[]; }[];
duration: number; duration: number;
finalPrice: number;
id: string; id: string;
isActive: boolean; isActive: boolean;
name: string; name: string;
price: number; price: number;
updatedAt: string; updatedAt: string;
originalPrice: number;
}; };
// export type BuyServiceType = { // export type BuyServiceType = {