checkout
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user