contact information + ...
This commit is contained in:
@@ -11,6 +11,8 @@ import { useGetCart, useSaveShipmentCart, useShippingCost } from '../hooks/useCa
|
||||
import { useGetProfile } from '@/app/profile/hooks/useProfileData'
|
||||
import Link from 'next/link'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { toast } from '@/components/Toast'
|
||||
import { extractErrorMessage } from '@/helpers/errorUtils'
|
||||
|
||||
const CartShipping: NextPage = () => {
|
||||
|
||||
@@ -67,30 +69,27 @@ const CartShipping: NextPage = () => {
|
||||
|
||||
setIsSavingShipment(true)
|
||||
|
||||
try {
|
||||
// تبدیل selectedShipments به فرمت مورد نیاز API
|
||||
const shipmentsInfo = Object.entries(selectedShipments).map(([shopId, shipperId]) => ({
|
||||
shopId,
|
||||
shipmentId: shipperId
|
||||
}))
|
||||
// تبدیل selectedShipments به فرمت مورد نیاز API
|
||||
const shipmentsInfo = Object.entries(selectedShipments).map(([shopId, shipperId]) => ({
|
||||
shopId,
|
||||
shipmentId: shipperId
|
||||
}))
|
||||
|
||||
// ذخیره انتخابها در API
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
saveShipmentCart({ shipmentsInfo }, {
|
||||
onSuccess: () => resolve(),
|
||||
onError: (error) => reject(error)
|
||||
})
|
||||
// ذخیره انتخابها در API
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
saveShipmentCart({ shipmentsInfo }, {
|
||||
onSuccess: () => {
|
||||
resolve()
|
||||
window.location.href = '/cart/payment'
|
||||
},
|
||||
onError: (error) => {
|
||||
setIsSavingShipment(false)
|
||||
toast(extractErrorMessage(error))
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// انتقال به صفحه پرداخت
|
||||
window.location.href = '/cart/payment'
|
||||
} catch (error) {
|
||||
console.error('Error saving shipment cart:', error)
|
||||
// در صورت خطا همچنان به صفحه پرداخت برویم
|
||||
window.location.href = '/cart/payment'
|
||||
} finally {
|
||||
setIsSavingShipment(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (cartLoading || shippingLoading || profileLoading) {
|
||||
|
||||
Reference in New Issue
Block a user