bulk cart
This commit is contained in:
@@ -22,7 +22,7 @@ type StepEnterNumberProps = {
|
||||
value?: string
|
||||
}
|
||||
|
||||
function StepEnterNumber (_props: StepEnterNumberProps = {}) {
|
||||
function StepEnterNumber(_props: StepEnterNumberProps = {}) {
|
||||
void _props
|
||||
|
||||
const { t } = useTranslation('auth')
|
||||
@@ -31,6 +31,7 @@ function StepEnterNumber (_props: StepEnterNumberProps = {}) {
|
||||
|
||||
const { mutate: mutateOtpRequest, isPending } = useOtpRequest()
|
||||
|
||||
|
||||
const formik = useFormik<LoginOTPRequestType>({
|
||||
initialValues: {
|
||||
phone: '',
|
||||
|
||||
@@ -8,6 +8,8 @@ import { useOtpVerify } from '@/app/auth/login/hooks/useAuthData'
|
||||
import { toast } from '@/components/Toast'
|
||||
import Button from '@/components/button/PrimaryButton'
|
||||
import { extractErrorMessage } from '@/lib/func'
|
||||
import { useReceiptStore } from '@/zustand/receiptStore'
|
||||
import { useBulkCart } from '@/app/[name]/(Dialogs)/cart/hooks/useCartData'
|
||||
|
||||
|
||||
type Props = {
|
||||
@@ -19,6 +21,10 @@ const StepOtp = ({ phone, slug }: Props) => {
|
||||
|
||||
const { t } = useTranslation('auth')
|
||||
const { mutate: mutateOtpVerify, isPending } = useOtpVerify()
|
||||
|
||||
const { items, clear } = useReceiptStore()
|
||||
const { mutate: mutateBulkCart, isPending: isBulkCartPending } = useBulkCart()
|
||||
|
||||
const formik = useFormik<LoginVerifyOTPType>({
|
||||
initialValues: {
|
||||
phone: phone,
|
||||
@@ -34,7 +40,31 @@ const StepOtp = ({ phone, slug }: Props) => {
|
||||
toast(t('otp_verified'), 'success')
|
||||
localStorage.setItem(process.env.NEXT_PUBLIC_TOKEN_NAME as string, data?.data?.tokens?.accessToken?.token as string)
|
||||
localStorage.setItem(process.env.NEXT_PUBLIC_REFRESH_TOKEN_NAME as string, data?.data?.tokens?.refreshToken?.token as string)
|
||||
window.location.href = `/${slug}`
|
||||
|
||||
if (Object.keys(items).length > 0) {
|
||||
const bulkCartItems = Object.entries(items).map(([key, value]) => {
|
||||
if (value.quantity > 0) {
|
||||
return {
|
||||
foodId: key,
|
||||
quantity: value.quantity
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}).filter((item): item is { foodId: string; quantity: number } => item !== undefined)
|
||||
mutateBulkCart({ items: bulkCartItems }, {
|
||||
onSuccess: () => {
|
||||
clear()
|
||||
window.location.href = `/${slug}`
|
||||
},
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), 'error')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
window.location.href = `/${slug}`
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), 'error')
|
||||
@@ -64,7 +94,7 @@ const StepOtp = ({ phone, slug }: Props) => {
|
||||
<Button
|
||||
className='mt-10'
|
||||
disabled={!formik.isValid}
|
||||
pending={isPending}
|
||||
pending={isPending || isBulkCartPending}
|
||||
type='button'
|
||||
onClick={() => formik.handleSubmit()}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user