fix shiping
This commit is contained in:
@@ -44,6 +44,20 @@ const CartShipping: NextPage = () => {
|
||||
}
|
||||
}, [selectedShipments])
|
||||
|
||||
// پاک کردن انتخابهای نامعتبر وقتی shippingData تغییر میکند
|
||||
useEffect(() => {
|
||||
if (shippingData?.results?.shipping) {
|
||||
const validShopIds = new Set(shippingData.results.shipping.map(shop => shop.shopId))
|
||||
const filteredShipments = Object.fromEntries(
|
||||
Object.entries(selectedShipments).filter(([shopId]) => validShopIds.has(shopId))
|
||||
)
|
||||
|
||||
if (Object.keys(filteredShipments).length !== Object.keys(selectedShipments).length) {
|
||||
setSelectedShipments(filteredShipments)
|
||||
}
|
||||
}
|
||||
}, [shippingData, selectedShipments])
|
||||
|
||||
// هندلر انتخاب روش ارسال
|
||||
const handleShipmentSelect = (shopId: string, shipperId: number) => {
|
||||
setSelectedShipments(prev => ({
|
||||
@@ -69,12 +83,18 @@ const CartShipping: NextPage = () => {
|
||||
|
||||
setIsSavingShipment(true)
|
||||
|
||||
// فیلتر کردن selectedShipments تا فقط shop هایی که در shippingData وجود دارند
|
||||
const validShopIds = new Set(shippingData?.results?.shipping?.map(shop => shop.shopId) || [])
|
||||
|
||||
// تبدیل selectedShipments به فرمت مورد نیاز API
|
||||
const shipmentsInfo = Object.entries(selectedShipments).map(([shopId, shipperId]) => ({
|
||||
const shipmentsInfo = Object.entries(selectedShipments)
|
||||
.filter(([shopId]) => validShopIds.has(shopId))
|
||||
.map(([shopId, shipperId]) => ({
|
||||
shopId,
|
||||
shipmentId: shipperId
|
||||
}))
|
||||
|
||||
|
||||
// ذخیره انتخابها در API
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
saveShipmentCart({ shipmentsInfo }, {
|
||||
|
||||
Reference in New Issue
Block a user