This commit is contained in:
hamid zarghami
2025-12-04 09:21:37 +03:30
parent 77535934d5
commit a170e4bd7c
6 changed files with 85 additions and 7 deletions
+13 -4
View File
@@ -11,6 +11,7 @@ import { extractErrorMessage } from '@/lib/func'
import { useReceiptStore } from '@/zustand/receiptStore'
import { useBulkCart } from '@/app/[name]/(Dialogs)/cart/hooks/useCartData'
import { setRefreshToken, setToken } from '@/lib/api/func'
import { useSearchParams } from 'next/navigation'
type Props = {
@@ -19,13 +20,21 @@ type Props = {
}
const StepOtp = ({ phone, slug }: Props) => {
const searchParams = useSearchParams()
const redirectUrl = searchParams.get('redirect')
const { t } = useTranslation('auth')
const { mutate: mutateOtpVerify, isPending } = useOtpVerify()
const { items, clear } = useReceiptStore()
const { mutate: mutateBulkCart, isPending: isBulkCartPending } = useBulkCart()
const getRedirectPath = () => {
if (redirectUrl) {
return decodeURIComponent(redirectUrl)
}
return `/${slug}`
}
const formik = useFormik<LoginVerifyOTPType>({
initialValues: {
phone: phone,
@@ -56,17 +65,17 @@ const StepOtp = ({ phone, slug }: Props) => {
mutateBulkCart({ items: bulkCartItems }, {
onSuccess: () => {
clear()
window.location.href = `/${slug}`
window.location.href = getRedirectPath()
},
onError: (error) => {
toast(extractErrorMessage(error), 'error')
}
})
} else {
window.location.href = `/${slug}`
window.location.href = getRedirectPath()
}
} else {
window.location.href = `/${slug}`
window.location.href = getRedirectPath()
}