fix shiping

This commit is contained in:
hamid zarghami
2025-10-27 16:28:41 +03:30
parent adbab2f94e
commit e56e73bf7b
+24 -4
View File
@@ -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,11 +83,17 @@ 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]) => ({
shopId,
shipmentId: shipperId
}))
const shipmentsInfo = Object.entries(selectedShipments)
.filter(([shopId]) => validShopIds.has(shopId))
.map(([shopId, shipperId]) => ({
shopId,
shipmentId: shipperId
}))
// ذخیره انتخاب‌ها در API
await new Promise<void>((resolve, reject) => {